Ejemplo n.º 1
0
static void write_insert_line_two(FILE *file, char *field_name, FIELD_TYPE field_type,
			   int field_num)
{
  /*
   * Adds to the values string for the insert statement.
   */
  static char is_first_line = TRUE;
  fprintf(file, "  if (data->bitfields[%d] == ABP_SET) {\n", field_num);
  if (is_first_line) {
    if (IsString(field_type))
      fprintf(file, 
	      "    arb_dbfcmd(dbcon, \"'%%s'\", data->%s);\n", field_name);
    else if (IsDate(field_type))
      fprintf(file, 
	      "    arb_dbfcmd(dbcon, \"%%t\", &data->%s);\n", field_name);
    else if (IsNumeric(field_type))
      fprintf(file, 
	      "    arb_dbfcmd(dbcon, \"%%n\", &data->%s);\n", field_name);
    else
      fprintf(file, 
	      "    arb_dbfcmd(dbcon, \"%%d\", data->%s);\n", field_name);
  }
  else {
    if (IsString(field_type))
      fprintf(file, 
	      "    arb_dbfcmd(dbcon, \"%%s'%%s'\", separator, data->%s);\n",
	      field_name);
    else if (IsDate(field_type))
      fprintf(file, 
	      "    arb_dbfcmd(dbcon, \"%%s%%t\", separator, &data->%s);\n", 
	      field_name);
    else if (IsNumeric(field_type))
      fprintf(file, 
	      "    arb_dbfcmd(dbcon, \"%%s%%n\", separator, &data->%s);\n", 
	      field_name);
    else
      fprintf(file, 
	      "    arb_dbfcmd(dbcon, \"%%s%%d\", separator, data->%s);\n",
	      field_name);
  }
  fputs("    separator = &comma[0];\n  }\n", file);
  fprintf(file, "  else if (IS_NULL(data->bitfields[%d])) {\n", field_num);
  if (is_first_line) {
    fprintf(file, "    arb_dbcmd(dbcon, \"NULL\");\n");
    is_first_line = FALSE;
  }
  else
    fprintf(file, "    arb_dbfcmd(dbcon, \"%%sNULL\", separator);\n");
  fputs("    separator = &comma[0];\n  }\n", file);
  /* 
   * "Defaulted" fields -- if not set, use current date.
   */
  if (take_field_from_list(field_name, &defaults)) {
    fputs("  else {\n", file);
    fputs("    arb_dbfcmd(dbcon, \"%s%s\", separator, arb_server_getdate());\n",
	  file);
    fputs("    separator = &comma[0];\n  }\n", file);
  }
}
Ejemplo n.º 2
0
//----------------------------------------
std::string CUnit::GetDateRefAsString(CDate* dateRef /*= NULL*/) const
{

  std::string result;

  if (!IsDate())
  {
    return result;
  }

  CDate dateTmp;
  if (HasDateRef(&dateTmp))
  {
    return result;
  }

  if (dateRef == NULL)
  {
    CDate d;
    result = GetDateRefAsString(&d);
  }
  else
  {
    result.append(" since ");
    result.append(dateRef->AsString("", true));
    result.append(" UTC");
  }

  return result;

}
Ejemplo n.º 3
0
void write_dbbind_line(FILE *file, char *field_name, FIELD_TYPE field_type)
{
  char	bindstring[64];
  switch (field_type) {
  case CHAR: case BYTE: 
    strcpy(bindstring, "ARB_TYPE_INT8");
    break;
  case BIT:			/* ??? */
    strcpy(bindstring, "ARB_TYPE_BIT");
    break;
  case SHORT:
    strcpy(bindstring, "ARB_TYPE_INT16");
    break;
  case INT:
    strcpy(bindstring, "ARB_TYPE_INT32");
    break;
  case LONG:
    strcpy(bindstring, "ARB_TYPE_INT32"); /* ?? */
    break;
  case STRING: 
  case LSTRING:
  case MSTRING: 
    strcpy(bindstring, "ARB_TYPE_STRING");
    break;
  case SMALL_DATETIME: 
  case DATETIME:
    strcpy(bindstring, "ARB_TYPE_DATELONG"); /* ?????? */
    break;
  case NUMERIC:
    strcpy(bindstring, "ARB_TYPE_NUMERIC");
    break;
  default:
    printf("Error: Unknown field type %d. (%d)\n", field_type, __LINE__);
    break;
  }
  if (IsString(field_type))
    /* Length: sizeof() or sizeof() - 1? */
    fprintf(file, 
	    "  ++fieldnum;\n  arb_dbbind_with_ind(dbcon, fieldnum, %s, sizeof(%s_buf->%s), %s_buf->%s, &(nbbuf[fieldnum - 1]));\n\n", 
	    bindstring,	/* type */
	    lc_table_name,
	    field_name,
	    lc_table_name, 
	    field_name);
  else
    if (IsDate(field_type) || IsNumeric(field_type))
      fprintf(file, 
	      "  ++fieldnum;\n  arb_dbbind_with_ind(dbcon, fieldnum, %s, sizeof(%s_buf->%s), &(%s_buf->%s), &(nbbuf[fieldnum - 1]));\n\n", 
	      bindstring,	/* type */
	      lc_table_name,
	      field_name,
	      lc_table_name, 
	      field_name);

    else
      /* Length: 0 or length_of[type] ? Irrelevant. */ 
      fprintf(file, 
	      "  ++fieldnum;\n  arb_dbbind_with_ind(dbcon, fieldnum, %s, 0, &(%s_buf->%s), &(nbbuf[fieldnum - 1]));\n\n", 
	      bindstring, lc_table_name, field_name);
}
Ejemplo n.º 4
0
//----------------------------------------
std::string CUnit::GetDateRefAs1950() const
{

  std::string result;

  if (!IsDate())
  {
    return result;
  }

  CDate dateTmp;
  CStringArray array;

  if (!HasDateRef(NULL, &array))
  {
    return result;
  }

  result.append(array[0]);
  result.append(" since ");
  result.append(dateTmp.AsString("", true));
  result.append(" UTC");

  return result;

}
Ejemplo n.º 5
0
//----------------------------------------
std::string CUnit::GetDateUnitWithoutDateOrigin() const
{
  std::string str = GetText();

  if (!IsDate())
  {
    return str;
  }

  if (!HasDateRef())
  {
    return str;
  }

  CStringArray ar;

  ar.ExtractStrings(GetText().c_str(), " since ");

  size_t len = ar.size();


  if (len <= 1)
  {
    return str;
  }

  str = ar[0];

  return str;

}
Ejemplo n.º 6
0
int CALLBACK CSortListCtrl::CompareFunction( LPARAM lParam1, LPARAM lParam2, LPARAM lParamData )
{
	CSortListCtrl* pListCtrl = reinterpret_cast<CSortListCtrl*>( lParamData );
	ASSERT( pListCtrl->IsKindOf( RUNTIME_CLASS( CListCtrl ) ) );

	ItemData* pid1 = reinterpret_cast<ItemData*>( lParam1 );
	ItemData* pid2 = reinterpret_cast<ItemData*>( lParam2 );

	ASSERT( pid1 );
	ASSERT( pid2 );


		LPCTSTR pszText1 = pid1->arrpsz[ pListCtrl->m_iSortColumn ];
		LPCTSTR pszText2 = pid2->arrpsz[ pListCtrl->m_iSortColumn ];


	ASSERT_VALID_STRING( pszText1 );
	ASSERT_VALID_STRING( pszText2 );

	if( IsNumber( pszText1 ) )
		return pListCtrl->m_bSortAscending ? NumberCompare( pszText1, pszText2 ) : NumberCompare( pszText2, pszText1 );
	else if( IsDate( pszText1 ) )
		return pListCtrl->m_bSortAscending ? DateCompare( pszText1, pszText2 ) : DateCompare( pszText2, pszText1 );
	else
		// text.
		return pListCtrl->m_bSortAscending ? lstrcmp( pszText1, pszText2 ) : lstrcmp( pszText2, pszText1 );
}
Ejemplo n.º 7
0
//----------------------------------------
bool CUnit::HasDateRef(CDate* dateRef /*= NULL*/, CStringArray* array /*= NULL*/) const
{
  if (!IsDate())
  {
    return false;
  }

  CStringArray ar;

  ar.ExtractStrings(GetText().c_str(), ' ');

  size_t len = ar.size();


  if (len <= 2)
  {
    return false;
  }

  int32_t index = ar.FindIndex("since");

  if (index < 0)
  {
    return false;
  }

  CDate dateTmp;

  int32_t result = BRATHL_ERROR;
  std::string strDate;

  for (uint32_t i = index + 1 ; i < ar.size() ; i++)
  {
    strDate.append(ar.at(i));
    strDate.append(" ");

  }

  strDate = CTools::StringTrim(strDate);
  
  result = dateTmp.SetDate(strDate.c_str());

  if (result == BRATHL_SUCCESS)
  {
    if (dateRef != NULL)
    {
      *dateRef = dateTmp;
    }
  }
  
  if (array != NULL)
  {
    array->Insert(ar);
  }

  return (result == BRATHL_SUCCESS);
}
Ejemplo n.º 8
0
Archivo: Value.cpp Proyecto: krf/QOds
void
Value::Read(ods::Ns &ns, ods::Attrs &attrs)
{
	DeleteData();
	auto *type_attr = attrs.Get(ns.office(), ods::ns::kValueType);
	if (type_attr == nullptr)
	{ // shouldn't happen
		type_ = ods::Type::Fail;
		return;
	}
	type_ = ods::TypeFromString(type_attr->value());
	auto *value_attr = attrs.Get(ns.office(), ods::ns::kValue);
	if (value_attr == nullptr)
	{
		type_ = ods::Type::Fail;
		return;
	}

	if (IsDouble() || IsPercentage() || IsCurrency())
	{
		double num;
		if (!value_attr->ToDouble(num))
		{
			mtl_warn("ToDouble()");
			return;
		}
		set(new double(num), type_);
	} else if (IsString()) {
		set(new QString(value_attr->value()), ods::Type::String);
	} else if (IsDate()) {
		auto *custom_attr = attrs.Get(ns.office(), ods::ns::kDateValue);
		if (custom_attr == nullptr)
		{
			mtl_warn("custom_attr == nullptr");
			return;
		}
		auto dt = QDateTime::fromString(custom_attr->value(), Qt::ISODate);
		set(new QDateTime(dt), type_);
	} else if (IsDuration()) {
		auto *custom_attr = attrs.Get(ns.office(), ods::ns::kTimeValue);
		if (custom_attr == nullptr)
		{
			mtl_warn("custom_attr == nullptr");
			return;
		}
		auto *t = new ods::Duration();
		t->Decode(custom_attr->value());
		set(t, type_);
	} else {
		type_ = ods::Type::NotSet;
	}
}
Ejemplo n.º 9
0
Substyle::~Substyle()
{
	if (IsNotSet())
		return;
	if (IsCurrency())
		delete AsCurrency();
	else if (IsDate())
		delete AsDate();
	else if (IsDuration())
		delete AsDuration();
	else if (IsPercent())
		delete AsPercent();
}
Ejemplo n.º 10
0
Value StdValueFromEsc(const EscValue& v)
{
	if(v.IsNumber())
		return v.GetNumber();
	if(v.IsArray())
		return (WString)v;
	if(IsTime(v))
		return Time(v.GetFieldInt("year"), v.GetFieldInt("month"), v.GetFieldInt("day"),
			v.GetFieldInt("hour"), v.GetFieldInt("minute"), v.GetFieldInt("second"));
	if(IsDate(v))
		return Date(v.GetFieldInt("year"), v.GetFieldInt("month"), v.GetFieldInt("day"));
	return Value();
}
Ejemplo n.º 11
0
void write_setter(FILE *file, char *name, FIELD_TYPE type)
{
  /*
   * Writing to file, define a slot setter for the datatype defined.
   */
  fprintf(file, "void set_%s_%s(%s *data, %s%svalue)\n{\n",
	  lc_table_name, name, struct_name, 
	  c_type[type],
	  (IsString(type) || IsDate(type) || IsNumeric(type)) ? "" : " ");
#ifdef _GENERATE_COMMENTS
  fprintf(file, "\n  /* Set value of %s in data */\n", name);
#endif
  if (IsString(type))
    fprintf(file, "  arb_safe_strncpy(data->%s, value, sizeof(data->%s));\n", 
	    name, name);
  else if (IsDate(type))
    fprintf(file, "  memcpy(&data->%s, value, sizeof(Arb_date));\n", name);
  else if (IsNumeric(type))
    fprintf(file, "  memcpy(&data->%s, value, sizeof(Arb_numeric));\n", name);
  else 
    fprintf(file, "  data->%s = value;\n", name);
  fprintf(file,"  *(%s_%s_bits(data)) = ABP_SET;\n}\n\n", lc_table_name, name);
}
Ejemplo n.º 12
0
void write_acc_declarations(FILE *file, char *name, FIELD_TYPE type)
{
  /*
   * Writing to file, declare the accessor and bitfield accessor functions 
   * for a field.
   */
  if (IsString(type) || IsDate(type) || IsNumeric(type))
    fprintf(file, "extern void set_%s_%s(%s *data, %svalue);\n",
	    lc_table_name, name, struct_name, c_type[type]);
  else				/* no *, so extra space... */
    fprintf(file, "extern void set_%s_%s(%s *data, %s value);\n",
	    lc_table_name, name, struct_name, c_type[type]);
  fprintf(file, "extern char *%s_%s_bits(%s *data);\n", lc_table_name, name,
	  struct_name);
}
Ejemplo n.º 13
0
/***** NO LONGER USED.  NB: prototypes also no longer generated.  *******/
void write_accessor(FILE *file, char *name, FIELD_TYPE type)
{
  /*
   * Writing to file, define a slot accessor for the datatype defined.
   */
  if (IsString(type) || IsDate(type)) {
    fprintf(file, "%sget_%s_%s(%s *data)\n{\n  /* Accessor for */\n",
	    c_type[type], lc_table_name, name, struct_name);
    fprintf(file, "  return data->%s;\n}\n\n", name);
  }
  else {
    fprintf(file, "%s *get_%s_%s(%s *data)\n{\n  /* Accessor for */\n",
	    c_type[type], lc_table_name, name, struct_name);
    fprintf(file, "  return &(data->%s);\n}\n\n", name);
  }
}
Ejemplo n.º 14
0
Archivo: Value.cpp Proyecto: krf/QOds
void
Value::DeleteData()
{
	if (!Ok())
		return;
	if (IsDouble() || IsPercentage())
		delete AsDouble();
	else if (IsString())
		delete AsString();
	else if (IsDate())
		delete AsDate();
	else if (IsDuration())
		delete AsDuration();
	data_ = nullptr;
	type_ = ods::Type::NotSet;
}
Ejemplo n.º 15
0
Archivo: Value.cpp Proyecto: krf/QOds
QString
Value::toString() const
{
	if (!Ok())
		return "";
	
	if (IsDouble() || IsPercentage())
		return QString::number(*AsDouble());
	if (IsString())
		return *AsString();
	if (IsDate())
		return AsDate()->toString(Qt::ISODate);
	if (IsCurrency())
		mtl_qline("Currency not supported yet");
	if (IsDuration())
		return AsDuration()->ToString();
	
	return "";
}
Ejemplo n.º 16
0
Archivo: Value.cpp Proyecto: krf/QOds
void
Value::CopyTo(ods::Value &v)
{
	v.type_set(type_);
	if (NoValue())
		return;
	if (IsDouble())
		v.SetDouble(*AsDouble());
	else if (IsString())
		v.SetString(*AsString());
	else if (IsCurrency())
		v.SetCurrency(*AsCurrency());
	else if (IsPercentage())
		v.SetPercentage(*AsPercentage());
	else if (IsDate())
		v.SetDate(*AsDate());
	else if (IsDuration())
		v.SetDuration(*AsDuration());
	else
		mtl_warn("Not implemented");
}
Ejemplo n.º 17
0
std::string CUnit::AsString
		(bool asBaseUnit /*= true*/, bool withDateOrigin /*= false*/, CDate* dateRef /*= NULL*/) const
{
  std::string result;

  if (asBaseUnit)
  {
    char	*Buffer;
    CheckUdunits(utPrint(&m_Compiled, &Buffer), m_Text);
  
    result = std::string(Buffer);
  }
  else
  {
    result = m_Text;
  }

  if ( (withDateOrigin) && IsDate() )
  {
    result.append(GetDateRefAsString(dateRef));
  }

  return result;
}