예제 #1
0
static VALUE typecast(sqlite3_stmt *stmt, int i, VALUE ruby_class) {
  const char *ruby_type;
  VALUE ruby_value = Qnil;
  int original_type = sqlite3_column_type(stmt, i);
  int length        = sqlite3_column_bytes(stmt, i);
  if ( original_type == SQLITE_NULL ) {
    return ruby_value;
  }

  if ( original_type == SQLITE_BLOB ) {
    return TAINTED_STRING((char*)sqlite3_column_blob(stmt, i), length);
  }

  if(ruby_class == Qnil) {
    switch(original_type) {
      case SQLITE_INTEGER: {
        ruby_type = "Integer";
        break;
      }
      case SQLITE_FLOAT: {
        ruby_type = "Float";
        break;
      }
      default: {
        ruby_type = "String";
        break;
      }
    }
  } else {
    ruby_type = rb_class2name(ruby_class);
  }

  if ( strcmp(ruby_type, "Class") == 0) {
    return rb_funcall(rb_cObject, rb_intern("full_const_get"), 1, TAINTED_STRING((char*)sqlite3_column_text(stmt, i), length));
  } else if ( strcmp(ruby_type, "Object") == 0 ) {
    return rb_marshal_load(rb_str_new2((char*)sqlite3_column_text(stmt, i)));
  } else if ( strcmp(ruby_type, "TrueClass") == 0 ) {
    return strcmp((char*)sqlite3_column_text(stmt, i), "t") == 0 ? Qtrue : Qfalse;
  } else if ( strcmp(ruby_type, "Integer") == 0 || strcmp(ruby_type, "Fixnum") == 0 || strcmp(ruby_type, "Bignum") == 0 ) {
    return LL2NUM(sqlite3_column_int64(stmt, i));
  } else if ( strcmp(ruby_type, "BigDecimal") == 0 ) {
    return rb_funcall(rb_cBigDecimal, ID_NEW, 1, TAINTED_STRING((char*)sqlite3_column_text(stmt, i), length));
  } else if ( strcmp(ruby_type, "Float") == 0 ) {
    return rb_float_new(sqlite3_column_double(stmt, i));
  } else if ( strcmp(ruby_type, "Date") == 0 ) {
    return parse_date((char*)sqlite3_column_text(stmt, i));
  } else if ( strcmp(ruby_type, "DateTime") == 0 ) {
    return parse_date_time((char*)sqlite3_column_text(stmt, i));
  } else if ( strcmp(ruby_type, "Time") == 0 ) {
    return parse_time((char*)sqlite3_column_text(stmt, i));
  } else {
    return TAINTED_STRING((char*)sqlite3_column_text(stmt, i), length);
  }
}
예제 #2
0
파일: CppSQLite3.cpp 프로젝트: GMIS/GMIS
double CppSQLite3Query::getFloatField(int nField, double fNullValue/*=0.0*/)
{
	if (fieldDataType(nField) == SQLITE_NULL)
	{
		return fNullValue;
	}
	else
	{
		return sqlite3_column_double(mpVM, nField);
	}
}
std::pair<int, double> SqliteMakePlots::Run(const char * query,int query_length, std::vector<Space*> spaces, 
        BaseGetValueFunction * reference_function){
    ///FIXME: atm the 'collection_rowid' columns has to be selected. This should be only optional
    std::pair<int, double> result;
    /// Prepare sql statement
    int error;
    const char * tail;
    sqlite3_stmt * stmt;
    error = sqlite3_prepare(_connection,query,query_length,&stmt,&tail);
    if (error != SQLITE_OK){
        std::cout << "ERROR: prepare stament failed" << std::endl;
        return result;
    }
    /// for retrieving tha vars
    int rowid;
    int ncols=sqlite3_column_count(stmt);
    double *vars = new double[ncols-2];
    /// Space iterator
    std::vector<Space*>::iterator space_it;
    /// some definitions
    int nrows=0, n_chi2_lt_45=0;
    double reference;
    int min_reference_rowid=-1;
    double min_reference=1e9;
    /// loop over selected rows
    while (sqlite3_step(stmt)==SQLITE_ROW){
        if (nrows%100000==0) std::cout << "Currently at " << nrows << " rows\r" << std::flush;
        ///Get all variables
        rowid=sqlite3_column_int(stmt,0);
        for (int i=0;i<ncols-2;i++){ 
            vars[i]=sqlite3_column_double(stmt,i+2);
        }
        ///Calculate reference (usually the chi2)
        reference=(*reference_function)(vars);
        if (reference < min_reference){
            min_reference = reference;
            min_reference_rowid = rowid;
        }
        if (reference<45) 
            n_chi2_lt_45++;
        ///Update all _spaces: check whether X^2 is lower than existing X^2
        for( space_it=spaces.begin(); space_it!=spaces.end() ; space_it++){
            (*space_it)->update(vars,rowid,reference);
        }
        nrows++;
    }
    sqlite3_finalize(stmt);
    sqlite3_close(_connection);
    std::cout << "Number of rows processed:       " << nrows << std::endl;
    std::cout << "Number of points with chi2<45 : " << n_chi2_lt_45 << std::endl;
    delete vars;
    result = std::make_pair(min_reference_rowid, min_reference);
    return result;
}
예제 #4
0
QgsOSMNode QgsOSMDatabase::node( QgsOSMId id ) const
{
  // bind the way identifier
  sqlite3_bind_int64( mStmtNode, 1, id );

  if ( sqlite3_step( mStmtNode ) != SQLITE_ROW )
  {
    //QgsDebugMsg( "Cannot get number of way members." );
    sqlite3_reset( mStmtNode );
    return QgsOSMNode();
  }

  double lon = sqlite3_column_double( mStmtNode, 0 );
  double lat = sqlite3_column_double( mStmtNode, 1 );

  QgsOSMNode node( id, QgsPoint( lon, lat ) );

  sqlite3_reset( mStmtNode );
  return node;
}
예제 #5
0
파일: db.c 프로젝트: jlsandell/Craft
int db_load_state(float *x, float *y, float *z, float *rx, float *ry) {
    if (!db_enabled) {
        return 0;
    }
    static const char *query =
        "select x, y, z, rx, ry from state;";
    int result = 0;
    sqlite3_stmt *stmt;
    sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
    if (sqlite3_step(stmt) == SQLITE_ROW) {
        *x = sqlite3_column_double(stmt, 0);
        *y = sqlite3_column_double(stmt, 1);
        *z = sqlite3_column_double(stmt, 2);
        *rx = sqlite3_column_double(stmt, 3);
        *ry = sqlite3_column_double(stmt, 4);
        result = 1;
    }
    sqlite3_finalize(stmt);
    return result;
}
예제 #6
0
 void deserialize_pms_guess(sqlite3* db, GuessGeneratorParameters & pms_guess, int64_t & id) {
     sqlite3_stmt *read;
     db_prepare(db, read, boost::format(
         "select ransac_iterations_count, min_inliers_count, max_projection_error "
         "from pms_guess where id=%d;") % id);
     db_step(read, SQLITE_ROW);
     int c = 0;
     pms_guess.ransacIterationsCount = sqlite3_column_int(read, c++);
     pms_guess.minInliersCount = sqlite3_column_int(read, c++);
     pms_guess.maxProjectionError = sqlite3_column_double(read, c++);
     sqlite3_finalize(read);
 }
예제 #7
0
파일: sqlite.c 프로젝트: exaphaser/neko_mod
/**
	result_get_float : 'result -> n:int -> float
	<doc>Return the [n]th field of the current result row as a float.</doc>
**/
static value result_get_float( value v, value n ) {
	result *r;
	val_check_kind(v,k_result);
	r = val_result(v);
	if( val_int(n) < 0 || val_int(n) >= r->ncols )
		neko_error();
	if( r->first )
		result_next(v);
	if( r->done )
		neko_error();
	return alloc_float(sqlite3_column_double(r->r,val_int(n)));
}
예제 #8
0
파일: NDBResult.cpp 프로젝트: x414e54/nano
//============================================================================
//		NDBResult::GetValueFloat64 : Get a Float64 value.
//----------------------------------------------------------------------------
Float64 NDBResult::GetValueFloat64(NIndex theIndex) const
{


	// Validate our parameters
	NN_ASSERT(theIndex < GetSize());



	// Get the value
	return(sqlite3_column_double((sqlite3_stmt *) mResult, theIndex));
}
예제 #9
0
파일: Database.cpp 프로젝트: noriter/nit
DataValue Database::Query::getValue(int column)
{
	if (_stmt == NULL) return DataValue::Void();

	switch (sqlite3_column_type(_stmt, column))
	{
	case SQLITE_INTEGER:				return sqlite3_column_int64(_stmt, column);

	case SQLITE_FLOAT:					return sqlite3_column_double(_stmt, column);

	case SQLITE_NULL:					return DataValue::Null();

	case SQLITE_BLOB:
		{ 
			const void* blob = sqlite3_column_blob(_stmt, column);
			size_t size = sqlite3_column_bytes(_stmt, column);

			if (size < sizeof(uint32) + sizeof(uint8))
				return DataValue(blob, size);

			// check DATA or ZDATA signature and try to convert to (or load) a DataValue
			uint32 signature = *(uint32*)blob;
			if (signature == NIT_DATA_SIGNATURE || signature == NIT_ZDATA_SIGNATURE)
			{
				DataValue blobValue(blob, size);

				try
				{
					uint8 type = ((uint8*)blob)[4];
					blobValue.convertTo((DataValue::Type)type);
				}
				catch (...)
				{
					// Conversion or load fail: return as just a plain blob
				}

				return blobValue;
			}

			// If signature doesn't tell it's a DataValue, return a plain blob
			return DataValue(blob, size);
		}

	case SQLITE3_TEXT:
		{
			const char* text = (const char*)sqlite3_column_text(_stmt, column);
			int len = sqlite3_column_bytes(_stmt, column);
			return DataValue(text, len);
		}

	default:							NIT_THROW(EX_NOT_SUPPORTED);
	}
}
Optional<double> SqlConnection::DataCommand::GetColumnOptionalDouble(
    SqlConnection::ColumnIndex column)
{
    LogPedantic("SQL data command get column optional double: ["
                << column << "]");
    CheckColumnIndex(column);
    if (sqlite3_column_type(m_stmt, column) == SQLITE_NULL)
        return Optional<double>::Null;
    double value = sqlite3_column_double(m_stmt, column);
    LogPedantic("    Value: " << value);
    return Optional<double>(value);
}
Optional<float> SqlConnection::DataCommand::GetColumnOptionalFloat(
    SqlConnection::ColumnIndex column)
{
    LogPedantic("SQL data command get column optional float: ["
                << column << "]");
    CheckColumnIndex(column);
    if (sqlite3_column_type(m_stmt, column) == SQLITE_NULL)
        return Optional<float>::Null;
    float value = static_cast<float>(sqlite3_column_double(m_stmt, column));
    LogPedantic("    Value: " << value);
    return Optional<float>(value);
}
예제 #12
0
void Sqlite3Connection::GetColumn(int i, Ref f) const {
	ASSERT(NULL != current_stmt);
	if(i == -1) {
		f = Value(sqlite3_last_insert_rowid(db));
		return;
	}

	ASSERT(got_row_data);
	String coltype;
	const char *s = sqlite3_column_decltype(current_stmt,i);
	if(s) coltype = ToLower(s);
	switch (sqlite3_column_type(current_stmt,i)) {
		case SQLITE_INTEGER:
			f = sqlite3_column_int64(current_stmt,i);
			break;
		case SQLITE_FLOAT:
			f = sqlite3_column_double(current_stmt,i);
			break;
		case SQLITE_TEXT:
			if(coltype == "date" || f.GetType() == DATE_V){
				const char *s = (const char *)sqlite3_column_text(current_stmt, i);
				if(strlen(s) >= 10)
					f = Value(Date(atoi(s), atoi(s + 5), atoi(s + 8)));
				else
					f = Null;
			}
			else
			if(coltype == "datetime" || f.GetType() == TIME_V) {
				const char *s = (const char *)sqlite3_column_text(current_stmt, i);
				if(strlen(s) >= 19)
					f = Value(Time(atoi(s), atoi(s + 5), atoi(s + 8), atoi(s + 11), atoi(s + 14), atoi(s + 17)));
				else
				if(strlen(s) >= 10)
					f = Value(ToTime(Date(atoi(s), atoi(s + 5), atoi(s + 8))));
				else
					f = Null;
			}
			else
				f = Value(WString((const wchar*)sqlite3_column_text16(current_stmt,i)));
			break;
		case SQLITE_NULL:
			f = Null;
			break;
		case SQLITE_BLOB:
			f = Value(String( (const byte*)sqlite3_column_blob(current_stmt,i),
			                  sqlite3_column_bytes(current_stmt,i)                ));
			break;
		default:
			NEVER();
			break;
	}
	return;
}
예제 #13
0
bool CppSQLite3Query::GetFloatValue(int nField, double &rDest)
{
	if (FieldDataType(nField) == SQLITE_NULL)
	{
		return false;
	}
	else
	{
		rDest = sqlite3_column_double(mpStmt, nField);
		return true;
	}
}
예제 #14
0
QString QgsCoordinateTransform::datumTransformString( int datumTransform )
{
    QString transformString;

    sqlite3* db;
    int openResult = sqlite3_open( QgsApplication::srsDbFilePath().toUtf8().constData(), &db );
    if ( openResult != SQLITE_OK )
    {
        sqlite3_close( db );
        return transformString;
    }

    sqlite3_stmt* stmt;
    QString sql = QString( "SELECT coord_op_method_code,p1,p2,p3,p4,p5,p6,p7 FROM tbl_datum_transform WHERE coord_op_code=%1" ).arg( datumTransform );
    int prepareRes = sqlite3_prepare( db, sql.toAscii(), sql.size(), &stmt, NULL );
    if ( prepareRes != SQLITE_OK )
    {
        sqlite3_finalize( stmt );
        sqlite3_close( db );
        return transformString;
    }

    if ( sqlite3_step( stmt ) == SQLITE_ROW )
    {
        //coord_op_methode_code
        int methodCode = sqlite3_column_int( stmt, 0 );
        if ( methodCode == 9615 ) //ntv2
        {
            transformString = "+nadgrids=" + QString(( const char * )sqlite3_column_text( stmt, 1 ) );
        }
        else if ( methodCode == 9603 || methodCode == 9606 || methodCode == 9607 )
        {
            transformString += "+towgs84=";
            double p1 = sqlite3_column_double( stmt, 1 );
            double p2 = sqlite3_column_double( stmt, 2 );
            double p3 = sqlite3_column_double( stmt, 3 );
            double p4 = sqlite3_column_double( stmt, 4 );
            double p5 = sqlite3_column_double( stmt, 5 );
            double p6 = sqlite3_column_double( stmt, 6 );
            double p7 = sqlite3_column_double( stmt, 7 );
            if ( methodCode == 9603 ) //3 parameter transformation
            {
                transformString += QString( "%1,%2,%3" ).arg( p1 ).arg( p2 ).arg( p3 );
            }
            else //7 parameter transformation
            {
                transformString += QString( "%1,%2,%3,%4,%5,%6,%7" ).arg( p1 ).arg( p2 ).arg( p3 ).arg( p4 ).arg( p5 ).arg( p6 ).arg( p7 );
            }
        }
    }

    sqlite3_finalize( stmt );
    sqlite3_close( db );
    return transformString;
}
예제 #15
0
QueryResult SQLiteStatement::executeAndFetch(string query,Binding* bindings){
	QueryResult result;
    //g_message("SQLiteStatement: Preparing query and Binding data");
	this->prepare(query)->bindData(bindings);
	//g_message("SQLiteStatement: Query [\n\n%s\n\n]",query.c_str());
    //g_message("SQLiteStatement: Prepared query and Binding data");
	int rc;

	while(SQLITE_ROW == (rc = sqlite3_step(m_stmt))) {
		QueryRow row = BundleFacade::get();
        //g_message("SQLiteStatement: Got A row");
        //QueryRow row;
		//int col;
		for(int col=0; col<sqlite3_column_count(m_stmt); col++) {
		    string key = (const char*) sqlite3_column_name(m_stmt,col);
		    //g_message("SQLiteStatement: Putting row value in Bundle for key [%s] in ",key.c_str());
		    string value;
		    switch(sqlite3_column_type(m_stmt,col)){
		    	case SQLITE_INTEGER:
		    		g_message("int");
		    		row->putExtra(key,(int) sqlite3_column_int64(m_stmt,col));
		    		break;
		    	case SQLITE_FLOAT:
		    		g_message("double");
		    		row->putExtra(key,sqlite3_column_double(m_stmt,col));
		    		break;
		    	case SQLITE3_TEXT:
		    		g_message("string");
		    		row->putExtra(key,string((const char*) sqlite3_column_text(m_stmt,col)));
		    		break;
		    	case SQLITE_NULL:
		    		g_message("null");
		    		row->putExtra(key,string(""));
		    		break;
		    	default:
		    		break;
		    }
		}
		this->m_result.push_back(row);
	}

	if(rc != SQLITE_DONE){
		g_error("Select Query Error: %s",sqlite3_errmsg(this->m_connection));
	}

	if(this->m_result.empty()){
        this->m_result.push_back(BundleFacade::get());
	}

    g_message("SQLiteStatement: Returning Result");
	return this->m_result;
}
예제 #16
0
 void deserialize_pms_match(sqlite3* db, MatcherParameters & pms_match, int64_t & id) {
     sqlite3_stmt *read;
     db_prepare(db, read, boost::format(
         "select matcher_type, knn, do_ratio_test, ratio_threshold "
         "from pms_match where id=%d;") % id);
     db_step(read, SQLITE_ROW);
     int c = 0;
     pms_match.type = string((const char*) sqlite3_column_text(read, c++));
     pms_match.knn = sqlite3_column_int(read, c++);
     pms_match.doRatioTest = sqlite3_column_int(read, c++);
     pms_match.ratioThreshold = sqlite3_column_double(read, c++);
     sqlite3_finalize(read);
 }
예제 #17
0
파일: save.cpp 프로젝트: teritriano/ftf
float fff::_save::getMeters(){
    sqlite3_stmt *stmt = NULL;
    if (sqlite3_prepare_v2(db, \
    "SELECT meters FROM game"\
    , -1, &stmt, NULL) != SQLITE_OK){
        std::cout << sqlite3_errmsg(db) << std::endl;
    }
    float meters = 0.f;
    sqlite3_step(stmt);
    meters = sqlite3_column_double(stmt, 0);
    sqlite3_finalize(stmt);
    return meters;
}
jdouble JNICALL Java_com_baidu_javalite_PrepareStmt_sqlite3_1column_1double(
        JNIEnv *env, jclass cls, jlong handle, jint column)
{
  if (handle == 0)
  {
    throwSqliteException(env, "handle is NULL");
    return 0;
  }

  sqlite3_stmt* stmt = (sqlite3_stmt*) handle;

  return sqlite3_column_double(stmt, column);
}
예제 #19
0
REFloat64 RESQLiteDBResultSet::floatForColumnIndex(const REUInt32 index) const
{
#if (IS_RE_USING_SQLITE)
	if ( _st ) 
	{
		if ( index < _st->columnsNames->count() ) 
		{
			return sqlite3_column_double((sqlite3_stmt*)_st->statement, (int)index);
		}
	}
#endif	
	return 0.0;
}
void PlaceDatabase::extractTransform(tf::Transform& xfm, int start_index) const
{
  xfm.getOrigin().setValue(sqlite3_column_double(select_transforms_stmt_, start_index),
                           sqlite3_column_double(select_transforms_stmt_, start_index + 1),
                           sqlite3_column_double(select_transforms_stmt_, start_index + 2));

  tf::Quaternion q(sqlite3_column_double(select_transforms_stmt_, start_index + 3),
                 sqlite3_column_double(select_transforms_stmt_, start_index + 4),
                 sqlite3_column_double(select_transforms_stmt_, start_index + 5),
                 sqlite3_column_double(select_transforms_stmt_, start_index + 6));
  xfm.setRotation(q);
}
예제 #21
0
double DB::Result::getDouble(unsigned int fieldidx)
{
	if (!isValid()) {
		DB::logError("Result::getDouble: statement is not valid");
		return 0.0;
	}
	if (fieldidx == 0) {
		DB::logError("Result: zero is an invalid field index");
		return 0.0;
	}
	double value = sqlite3_column_double(_handle->_stmt, fieldidx-1);
	reportError(_handle->_stmt);
	return value;
}
예제 #22
0
파일: cfacdb.c 프로젝트: mbelkhir/cfac
int cfacdb_cstates(cfacdb_t *cdb, cfacdb_cstates_sink_t sink, void *udata)
{
    sqlite3_stmt *stmt;
    const char *sql;
    int rc;
    
    if (!cdb) {
        return CFACDB_FAILURE;
    }
    
    sql = "SELECT nele, e_gs, nlevels" \
          " FROM _cstates_v" \
          " WHERE sid = ? AND nele <= ? AND nele >= ?" \
          " ORDER BY nele DESC";
    sqlite3_prepare_v2(cdb->db, sql, -1, &stmt, NULL);
    sqlite3_bind_int(stmt, 1, cdb->sid);
    sqlite3_bind_int(stmt, 2, cdb->nele_max);
    sqlite3_bind_int(stmt, 3, cdb->nele_min);
    
    do {
        cfacdb_cstates_data_t cbdata;
        
        rc = sqlite3_step(stmt);
        switch (rc) {
        case SQLITE_DONE:
        case SQLITE_OK:
            break;
        case SQLITE_ROW:
            cbdata.nele    = sqlite3_column_int   (stmt, 0);
            cbdata.e_gs    = sqlite3_column_double(stmt, 1);
            cbdata.nlevels = sqlite3_column_int   (stmt, 2);
            
            if (sink(cdb, &cbdata, udata) != CFACDB_SUCCESS) {
                sqlite3_finalize(stmt);
                return CFACDB_FAILURE;
            }
            
            break;
        default:
            fprintf(stderr, "SQL error: %s\n", sqlite3_errmsg(cdb->db));
            sqlite3_finalize(stmt);
            return CFACDB_FAILURE;
            break;
        }
    } while (rc == SQLITE_ROW);
    
    sqlite3_finalize(stmt);
    
    return CFACDB_SUCCESS;
}
예제 #23
0
int cduck_db_fetch_statistics ( const char* ip, time_t minimum, cduck_db_host_stats* statistics )
{
	int rc;
	sqlite3_stmt* statement;
	sqlite3_prepare_v2(db, "SELECT cpu_count, cpu_power, cpu_usage, available_ram, used_ram FROM hosts WHERE ip = ?1 AND stat_time > ?2", -1, &statement, NULL);
	sqlite3_bind_text(statement, 1, ip, strlen(ip), SQLITE_STATIC);
	sqlite3_bind_int64(statement, 2, minimum);
	if (sqlite3_step(statement) == SQLITE_ROW)
	{
		rc = 0;
		statistics->cpu_count = sqlite3_column_int64(statement, 0);
		statistics->cpu_power = sqlite3_column_double(statement, 1);
		statistics->cpu_usage = sqlite3_column_double(statement, 2);
		statistics->available_ram = sqlite3_column_int64(statement, 3);
		statistics->used_ram = sqlite3_column_int64(statement, 4);
	}
	else
	{
		rc = 1;
	}
	sqlite3_finalize(statement);
	return rc;
}
SWIGEXPORT jdouble JNICALL Java_com_almworks_sqlite4java__1SQLiteSwiggedJNI_sqlite3_1column_1double(JNIEnv *jenv, jclass jcls, jlong jarg1, jint jarg2) {
  jdouble jresult = 0 ;
  sqlite3_stmt *arg1 = (sqlite3_stmt *) 0 ;
  int arg2 ;
  double result;
  
  (void)jenv;
  (void)jcls;
  arg1 = *(sqlite3_stmt **)&jarg1; 
  arg2 = (int)jarg2; 
  result = (double)sqlite3_column_double(arg1,arg2);
  jresult = (jdouble)result; 
  return jresult;
}
예제 #25
0
	void sqlite_table::retrieve_data(sqlite3_stmt* stmt)
	{
		tu_autolock locker(s_sqlite_plugin_mutex);

		int col_count = sqlite3_column_count(stmt);
		m_title.resize(col_count);
		for (int i = 0; i < col_count; i++)
		{
			m_title[i] = sqlite3_column_name(stmt, i);
		}
 
		int rc;
		do
		{
			as_object* row = new as_object(get_player());
			m_data.push_back(row);

			for (int i = 0; i < col_count; i++)
			{
				as_value val;
				int col_type = sqlite3_column_type(stmt, i);
				switch (col_type)
				{
					case SQLITE_INTEGER :
						val.set_int(sqlite3_column_int(stmt, i));
						break;
					case SQLITE_FLOAT :
						val.set_double(sqlite3_column_double(stmt, i));
						break;
					case SQLITE_BLOB :
// FIXME:						val.set_string((const char*) sqlite3_column_blob(stmt, i));
						break;
					case SQLITE_NULL :
//						val.set_null();
						val.set_string("");
						break;
					case SQLITE3_TEXT :
						val.set_string((const char*) sqlite3_column_text(stmt, i));
						break;
					default:
						assert(0);
						break;
				}
				row->set_member(m_title[i], val);
			}
			rc = sqlite3_step(stmt);
		}
		while (rc == SQLITE_ROW);
	}
예제 #26
0
void genGateKeeperApprovedAppRow(sqlite3_stmt* const stmt, Row& r) {
  for (int i = 0; i < sqlite3_column_count(stmt); i++) {
    auto column_name = std::string(sqlite3_column_name(stmt, i));
    auto column_type = sqlite3_column_type(stmt, i);
    if (column_type == SQLITE_TEXT) {
      auto value = sqlite3_column_text(stmt, i);
      if (value != nullptr) {
        r[column_name] = std::string(reinterpret_cast<const char*>(value));
      }
    } else if (column_type == SQLITE_FLOAT) {
      auto value = sqlite3_column_double(stmt, i);
      r[column_name] = DOUBLE(value);
    }
  }
}
static void fill_musician(sqlite3_stmt * stmt, musician_t * fl)
{
    int id = sqlite3_column_int(stmt, 0);
    const unsigned char * name = sqlite3_column_text(stmt, 1);
    const unsigned char * surname = sqlite3_column_text(stmt, 2);
    double salary = sqlite3_column_double(stmt, 3);
    int instr = sqlite3_column_int(stmt, 4);
    const unsigned char * birthDate =  sqlite3_column_text(stmt, 5);
    strcpy(fl->name, (char *)name);
    strcpy(fl->surname, (char *)surname);
    fl->id = id;
    fl->instr = instr;
    fl->salary = salary;
    strcpy(fl->birthDate, (char *)birthDate);
}
예제 #28
0
void SongDatabase::GetPreviewInfo(int SongID, GString &Filename, float &PreviewStart)
{
	int ret;
	SC(sqlite3_bind_int(st_GetPreviewInfo, 1, SongID));
	SCS(sqlite3_step(st_GetPreviewInfo));

	const char* sOut = (const char*)sqlite3_column_text(st_GetPreviewInfo, 0);
	float fOut = sqlite3_column_double(st_GetPreviewInfo, 1);

	GString Out = sOut ? sOut : "";

	SC(sqlite3_reset(st_GetPreviewInfo));
	Filename = Out;
	PreviewStart = fOut;
}
예제 #29
0
/**
@SYMTestCaseID			SYSLIB-SQLITE3-UT-4025
@SYMTestCaseDesc		SQLite library single-select performance test.
						The test selects one record and stores 
						the execution time for later use (comparison and printing).
						The ID of the selected record is exactly the same as the ID of the selected
						record, used by SYSLIB-SQLITE3-UT-4017 test case.
						The results of this test case will be compared against the results of
						the SYSLIB-SQLITE3-UT-4017 test case - "SQL server single-select performance test".
@SYMTestPriority		High
@SYMTestActions			SQLite library single-select performance test.
@SYMTestExpectedResults Test must not fail
@SYMREQ					REQ8782
*/
void SqliteSingleSelectTest(TPerfTestMode aPerfTestMode, const char aSingleSelectSql[], TInt aSelectRecId)
	{
	int err;
	const char* tail = 0;
	sqlite3_stmt* stmt = 0;
	int recCnt = 0;
	unsigned int fc;
	char tmp[10];
	
	TEST(aPerfTestMode > EPerfTestSqlMode && aPerfTestMode < EPerfTestModeCnt);
	TEST(!TheDb2);
	err = sqlite3_open(TestDbName(), &TheDb2);
	TEST2(err, SQLITE_OK);
	ExecSqliteConfig(aPerfTestMode);

	sprintf(tmp, "%d", aSelectRecId);
	strcpy(TheSqlBuf2, aSingleSelectSql);
	strcat(TheSqlBuf2, tmp);
	
	err = sqlite3_prepare(TheDb2, TheSqlBuf2, -1, &stmt, &tail);
	TEST2(err, SQLITE_OK);
	
	fc = FastCounterValue();
	while((err = sqlite3_step(stmt)) == SQLITE_ROW)
		{
		__int64 i64;
		double d;
		const unsigned short* t;
		const unsigned char* b;
		
		i64 = sqlite3_column_int64(stmt, 0);
		UNUSED_VAR(i64);
		d = sqlite3_column_double(stmt, 1);
		UNUSED_VAR(d);
		t = (const unsigned short*)sqlite3_column_text16(stmt, 2);
		UNUSED_VAR(t);
		b = (const unsigned char*)sqlite3_column_blob(stmt, 3);
		UNUSED_VAR(b);
		++recCnt;
		}
	StorePerfTestResult(aPerfTestMode, EPerfTestSingleSelect, FastCounterValue() - fc);
	TEST2(err, SQLITE_DONE);
	TEST2(recCnt, 1);

	sqlite3_finalize(stmt);	
	sqlite3_close(TheDb2);
	TheDb2 = 0;
	}
예제 #30
0
파일: Member.cpp 프로젝트: pasu/EasyFood
void Member::FillGrid()
{
	sqlite3_stmt* ppStmt = NULL;

	const char* getCount = "select count(*) from member";
	int ret = sqlite3_prepare(conn, getCount, -1, &ppStmt, /*&tail*/0);
	ret = sqlite3_step(ppStmt);
	int nCount = sqlite3_column_int(ppStmt, 0);
	m_Grid.SetRowCount(nCount+1);
	sqlite3_finalize(ppStmt);

	int i = 1;

	const char *ps ="select * from member";
	const char **pzTail = &ps;
	ret = sqlite3_prepare_v2(conn,ps,-1,&ppStmt,pzTail);
	
	ret = sqlite3_step(ppStmt);//sqlite3_step返回值
	CString strDes;

	//int nCount = sqlite3_;
	

	while(ret!=SQLITE_DONE)//当前表还没用读完
	{
		int id = sqlite3_column_int(ppStmt,0);
		strDes.Format("%d",id);
		m_Grid.SetItemText(i,0,strDes);
		const char* name = (const char*)sqlite3_column_text(ppStmt,1);
		strDes.Format("%s",name);
		m_Grid.SetItemText(i,1,strDes);
		float money = sqlite3_column_double(ppStmt,2);
		strDes.Format("%f",money);
		m_Grid.SetItemText(i,2,strDes);
		ret = sqlite3_step(ppStmt);
		i++;
	}
	
	for(i=1;i<nCount+1;i++)
	{
		m_Grid.SetItemState(i,0,GVIS_READONLY);
		m_Grid.SetItemState(i,1,GVIS_READONLY);
		m_Grid.SetItemState(i,2,GVIS_READONLY);
	}
	sqlite3_finalize(ppStmt);

	//m_Grid.EnableScrollBars(SB_VERT,1);
}