EagleBoolean EagleDbTuple_set(EagleDbTuple *tuple, int position, EagleDbSqlValue *v, EagleDataType columnType) { EagleBoolean canCast; switch (columnType) { case EagleDataTypeInteger: { EagleDataTypeIntegerType value = EagleDbSqlValue_getInteger(v, &canCast); EagleDbTuple_setInt(tuple, position, value); break; } case EagleDataTypeFloat: { EagleDataTypeFloatType value = EagleDbSqlValue_getFloat(v, &canCast); EagleDbTuple_setFloat(tuple, position, value); break; } case EagleDataTypeVarchar: { EagleDataTypeVarcharType value = EagleDbSqlValue_getVarchar(v, &canCast); EagleDbTuple_setVarchar(tuple, position, value); break; } case EagleDataTypeUnknown: { canCast = EagleFalse; break; } } return canCast; }
EagleDbParser* _BenchSuite_distance(EagleDbInstance *db, int rows) { /* SLOW INSERT for(int i = 0; i < rows; ++i) { char sql[1024]; sprintf(sql, "INSERT INTO point (id, x, y) VALUES (%d, %g, %g);", i + 1, frand(1000.0), frand(1000.0)); //printf("%s\n", sql); success = EagleDbInstance_execute(db, sql, &error); if(EagleFalse == success) { CUNIT_FAIL("%s", error->message); } } */ EagleDbTableData *td = EagleDbInstance_getTable(db, "point"); EagleDbTuple *tuple = EagleDbTuple_New(td->table); for(int i = 0; i < rows; ++i) { EagleDbTuple_setInt(tuple, 0, i + 1); EagleDbTuple_setFloat(tuple, 1, frand(1000.0)); EagleDbTuple_setFloat(tuple, 2, frand(1000.0)); EagleDbTableData_insert(td, tuple); // this is a bit naughty, to save time on recreating the tuple for every row we are reusing it free(tuple->data[0]); free(tuple->data[1]); free(tuple->data[2]); tuple->data[0] = NULL; tuple->data[1] = NULL; tuple->data[2] = NULL; } EagleDbTuple_Delete(tuple); // do a distance search EagleDbParser *p = EagleDbParser_ParseWithString("SELECT id, x, y FROM point WHERE sqrt((500.0 - x) * (500.0 - x) + (500.0 - y) * (500.0 - y)) < 1.0"); if(EagleTrue == EagleDbParser_hasError(p)) { CUNIT_FAIL("%s", EagleDbParser_lastError(p)); } return p; }
CUNIT_TEST(DBSuite, EagleDbTuple_setFloat) { EagleLogger_Get()->out = NULL; EagleDbTable *table = EagleDbTable_New("mytable"); EagleDbTable_addColumn(table, EagleDbColumn_New("a", EagleDataTypeVarchar)); EagleDbTuple *tuple = EagleDbTuple_New(table); EagleDbTuple_setFloat(tuple, 0, 123.0); CUNIT_ASSERT_LAST_ERROR("Wrong type."); EagleDbTuple_Delete(tuple); EagleDbTable_DeleteWithColumns(table); }