/* creates a new dir_info from that statement passed */ static inline struct mp3_info* create_from_stmt( sqlite3_stmt* res ) { struct mp3_info* tmp = malloc(sizeof(struct mp3_info)); memset( tmp, 0, sizeof(struct dir_info)); /* set the data */ tmp->oid = sqlite3_column_int ( res, 0 ); /* have to use strdup so the pointers are not deleted on finalize */ tmp->title = strdup( (char*)sqlite3_column_text( res, 1 ) ); tmp->artist = strdup( (char*)sqlite3_column_text( res, 2 ) ); tmp->album = strdup( (char*)sqlite3_column_text( res, 3 ) ); const void* blob = sqlite3_column_blob( res, 4 ); size_t blob_bytes = sqlite3_column_bytes( res, 4 ); tmp->metadata = malloc( tmp->metadata_blob_len = blob_bytes ); memcpy( tmp->metadata, blob, blob_bytes ); return tmp; }
/* * Gather the results into list_entry format. Each row has page, number, len, * value. Look at queries in attr_get_attr attr_get_attr_page. See page 163. * * -EINVAL: invalid argument * -EOVERFLOW: error, if not enough room to even start the entry * >0: success. returns number of bytes copied into outbuf. */ static int attr_gather_attr(sqlite3_stmt *stmt, void *buf, uint32_t buflen, uint64_t oid, uint8_t listfmt) { uint32_t page = sqlite3_column_int(stmt, 0); uint32_t number = sqlite3_column_int(stmt, 1); uint16_t len = sqlite3_column_bytes(stmt, 2); const void *val = sqlite3_column_blob(stmt, 2); if (listfmt == RTRVD_SET_ATTR_LIST) { return le_pack_attr(buf, buflen, page, number, len, val); } else if (listfmt == RTRVD_MULTIOBJ_LIST) { return le_multiobj_pack_attr(buf, buflen, oid, page, number, len, val); } else if (listfmt == RTRVD_CREATE_MULTIOBJ_LIST) { return le_create_multiobj_pack_attr(buf, buflen, oid, page, number, len, val); } else { return -EINVAL; } }
/*! * * @param field * @return */ QString Address::searchDB(const char* field) const{ ostringstream sqlCmmd; sqlCmmd << "SELECT " << field << " FROM ics_addresses WHERE a_customer='" << customer.toStdString() << "';"; sqlite3_stmt* stmt; int rc = sqlite3_prepare_v2(db, sqlCmmd.str().c_str(), -1, &stmt, NULL); rc = sqlite3_step(stmt); if(rc != SQLITE_DONE){ return QString(static_cast<const char*>(sqlite3_column_blob(stmt, 0))); } else{ return ""; } }
/* ** Print the content of a segment or of the root of a segdir. The segment ** or root is identified by azExtra[0]. If the first character of azExtra[0] ** is 'r' then the remainder is the integer rowid of the %_segdir entry. ** If the first character of azExtra[0] is not 'r' then, then all of ** azExtra[0] is an integer which is the block number. ** ** If the --raw option is present in azExtra, then a hex dump is provided. ** Otherwise a decoding is shown. */ static void showSegment(sqlite3 *db, const char *zTab) { const unsigned char *aData; int nData; sqlite3_stmt *pStmt; pStmt = prepareToGetSegment(db, zTab, azExtra[0]); if( sqlite3_step(pStmt)!=SQLITE_ROW ) { sqlite3_finalize(pStmt); return; } nData = sqlite3_column_bytes(pStmt, 0); aData = sqlite3_column_blob(pStmt, 0); printf("Segment %s of size %d bytes:\n", azExtra[0], nData); if( findOption("raw", 0, 0)!=0 ) { printBlob(aData, nData); } else { decodeSegment(aData, nData); } sqlite3_finalize(pStmt); }
/* * packs contents of an attribute of dir page. Note that even though the * query selects 'page', the resultant rows are actually rows 'numbers' * within directory page. * * returns: * -EINVAL: invalid argument, or length(attribute value) != 40 * -EOVERFLOW: outlen too small * >0: success, number of bytes copied into outdata */ static int attr_gather_dir_page(sqlite3_stmt *stmt, uint32_t outlen, void *outdata, uint64_t oid, uint32_t page, uint8_t listfmt) { uint32_t number = sqlite3_column_int(stmt, 0); uint16_t len = sqlite3_column_bytes(stmt, 1); const void *val = sqlite3_column_blob(stmt, 1); if (len != ATTR_PAGE_ID_LEN) return -EINVAL; if (listfmt == RTRVD_SET_ATTR_LIST) { return le_pack_attr(outdata, outlen, page, number, len, val); } else if (listfmt == RTRVD_CREATE_MULTIOBJ_LIST) { return le_multiobj_pack_attr(outdata, outlen, oid, page, number, len, val); } else { return -EINVAL; } }
void MapDatabaseSQLite3::loadBlock(const v3s16 &pos, std::string *block) { verifyDatabase(); bindPos(m_stmt_read, pos); if (sqlite3_step(m_stmt_read) != SQLITE_ROW) { sqlite3_reset(m_stmt_read); return; } const char *data = (const char *) sqlite3_column_blob(m_stmt_read, 0); size_t len = sqlite3_column_bytes(m_stmt_read, 0); *block = (data) ? std::string(data, len) : ""; sqlite3_step(m_stmt_read); // We should never get more than 1 row, so ok to reset sqlite3_reset(m_stmt_read); }
Blob Sqlite3ConsumerDb::getKey(const Name& keyName) { sqlite3_stmt *statement; sqlite3_prepare_v2 (database_, "SELECT key_buf FROM decryptionkeys WHERE key_name=?", -1, &statement, 0); sqlite3_bind_blob(statement, 1, keyName.wireEncode(), SQLITE_TRANSIENT); int res = sqlite3_step(statement); Blob key; if (res == SQLITE_ROW) key = Blob (static_cast<const uint8_t*>(sqlite3_column_blob(statement, 0)), sqlite3_column_bytes(statement, 0)); sqlite3_finalize(statement); return key; }
bool DBBrowserDB::getRow(const QString& sTableName, int rowid, QList<QByteArray>& rowdata) { QString sQuery = QString("SELECT * from %1 WHERE rowid=%2;").arg(sTableName).arg(rowid); QByteArray utf8Query = sQuery.toUtf8(); sqlite3_stmt *stmt; int status = sqlite3_prepare_v2(_db, utf8Query, utf8Query.size(), &stmt, NULL); if(SQLITE_OK == status) { // even this is a while loop, the statement should always only return 1 row while(sqlite3_step(stmt) == SQLITE_ROW) { for (int i = 0; i < sqlite3_column_count(stmt); ++i) rowdata.append(QByteArray(static_cast<const char*>(sqlite3_column_blob(stmt, i)), sqlite3_column_bytes(stmt, i))); } } sqlite3_finalize(stmt); return status == SQLITE_OK; }
// ================================ // gbDB_GetNextRowFromMassTileRead: // ================================ // // Unused / deprecated. // int gbDB_GetNextRowFromMassTileRead(sqlite3* database, sqlite3_stmt* selStmt, void** tileData, size_t* tileDataBytes, int* dataCount, uint32_t* x, uint32_t* y) { int sqliteStepResult = sqlite3_step(selStmt); uint32_t _x = -1; uint32_t _y = -1; int _dataCount = 0; void* _tileData = NULL; size_t _tileDataBytes = 0; // -- 1. read row with tile, store in temp vector -- if (sqliteStepResult == SQLITE_ROW) { _x = (uint32_t)sqlite3_column_int(selStmt, 0); _y = (uint32_t)sqlite3_column_int(selStmt, 1); _dataCount = sqlite3_column_int(selStmt, 2); const void *blobBytes = sqlite3_column_blob(selStmt, 3); int blobLen = sqlite3_column_bytes(selStmt, 3); if (blobLen > 0) { _tileDataBytes = blobLen; _tileData = malloc(_tileDataBytes); memcpy(_tileData, blobBytes, _tileDataBytes); }//if }//if *tileData = _tileData; *tileDataBytes = _tileDataBytes; *x = _x; *y = _y; *dataCount = _dataCount; return sqliteStepResult; }//gbDB_GetNextRowFromMassTileRead
BYTE * CSQLite::ReadScorcoData(const char * SQL, const char * param, BOOL * pSqlError, int * size) { int rc; const void* pBlob; if (strcmp(param, "FETCHMODE") != 0) { finalizeStatement(); rc = sqlite3_prepare(sdb, SQL, -1, &pStmt, NULL); if (rc != SQLITE_OK) { strcpy(lastError, sqlite3_errmsg(sdb)); finalizeStatement(); *pSqlError = true; return NULL; } } // execute step rc = sqlite3_step(pStmt); if (rc == SQLITE_ERROR) { strcpy(lastError, sqlite3_errmsg(sdb)); *pSqlError = true; finalizeStatement(); return NULL; } *pSqlError = false; if (rc == SQLITE_ROW) { unsigned long length = sqlite3_column_bytes(pStmt, 0); *size = length; if (length == 0) return NULL; char* buf = new char[length]; if (buf == NULL) return NULL; pBlob = sqlite3_column_blob(pStmt, 0); if (pBlob == NULL) { delete [] buf; return NULL; } memcpy(buf, pBlob, length); return (BYTE*)buf; // NWN VM will delete this block of memory } else if (rc == SQLITE_DONE) { finalizeStatement(); } return NULL; }
/* * stack_res_get * --------------------------------------------------------------------------------------------- * Accesses the details and/or data of the resource with the specified ID and type. * Returns STACK_YES on success, STACK_NO otherwise. * * Only returns the arguments for which a non-NULL pointer is supplied. * * The result string and data remain valid until the next call, the stack is closed or * stack_res_type_n() is invoked. * * An error can occur because the resource cannot be found or because of an I/O error. */ int stack_res_get(Stack *in_stack, int in_id, char const *in_type, char **out_name, void **out_data, long *out_size) { assert(IS_STACK(in_stack)); assert(in_id >= 1); if (in_stack->_returned_res_str) _stack_free(in_stack->_returned_res_str); in_stack->_returned_res_str = NULL; if (in_stack->_returned_res_data) _stack_free(in_stack->_returned_res_data); in_stack->_returned_res_data = NULL; long data_size = 0; sqlite3_stmt *stmt; sqlite3_prepare_v2(in_stack->db, "SELECT resourcename,data FROM resource WHERE resourceid=?1 AND resourcetype=?2", -1, &stmt, NULL); sqlite3_bind_int(stmt, 1, in_id); sqlite3_bind_text(stmt, 2, in_type, -1, SQLITE_STATIC); int err = sqlite3_step(stmt); if (err == SQLITE_ROW) { in_stack->_returned_res_str = _stack_clone_cstr((char*)sqlite3_column_text(stmt, 0)); data_size = sqlite3_column_bytes(stmt, 1); in_stack->_returned_res_data = _stack_malloc(data_size); if (!in_stack->_returned_res_data) { _stack_panic_void(in_stack, STACK_ERR_MEMORY); sqlite3_finalize(stmt); return STACK_NO; } else memcpy(in_stack->_returned_res_data, sqlite3_column_blob(stmt, 1), data_size); } sqlite3_finalize(stmt); if (err == SQLITE_ROW) { if (out_name) *out_name = in_stack->_returned_res_str; if (out_data) *out_data = in_stack->_returned_res_data; if (out_size) *out_size = data_size; return STACK_YES; } else return STACK_NO; }
bool getAvatar(const std::string &db_path, const std::string &name, std::string &photo) { bool ret = false; sqlite3 *db; LOG4CXX_INFO(logger, "Opening database " << db_path); if (sqlite3_open(db_path.c_str(), &db)) { sqlite3_close(db); LOG4CXX_ERROR(logger, "Can't open database"); } else { sqlite3_stmt *stmt; PREP_STMT(stmt, "SELECT avatar_image FROM Contacts WHERE skypename=?"); if (stmt) { BEGIN(stmt); BIND_STR(stmt, name); if(sqlite3_step(stmt) == SQLITE_ROW) { int size = sqlite3_column_bytes(stmt, 0); if (size > 0) { const void *data = sqlite3_column_blob(stmt, 0); photo = std::string((const char *)data + 1, size - 1); ret = true; } else { ret = false; } } else { LOG4CXX_ERROR(logger, (sqlite3_errmsg(db) == NULL ? "" : sqlite3_errmsg(db))); } int ret; while((ret = sqlite3_step(stmt)) == SQLITE_ROW) { } FINALIZE_STMT(stmt); } else { LOG4CXX_ERROR(logger, "Can't create prepared statement"); LOG4CXX_ERROR(logger, (sqlite3_errmsg(db) == NULL ? "" : sqlite3_errmsg(db))); } sqlite3_close(db); } return ret; }
int print_col(sqlite3_stmt * pTableInfo, int col) { int fd; static int ct = 0; char outfile[50]; switch (sqlite3_column_type(pTableInfo, col)) { case SQLITE_INTEGER: printf("%d ", sqlite3_column_int(pTableInfo, col)); break; case SQLITE_FLOAT: printf("%f ", sqlite3_column_double(pTableInfo, col)); break; case SQLITE_TEXT: printf("%s ", sqlite3_column_text(pTableInfo, col)); break; case SQLITE_BLOB: //printf("%s",sqlite3_column_blob(pTableInfo, col)); /* fprintf(stderr, "IN BLOB bytes %d\n", sqlite3_column_bytes(pTableInfo, col)); */ snprintf(outfile, 20, "outdata.%d.png", ct++); if ((fd = open(outfile, O_RDWR | O_CREAT, 0600)) == -1) { fprintf(stderr, "Can't open data: %s\n", strerror(errno)); return 1; } write(fd, sqlite3_column_blob(pTableInfo, col), sqlite3_column_bytes(pTableInfo, col)); close(fd); break; case SQLITE_NULL: printf("Null "); break; default: printf(" *Cannot determine SQLITE TYPE* col=%d ", col); } return 0; }
void db_query_value(struct db_query *query, uint8_t **value, size_t *size, int *raw, int *id) { const void *data; int n; *raw = sqlite3_column_int(query->stmt, 1); *id = sqlite3_column_int(query->stmt, 2); if(value == NULL) return; if( (data = sqlite3_column_blob(query->stmt, 0)) == NULL) err_panic(0, "column data is NULL: %s", sqlite3_errmsg(g.handle)); if( (n = sqlite3_column_bytes(query->stmt, 0)) < 0) err_panic(0, "value size is negative"); *size = n; if(*size > 0) { *value = talloc_array(NULL, uint8_t, *size); memcpy(*value, data, *size); } }
/*! * * @param username * @param password * @return */ Customer* Database::loginAsCustomer(QString username, QString password){ unsigned* digest = encryptPassword(password); Customer* customer; if(validateCustomerLogin(username, digest)){ ostringstream sqlCmmd; sqlCmmd << "SELECT cl_customer FROM ics_customer_logins WHERE cl_username = '******'"; sqlite3_stmt* stmt; sqlite3_prepare_v2(connection, sqlCmmd.str().c_str(), -1, &stmt, NULL); sqlite3_step(stmt); customer = new Customer(connection, QString(static_cast<const char*>(sqlite3_column_blob(stmt, 0)))); } else{ ostringstream ex; ex << "Invalid login by " << username.toStdString(); throw new InvalidLoginException(ex.str().c_str()); } return customer; }
//============================================================================ // NDBResult::GetValueData : Get a data value. //---------------------------------------------------------------------------- NData NDBResult::GetValueData(NIndex theIndex) const { NData theResult; const void *thePtr; NIndex theSize; // Validate our parameters NN_ASSERT(theIndex < GetSize()); // Get the value thePtr = (const void *) sqlite3_column_blob( (sqlite3_stmt *) mResult, theIndex); theSize = (NIndex ) sqlite3_column_bytes((sqlite3_stmt *) mResult, theIndex); if (thePtr != NULL && theSize != 0) theResult.AppendData(theSize, thePtr); return(theResult); }
String SQLiteStatement::getColumnBlobAsString(int col) { ASSERT(col >= 0); if (!m_statement && prepareAndStep() != SQLITE_ROW) return String(); if (columnCount() <= col) return String(); const void* blob = sqlite3_column_blob(m_statement, col); if (!blob) return String(); int size = sqlite3_column_bytes(m_statement, col); if (size < 0) return String(); ASSERT(!(size % sizeof(UChar))); return String(static_cast<const UChar*>(blob), size / sizeof(UChar)); }
void QgsSpatiaLiteFeatureIterator::getFeatureGeometry( sqlite3_stmt* stmt, int ic, QgsFeature& feature ) { if ( sqlite3_column_type( stmt, ic ) == SQLITE_BLOB ) { unsigned char *featureGeom = NULL; size_t geom_size = 0; const void *blob = sqlite3_column_blob( stmt, ic ); size_t blob_size = sqlite3_column_bytes( stmt, ic ); QgsSpatiaLiteProvider::convertToGeosWKB(( const unsigned char * )blob, blob_size, &featureGeom, &geom_size ); if ( featureGeom ) feature.setGeometryAndOwnership( featureGeom, geom_size ); else feature.setGeometryAndOwnership( 0, 0 ); } else { // NULL geometry feature.setGeometryAndOwnership( 0, 0 ); } }
float zDBBinaryReader::ToSingle(int offset) { int cb = sizeof(float); // Number of bytes to alloc/copy const unsigned char* puData; // Pointer into raw data array<System::Byte>^ rg; // Managed byte array of data PinnedBytePtr pinRg; // Pinned pointer into rg[] CHECK_DISPOSED(m_disposed); if(offset < 0) throw gcnew ArgumentException(); if(offset > (m_cb - cb)) throw gcnew ArgumentOutOfRangeException(); rg = gcnew array<System::Byte>(cb); // Allocate the local buffer pinRg = &rg[0]; // Pin it down for memcpy_s // Copy only the amount of data we specifically need from SQLite, and attempt // to convert it using a standard binary conversion mechanism puData = reinterpret_cast<const unsigned char*>(sqlite3_column_blob(m_pStatement->Handle, m_ordinal)); memcpy_s(pinRg, cb, puData + offset, cb); return BitConverter::ToSingle(rg, 0); }
/* ** Load a list of Blob objects from the database */ static void blobListLoadFromDb( sqlite3 *db, /* Read from this database */ const char *zSql, /* Query used to extract the blobs */ int onlyId, /* Only load where id is this value */ int *pN, /* OUT: Write number of blobs loaded here */ Blob **ppList /* OUT: Write the head of the blob list here */ ){ Blob head; Blob *p; sqlite3_stmt *pStmt; int n = 0; int rc; char *z2; if( onlyId>0 ){ z2 = sqlite3_mprintf("%s WHERE rowid=%d", zSql, onlyId); }else{ z2 = sqlite3_mprintf("%s", zSql); } rc = sqlite3_prepare_v2(db, z2, -1, &pStmt, 0); sqlite3_free(z2); if( rc ) fatalError("%s", sqlite3_errmsg(db)); head.pNext = 0; p = &head; while( SQLITE_ROW==sqlite3_step(pStmt) ){ int sz = sqlite3_column_bytes(pStmt, 1); Blob *pNew = safe_realloc(0, sizeof(*pNew)+sz ); pNew->id = sqlite3_column_int(pStmt, 0); pNew->sz = sz; pNew->seq = n++; pNew->pNext = 0; memcpy(pNew->a, sqlite3_column_blob(pStmt,1), sz); pNew->a[sz] = 0; p->pNext = pNew; p = pNew; } sqlite3_finalize(pStmt); *pN = n; *ppList = head.pNext; }
static bool read_chunk_sqlite(unsigned char *chunk, const unsigned char *digest, void *db_info_ptr) { static const char sql[] = "SELECT data FROM chunk WHERE hash = ?"; struct db_info *db_info = db_info_ptr; sqlite3_stmt *stmt; int err; bool status = false; lock_db(db_info); err = sqlite3_prepare(db_info->db, sql, -1, &stmt, 0); if (err != SQLITE_OK) { ERROR("sqlite3_prepare failed: %d\n", sqlite3_errmsg(db_info->db)); unlock_db(db_info); return false; } TRACE("%s\n", digest_string(digest)); sqlite3_bind_text(stmt, 1, digest_string(digest), -1, SQLITE_STATIC); err = sqlite3_step(stmt); if (err != SQLITE_ROW) { ERROR("sqlite3_step failed: %s\n", sqlite3_errmsg(db_info->db)); } else if (sqlite3_column_bytes(stmt, 0) != CHUNK_SIZE) { ERROR("sqlite3 query returned %d bytes instead of %d.\n", sqlite3_column_bytes(stmt, 0), CHUNK_SIZE); } else { TRACE("sqlite3 query got chunk.\n"); memcpy(chunk, sqlite3_column_blob(stmt, 0), CHUNK_SIZE); status = true; } sqlite3_finalize(stmt); unlock_db(db_info); return status; }
sf::SoundBuffer* ResourceManager::getSoundBuffer(std::string filename) { if (mSoundBuffers.count(filename) > 0) { return mSoundBuffers.at(filename); } int rc; std::string query = "SELECT bytes FROM files " "WHERE name='" + filename + "';"; sqlite3_stmt *stmt; rc = sqlite3_prepare_v2(mDB, query.c_str(), -1, &stmt, NULL); if(rc != SQLITE_OK){ std::cerr << "Could not prepare query: " << sqlite3_errmsg(mDB) << std::endl; sqlite3_finalize(stmt); throw ErrorCode(EC_DB_FAILURE); } rc = sqlite3_step(stmt); if(rc != SQLITE_ROW){ std::cerr << "Could not execute query: " << sqlite3_errmsg(mDB) << std::endl; sqlite3_finalize(stmt); throw ErrorCode(EC_DB_FAILURE); } const void* data = sqlite3_column_blob(stmt, 0); size_t data_size = sqlite3_column_bytes(stmt, 0); sf::SoundBuffer* soundBuffer = new sf::SoundBuffer(); if (!soundBuffer->loadFromMemory(data, data_size)) { throw ErrorCode(EC_AUDIO_FAILURE); } mSoundBuffers[filename] = soundBuffer; sqlite3_finalize(stmt); return soundBuffer; }
void O2DatDB:: get_columns(sqlite3_stmt* stmt, wstrarray &cols) { __int64 t_int; double t_float; wstring t_text; byte *t_byte; int size; wchar_t tmp[1024]; int column_count = sqlite3_column_count(stmt); for (int i = 0; i < column_count; i++) { switch (sqlite3_column_type(stmt, i)) { case SQLITE_INTEGER: t_int = sqlite3_column_int64 (stmt, i); swprintf_s(tmp, 1024, L"%I64u", t_int); cols.push_back(tmp); break; case SQLITE_FLOAT: t_float = sqlite3_column_double(stmt, i); swprintf_s(tmp, 1024, L"%lf", t_float); cols.push_back(tmp); break; case SQLITE_TEXT: t_text = (wchar_t*)sqlite3_column_text16(stmt, i); cols.push_back(t_text); break; case SQLITE_BLOB: size = sqlite3_column_bytes(stmt, i); t_byte = new byte[size]; memcpy(t_byte, (byte*)sqlite3_column_blob(stmt, i), size); byte2whex(t_byte, size, t_text); cols.push_back(t_text); delete [] t_byte; break; } } }
/* ** Print the content of a doclist. The segment or segdir-root is ** identified by azExtra[0]. If the first character of azExtra[0] ** is 'r' then the remainder is the integer rowid of the %_segdir entry. ** If the first character of azExtra[0] is not 'r' then, then all of ** azExtra[0] is an integer which is the block number. The offset ** into the segment is identified by azExtra[1]. The size of the doclist ** is azExtra[2]. ** ** If the --raw option is present in azExtra, then a hex dump is provided. ** Otherwise a decoding is shown. */ static void showDoclist(sqlite3 *db, const char *zTab){ const unsigned char *aData; sqlite3_int64 offset, nData; sqlite3_stmt *pStmt; offset = atoi64(azExtra[1]); nData = atoi64(azExtra[2]); pStmt = prepareToGetSegment(db, zTab, azExtra[0]); if( sqlite3_step(pStmt)!=SQLITE_ROW ){ sqlite3_finalize(pStmt); return; } aData = sqlite3_column_blob(pStmt, 0); printf("Doclist at %s offset %lld of size %lld bytes:\n", azExtra[0], offset, nData); if( findOption("raw", 0, 0)!=0 ){ printBlob(aData+offset, nData); }else{ decodeDoclist(aData+offset, nData); } sqlite3_finalize(pStmt); }
static mrb_value row_to_value(mrb_state* mrb, sqlite3_stmt* stmt) { int i; int count = sqlite3_column_count(stmt); mrb_value a = mrb_ary_new(mrb); for (i = 0; i < count; i++) { switch (sqlite3_column_type(stmt, i)) { case SQLITE_INTEGER: { sqlite3_int64 value = sqlite3_column_int64(stmt, i); mrb_ary_push(mrb, a, mrb_fixnum_value((mrb_int) value)); } break; case SQLITE_FLOAT: { double value = sqlite3_column_double(stmt, i); mrb_ary_push(mrb, a, mrb_float_value(mrb, value)); } break; case SQLITE_BLOB: { int size = sqlite3_column_bytes(stmt, i); const char* ptr = sqlite3_column_blob(stmt, i); mrb_ary_push(mrb, a, mrb_str_new(mrb, ptr, size)); } break; case SQLITE_NULL: mrb_ary_push(mrb, a, mrb_nil_value()); break; case SQLITE_TEXT: { const char* value = (const char*) sqlite3_column_text(stmt, i); mrb_ary_push(mrb, a, mrb_str_new_cstr(mrb, value)); } break; } } return a; }
// Retrieve an arbitrary binary value from INI file or registry. BOOL SQLITE3::GetProfileBinary(LPCTSTR lpszSection, LPCTSTR lpszEntry, LPBYTE* ppData, UINT* pBytes, bool fallofftoreg) { CString szSQL; szSQL.Format(_T("SELECT vdata FROM settingbin2 WHERE skey = \"%s\" AND sect = \"%s\" ") , lpszSection, lpszEntry); int iDestLen; char* buff = svpTool.CStringToUTF8(szSQL, &iDestLen); char *tail; sqlite3_stmt *stmt=0; int err = 1; if(sqlite3_prepare_v2(db, buff, strlen(buff), &stmt, 0) == SQLITE_OK) { //printf("Could not prepare statement.\n"); //return; rc = sqlite3_step(stmt); if( rc==SQLITE_ROW ) { int newBlobSize = sqlite3_column_bytes(stmt, 0); if(newBlobSize > 0){ void* buffx = malloc(newBlobSize); *pBytes = newBlobSize; memcpy(buffx, sqlite3_column_blob(stmt, 0), newBlobSize); *ppData = (LPBYTE)buffx; //SVP_LogMsg6("lalalax got bin %d", newBlobSize); err = 0; } } sqlite3_finalize(stmt); } free(buff); if(!err){ return true; }else if (fallofftoreg){ //SVP_LogMsg6("lalalax"); return AfxGetApp()->GetProfileBinary(lpszSection,lpszEntry,ppData,pBytes); } else return false; }
static Value cursor_get_sub(sqlite3_stmt *stmt, int i) { switch (sqlite3_column_type(stmt, i)) { case SQLITE_INTEGER: return fs->int64_Value(sqlite3_column_int64(stmt, i)); case SQLITE_FLOAT: return fs->float_Value(fs->cls_float, sqlite3_column_double(stmt, i)); case SQLITE_TEXT: { const char *p = (const char*)sqlite3_column_text(stmt, i); int len = sqlite3_column_bytes(stmt, i); return fs->cstr_Value(NULL, p, len); } case SQLITE_BLOB: { const char *p = (const char*)sqlite3_column_blob(stmt, i); int len = sqlite3_column_bytes(stmt, i); return fs->cstr_Value(fs->cls_bytes, p, len); } default: break; } return VALUE_NULL; }
// id integer primary key,source text,title text,link text,description blob,read integer bool CSQLite::GetCaches(std::vector<CCache*>* caches, const char* source, int read) { std::stringstream ss; std::string sql; std::string tsource; if(WrapApostrophe(source, &tsource)) source = tsource.c_str(); ss << "select * from " << kCachesTableName << " where source='" << source << "'"; if(read == 1) ss << " and read=1;"; else if(read == 0) ss << " and read=0;"; else ss << ";"; sql = ss.str(); sqlite3_stmt* stmt; if(sqlite3_prepare(m_db, sql.c_str(),-1,&stmt,nullptr) == SQLITE_OK){ int rv; while((rv = sqlite3_step(stmt)) == SQLITE_ROW){ auto pCache = new CCache; pCache->id = sqlite3_column_int(stmt, 0); pCache->source = (const char*)sqlite3_column_text(stmt, 1); pCache->title = (const char*)sqlite3_column_text(stmt, 2); pCache->link = (const char*)sqlite3_column_text(stmt, 3); pCache->description = (const char*)sqlite3_column_blob(stmt, 4); pCache->read = !!sqlite3_column_int(stmt, 5); caches->push_back(pCache); } if(rv != SQLITE_DONE){ throw "未能取得缓存数据!"; } sqlite3_finalize(stmt); return true; } else{ throw "sqlite3错误!"; } return false; }
static gchar* get_active_preset_name(dt_lib_module_info_t *minfo) { sqlite3_stmt *stmt; DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "select name, op_params, writeprotect from presets where operation=?1 and op_version=?2", -1, &stmt, NULL); DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 1, minfo->plugin_name, strlen(minfo->plugin_name), SQLITE_TRANSIENT); DT_DEBUG_SQLITE3_BIND_INT(stmt, 2, minfo->version); gchar *name = NULL; // collect all presets for op from db while(sqlite3_step(stmt) == SQLITE_ROW) { void *op_params = (void *)sqlite3_column_blob(stmt, 1); int32_t op_params_size = sqlite3_column_bytes(stmt, 1); if(op_params_size == minfo->params_size && !memcmp(minfo->params, op_params, op_params_size)) { name = g_strdup((char *)sqlite3_column_text(stmt, 0)); break; } } sqlite3_finalize(stmt); return name; }
void SqliteTableModel::fetchData(unsigned int from, unsigned to) { int currentsize = m_data.size(); QString sLimitQuery; if(m_sQuery.startsWith("PRAGMA", Qt::CaseInsensitive) || m_sQuery.startsWith("EXPLAIN", Qt::CaseInsensitive)) { sLimitQuery = m_sQuery; } else { // Remove trailing trailing semicolon QString queryTemp = rtrimChar(m_sQuery, ';'); // If the query ends with a LIMIT statement take it as it is, if not append our own LIMIT part for lazy population if(queryTemp.contains(QRegExp("LIMIT\\s+\\d+\\s*(,\\s*\\d+\\s*)?$", Qt::CaseInsensitive))) sLimitQuery = queryTemp; else sLimitQuery = QString("%1 LIMIT %2, %3;").arg(queryTemp).arg(from).arg(to-from); } m_db->logSQL(sLimitQuery, kLogMsg_App); QByteArray utf8Query = sLimitQuery.toUtf8(); sqlite3_stmt *stmt; int status = sqlite3_prepare_v2(m_db->_db, utf8Query, utf8Query.size(), &stmt, NULL); if(SQLITE_OK == status) { while(sqlite3_step(stmt) == SQLITE_ROW) { QByteArrayList rowdata; for (int i = 0; i < m_headers.size(); ++i) rowdata.append(QByteArray(static_cast<const char*>(sqlite3_column_blob(stmt, i)), sqlite3_column_bytes(stmt, i))); m_data.push_back(rowdata); } } sqlite3_finalize(stmt); beginInsertRows(QModelIndex(), currentsize, m_data.size()-1); endInsertRows(); }