int CppSQLite3Query::fieldIndex(const char* szField) { checkVM(); if (szField) { for (int nField = 0; nField < mnCols; nField++) { const char* szTemp = sqlite3_column_name(mpVM, nField); if (strcmp(szField, szTemp) == 0) { return nField; } } } throw CppSQLite3Exception(CPPSQLITE_ERROR, "Invalid field name requested", DONT_DELETE_MSG); }
static int column_tolua(lua_State *L) { SQLiteLuaStmt *ptr = (SQLiteLuaStmt *)checkudata(L, 1, &stmtmetakey, "sqlite.stmt"); if (ptr->stmt == NULL) { lua_pushnil(L); lua_pushliteral(L, "closed database"); return 2; } int col = sqlite3_column_count(ptr->stmt); lua_createtable(L, col, 0); for (int i = 0; i < col; ++i) { lua_pushstring(L, sqlite3_column_name(ptr->stmt, i)); lua_rawseti(L, -2, i + 1); } return 1; }
/* ** This procedure runs in the thread to step the virtual machine. */ static void do_step(Thread *p){ int i; if( p->pStmt==0 ){ p->zErr = p->zStaticErr = "no virtual machine available"; p->rc = SQLITE_ERROR; return; } p->rc = sqlite3_client_step(p->pStmt); if( p->rc==SQLITE_ROW ){ p->argc = sqlite3_column_count(p->pStmt); for(i=0; i<sqlite3_data_count(p->pStmt); i++){ p->argv[i] = (char*)sqlite3_column_text(p->pStmt, i); } for(i=0; i<p->argc; i++){ p->colv[i] = sqlite3_column_name(p->pStmt, i); } } }
int CSQLite3Query::fieldIndex(const char* pszField) { checkVM(); if (pszField) { for (int iField = 0; iField < m_iCols; iField++) { const char* pszTemp = sqlite3_column_name(m_pVM, iField); if (0 == strcmp(pszField, pszTemp)) { return iField; } } } Q_EXCEPTION(Q_ERROR_DATABASE, "invalid field name requested, %s", pszField); }
static int fetch(lua_State* L, int mode) { stmt* s = (stmt*)luaL_checkudata(L, 1, MT_STMT); sqlite3* db = sqlite3_db_handle(s->handle); int ret; while((ret = sqlite3_step(s->handle)) == SQLITE_SCHEMA) {} if(ret == SQLITE_DONE) { lua_pushnil(L); return 1; } else if(ret == SQLITE_ROW) { int i; int col_count = sqlite3_column_count(s->handle); lua_createtable(L, col_count, 0); for(i = 0; i < col_count; i++) { if(mode == 0) { /* fetch, rows */ lua_pushstring(L, sqlite3_column_name(s->handle, i)); } else if(mode == 1) { /* ifetch, irows */ lua_pushinteger(L, i + 1); } switch(sqlite3_column_type(s->handle, i)) { case SQLITE_INTEGER: lua_pushinteger(L, sqlite3_column_int(s->handle, i)); break; case SQLITE_FLOAT: lua_pushnumber(L, sqlite3_column_double(s->handle, i)); break; case SQLITE_TEXT: lua_pushstring(L, (const char*)sqlite3_column_text(s->handle, i)); break; case SQLITE_BLOB: case SQLITE_NULL: lua_pushnil(L); break; } lua_settable(L, -3); } return 1; } return luaL_error(L, "[%d] %s", ret, sqlite3_errmsg(db)); }
/* * mode: 0 = direct, 1 = integer, 2 = alphanumeric */ static int l_sqlite3_row_mode(lua_State * L, int mode) { /* Old code / Just a reminder / To be removed: ** checkargs(L, 1, 2, CHECK_PTR, CHECK_NILTABLE, 0); */ sqlite3_stmt * stmt = checkstmt_stmt(L, 1); int num_columns = sqlite3_data_count(stmt); /* Maybe wrong state, so don't use sqlite3_column_count */ int index; /* XXX Should really be cleaned up... Fixme! */ if (mode == 0) lua_checkstack(L, num_columns); else if (!lua_istable(L, -1)) lua_newtable(L); for (index=0; index<num_columns; index++) switch(mode) { case 0: /* direct mode */ push_column(L, stmt, index); break; case 1: /* integer mode */ push_column(L, stmt, index); lua_rawseti(L, -2, index+1); break; case 2: /* alphanumeric mode */ lua_pushstring(L, sqlite3_column_name(stmt, index)); push_column(L, stmt, index); lua_rawset(L, -3); break; default: report_error(L, "libluasqlite3: Internal error in sqlite3_row_mode"); } if (mode) return 1; else return num_columns; }
int chirp_sqlite3_row_jsonify(sqlite3_stmt *stmt, buffer_t *B) { int rc; int i, first; CATCHUNIX(buffer_putliteral(B, "{")); for (i = 0, first = 1; i < sqlite3_column_count(stmt); i++, first = 0) { if (!first) CATCHUNIX(buffer_putliteral(B, ",")); CATCHUNIX(buffer_putfstring(B, "\"%s\":", sqlite3_column_name(stmt, i))); chirp_sqlite3_column_jsonify(stmt, i, B); } CATCHUNIX(buffer_putliteral(B, "}")); rc = 0; goto out; out: return rc; }
int fetch_results(sqlite3_stmt *stmt, mxArray **results) { struct structlist result_list; structlist_init(&result_list); int i, num_columns = sqlite3_column_count(stmt); mxArray *row = mxCreateStructMatrix(1, 1, 0, NULL); for (i = 0; i < num_columns; i++) { const char *name = sqlite3_column_name(stmt, i); mxAddField(row, name); } int res; while (res = fetch_row(stmt, num_columns, &row), res == SQLITE_ROW) { structlist_add(&result_list, row); } *results = structlist_collapse(&result_list); return res; }
void Session::_MapResultColumnsToObject(ObjectBase *oPtr, sqlite3_stmt *statement) { int cols = sqlite3_column_count(statement); TCHAR *column_name; CString *pCString; for(int x = 0; x < cols; ++x) { #ifdef UNICODE column_name = (TCHAR*)sqlite3_column_name16(statement, x); #else column_name = sqlite3_column_name(statement, x); #endif if(!oPtr->GetMap().count(column_name)) { return; } VarInfo p(oPtr->GetMap().find(column_name)->second); switch(p.type) { case VarInfo::STRING: pCString = reinterpret_cast<CString*>(p.dataPtr); #ifdef UNICODE pCString->Format(_T("%s"),(TCHAR*)sqlite3_column_text16(statement, x)); #else pCString->Format(_T("%s"),(TCHAR*)sqlite3_column_text(statement, x)); #endif break; case VarInfo::INT: *((int*)p.dataPtr) = sqlite3_column_int(statement, x); break; case VarInfo::INT64: *((__int64*)p.dataPtr) = sqlite3_column_int64(statement, x); break; case VarInfo::DOUBLE: *((double*)p.dataPtr) = sqlite3_column_double(statement, x); break; } } oPtr->m_is_null = false; }
static int es_sqlite_step(duk_context *ctx) { es_sqlite_t *es = es_resource_get(ctx, 0, &es_resource_sqlite); if(es->es_stmt == NULL) { duk_push_null(ctx); return 1; } const int cols = sqlite3_data_count(es->es_stmt); duk_push_object(ctx); for(int i = 0; i < cols; i++) { int64_t i64; switch(sqlite3_column_type(es->es_stmt, i)) { case SQLITE_INTEGER: i64 = sqlite3_column_int64(es->es_stmt, i); if(i64 >= INT32_MIN && i64 <= INT32_MAX) duk_push_int(ctx, i64); else if(i64 >= 0 && i64 <= UINT32_MAX) duk_push_uint(ctx, i64); else duk_push_number(ctx, i64); break; case SQLITE_TEXT: duk_push_string(ctx, (const char *)sqlite3_column_text(es->es_stmt, i)); break; case SQLITE_FLOAT: duk_push_number(ctx, sqlite3_column_double(es->es_stmt, i)); break; default: continue; } duk_put_prop_string(ctx, -2, sqlite3_column_name(es->es_stmt, i)); } es_sqlite_stmt_step(ctx, es); return 1; }
bool SqlFile::GetNextBed(BED &bed, bool forceSorted) { int rc = sqlite3_step(_stmt); int ncol; std::string sql_exec; _status = BED_INVALID; switch( rc ) { case SQLITE_DONE: I_chrom++; if (I_chrom == _chrom_table.end()) { _status = BED_BLANK; return false; } prepareNextChrom(I_chrom->first); return GetNextBed(bed, forceSorted); break; case SQLITE_ROW: bed.chrom = _prev_chrom; bed.start = (CHRPOS)sqlite3_column_int(_stmt, 0); bed.end = (CHRPOS)sqlite3_column_int(_stmt, 1); bed.fields.clear(); ncol = 2; while (1) { const char *_name = sqlite3_column_name(_stmt, ncol); if (_name == NULL) break; if (std::string("name").compare(_name) == 0) bed.name = std::string((char*)sqlite3_column_text(_stmt, ncol)); else if (std::string("score").compare(_name) == 0) bed.score = std::string((char*)sqlite3_column_text(_stmt, ncol)); else if (std::string("strand").compare(_name) == 0) bed.strand = std::string(sqlite3_column_int(_stmt, ncol)>0 ? "+" : "-"); else bed.fields.push_back(std::string((char*)sqlite3_column_text(_stmt, ncol))); ncol++; } _prev_start = bed.start; _status = BED_VALID; return true; default: std::cerr << "Error: " << rc << ": " << sqlite3_errmsg(_db) << "\n"; break; } return false; }
static int column_types(lua_State* L, int mode) { stmt* s = (stmt*)luaL_checkudata(L, 1, MT_STMT); int col_count = sqlite3_column_count(s->handle); int i; lua_createtable(L, col_count, 0); for(i=0;i<col_count;i++) { if(mode == 0) { /* column_types */ lua_pushstring(L, sqlite3_column_name(s->handle, i)); } else { /* icolumn_types */ lua_pushinteger(L, i + 1); } lua_pushinteger(L, sqlite3_column_type(s->handle, i)); lua_settable(L, -3); } return 1; }
RowPtr SQLiteCursorBackend::fetch_row() { if (SQLITE_DONE == last_code_ || SQLITE_OK == last_code_) return RowPtr(); if (SQLITE_ROW != last_code_) throw DBError(WIDEN(sqlite3_errmsg(conn_))); int col_count = sqlite3_column_count(stmt_); RowPtr row(new Row(col_count)); for (int i = 0; i < col_count; ++i) { String name = str_to_upper(WIDEN(sqlite3_column_name(stmt_, i))); int type = sqlite3_column_type(stmt_, i); (*row)[i].first = name; if (SQLITE_NULL != type) (*row)[i].second = Value( WIDEN((const char *)sqlite3_column_text(stmt_, i))); } last_code_ = sqlite3_step(stmt_); return row; }
int CppSQLite3Query::fieldIndex(const CString& szField) { checkVM(); if (szField) { for (int nField = 0; nField < mnCols; nField++) { const char* szTemp = sqlite3_column_name(mpVM, nField); if (szField.CompareNoCase(szTemp) == 0) { return nField; } } } throw CppSQLite3Exception(CPPSQLITE_ERROR, "Invalid field name requested"); }
/* static int create_cursor(lua_State *L, int conn, sqlite3_stmt *sql_vm, int numcols, const char **row, const char **col_info)*/ static int create_cursor(lua_State *L, int o, conn_data *conn, sqlite3_stmt *sql_vm, int numcols) { int i; cur_data *cur = (cur_data*)lua_newuserdata(L, sizeof(cur_data)); luasql_setmeta (L, LUASQL_CURSOR_SQLITE); /* increment cursor count for the connection creating this cursor */ conn->cur_counter++; /* fill in structure */ cur->closed = 0; cur->conn = LUA_NOREF; cur->numcols = numcols; cur->colnames = LUA_NOREF; cur->coltypes = LUA_NOREF; cur->sql_vm = sql_vm; cur->conn_data = conn; lua_pushvalue(L, o); cur->conn = luaL_ref(L, LUA_REGISTRYINDEX); /* create table with column names */ lua_newtable(L); for (i = 0; i < numcols;) { lua_pushstring(L, sqlite3_column_name(sql_vm, i)); lua_rawseti(L, -2, ++i); } cur->colnames = luaL_ref(L, LUA_REGISTRYINDEX); /* create table with column types */ lua_newtable(L); for (i = 0; i < numcols;) { lua_pushstring(L, sqlite3_column_decltype(sql_vm, i)); lua_rawseti(L, -2, ++i); } cur->coltypes = luaL_ref(L, LUA_REGISTRYINDEX); return 1; }
size_t mLibraryGetEntries(struct mLibrary* library, struct mLibraryListing* out, size_t numEntries, size_t offset, const struct mLibraryEntry* constraints) { mLibraryListingClear(out); // TODO: Free memory sqlite3_clear_bindings(library->select); sqlite3_reset(library->select); _bindConstraints(library->select, constraints); int countIndex = sqlite3_bind_parameter_index(library->select, ":count"); int offsetIndex = sqlite3_bind_parameter_index(library->select, ":offset"); sqlite3_bind_int64(library->select, countIndex, numEntries ? numEntries : -1); sqlite3_bind_int64(library->select, offsetIndex, offset); size_t entryIndex; for (entryIndex = 0; (!numEntries || entryIndex < numEntries) && sqlite3_step(library->select) == SQLITE_ROW; ++entryIndex) { struct mLibraryEntry* entry = mLibraryListingAppend(out); memset(entry, 0, sizeof(*entry)); int nCols = sqlite3_column_count(library->select); int i; for (i = 0; i < nCols; ++i) { const char* colName = sqlite3_column_name(library->select, i); if (strcmp(colName, "crc32") == 0) { entry->crc32 = sqlite3_column_int(library->select, i); struct NoIntroGame game; if (NoIntroDBLookupGameByCRC(library->gameDB, entry->crc32, &game)) { entry->title = strdup(game.name); } } else if (strcmp(colName, "platform") == 0) { entry->platform = sqlite3_column_int(library->select, i); } else if (strcmp(colName, "size") == 0) { entry->filesize = sqlite3_column_int64(library->select, i); } else if (strcmp(colName, "internalCode") == 0 && sqlite3_column_type(library->select, i) == SQLITE_TEXT) { strncpy(entry->internalCode, (const char*) sqlite3_column_text(library->select, i), sizeof(entry->internalCode) - 1); } else if (strcmp(colName, "internalTitle") == 0 && sqlite3_column_type(library->select, i) == SQLITE_TEXT) { strncpy(entry->internalTitle, (const char*) sqlite3_column_text(library->select, i), sizeof(entry->internalTitle) - 1); } else if (strcmp(colName, "filename") == 0) { entry->filename = strdup((const char*) sqlite3_column_text(library->select, i)); } else if (strcmp(colName, "base") == 0) { entry->base = strdup((const char*) sqlite3_column_text(library->select, i)); } } } return mLibraryListingSize(out); }
int CppSQLite3Query::fieldIndex(const char* szField) { checkVM(); if (szField) { for (int nField = 0; nField < mnCols; nField++) { const char* szTemp = sqlite3_column_name(mpVM, nField); if (strcmp(szField, szTemp) == 0) { return nField; } } } IwError(("Invalid field name requested")); return 0; }
// Return the index of the specified (potentially aliased) column name int Statement::getColumnIndex(const char* apName) const { // Build the map of column index by name on first call if (mColumnNames.empty()) { for (int i = 0; i < mColumnCount; ++i) { const char* pName = sqlite3_column_name(mStmtPtr, i); mColumnNames[pName] = i; } } const TColumnNames::const_iterator iIndex = mColumnNames.find(apName); if (iIndex == mColumnNames.end()) { throw SQLite::Exception("Unknown column name."); } return (*iIndex).second; }
void FTNCALL sqlite3_column_name_type_c_( sqlite3_stmt **stmt, int *colidx, char *name, int len_name, char *type, int len_type ) { int rc ; char *pstr ; pstr = sqlite3_column_name(*stmt, *colidx ) ; strncpy( name, pstr, len_name ) ; name[len_name-1] = '\0' ; pstr = sqlite3_column_decltype(*stmt, *colidx ) ; strncpy( type, pstr, len_type ) ; type[len_type-1] = '\0' ; return ; }
RowSet *SQLiteSelect(const char* str) { size_t i, row; int ret; char *buf = g_strdup_printf("Select %s;", str); RowSet *rs = NULL; sqlite3_stmt *pStmt; ret = sqlite3_prepare(connection, buf, -1, &pStmt, NULL); g_free(buf); if (ret == SQLITE_OK) { size_t numCols = (size_t)sqlite3_column_count(pStmt); size_t numRows = 0; while((ret = sqlite3_step(pStmt)) == SQLITE_ROW) numRows++; if (sqlite3_reset(pStmt) != SQLITE_OK) outputerrf("SQL error: %s in sqlite3_reset()", sqlite3_errmsg(connection)); rs = MallocRowset(numRows + 1, numCols); /* first row is headings */ for (i = 0; i < numCols; i++) SetRowsetData(rs, 0, i, sqlite3_column_name(pStmt, (int)i)); row = 0; while((ret = sqlite3_step(pStmt)) == SQLITE_ROW) { row++; for (i = 0; i < numCols; i++) SetRowsetData(rs, row, i, (const char*)sqlite3_column_text(pStmt, (int)i)); } if (ret == SQLITE_DONE) ret = SQLITE_OK; } if (ret != SQLITE_OK) outputerrf("SQL error: %s\nfrom '%s'", sqlite3_errmsg(connection), str); if (sqlite3_finalize(pStmt) != SQLITE_OK) outputerrf("SQL error: %s in sqlite3_finalize()", sqlite3_errmsg(connection)); return rs; }
int storage_step(storage_stmt_t *stmt, hash_t **row) { int i, ret, ncols = sqlite3_column_count(stmt); void *data; ret = sqlite3_step(stmt); if (ret != SQLITE_ROW) { errno = EINVAL; return ret; } if (!row || ret == SQLITE_DONE) return ret; *row = hash_init(); for (i = 0; i < ncols; i++) { switch (sqlite3_column_type(stmt, i)) { case SQLITE_INTEGER: data = xintdup(sqlite3_column_int(stmt, i)); break; case SQLITE_NULL: data = NULL; break; case SQLITE_BLOB: case SQLITE_TEXT: data = xstrdup((char *)sqlite3_column_text(stmt, i)); break; default: FAIL("błąd sqlite3: nierozpoznany typ danych. Prawdopodobnie jest to błąd wewnętrzny programu.\n"); exit(EXIT_FAILURE); } hash_set(*row, xstrdup(sqlite3_column_name(stmt, i)), data, TRUE); } return ret; }
wxString MPInfo::execQuery(const char* s) { wxString t_ret; int rc = sqlite3_prepare_v2(MPbase,s,-1,&ppStmtExec,NULL); rcExecQuery = sqlite3_step( ppStmtExec ); if( rcExecQuery == SQLITE_ROW ) { _hasNextLine = true; t_ret.Append(_T("<TR>")); for( int i = 0; i < sqlite3_column_count(ppStmtExec); i++ ) { t_ret.Append(_T("<TH>")); t_ret.Append(wxString::FromUTF8(sqlite3_column_name(ppStmtExec,i))); t_ret.Append(_T("</TH>")); } t_ret.Append(_T("</TR>")); } else { _hasNextLine = false; t_ret.Append( wxString::FromUTF8( sqlite3_errmsg(MPbase) ) ); } return t_ret; }
jstring JNICALL Java_com_baidu_javalite_PrepareStmt_sqlite3_1column_1name( JNIEnv *env, jclass cls, jlong handle, jint column) { if (handle == 0) { throwSqliteException(env, "handle is NULL"); return 0; } sqlite3_stmt* stmt = (sqlite3_stmt*) handle; const char* cn = sqlite3_column_name(stmt, column); if (cn == 0) { return (*env)->NewStringUTF(env, ""); } else { return (*env)->NewStringUTF(env, cn); } }
//根据字段名返回列索引 int CppSQLite3Query::FieldIndex(const char* szField) { CheckStmt(); if (szField) { for (int nField = 0; nField < mnCols; nField++) { //后面还有很多类似的函数,参数差不多,需要一个sqlite3_stmt*和列索引值,这应该是内部查询了之后返回的结果,而不是事先保存的 const char *szTemp = sqlite3_column_name(mpStmt, nField); if (strcmp(szTemp, szField) == 0) { return nField; } } } throw CppSQLite3Exception(CPPSQLITE_ERROR, "Invalid field name requested", DONT_DELETE_MSG); }
Vector *SqliteDb::executeQuery(const std::string &sql) { CCLOG("Sqlite: %s", sql.c_str()); auto valueArray = Vector::create(); sqlite3_stmt *pStmt = nullptr; bool res = sqlite3_prepare(_db, sql.c_str(), -1, &pStmt, nullptr) == SQLITE_OK; if (res) { while (sqlite3_step(pStmt) == SQLITE_ROW) { auto columnDict = Map::create(); int columnNum = sqlite3_column_count(pStmt); for (int i = 0; i < columnNum; ++i) { int type = sqlite3_column_type(pStmt, i); const char *szName = sqlite3_column_name(pStmt, i); Ref *pValue = nullptr; if (type == SQLITE_INTEGER) { pValue = RefInteger::create(sqlite3_column_int(pStmt, i)); } else if (type == SQLITE_FLOAT) { pValue = RefDouble::create(sqlite3_column_double(pStmt, i)); } else if (type == SQLITE_TEXT) { pValue = RefString::create((const char*)sqlite3_column_text(pStmt, i)); } columnDict->setObjectForKey(pValue, szName); } valueArray->addObject(columnDict); } sqlite3_finalize(pStmt); } return valueArray; }
recList_t SqliteDB::query(const QString &sql, bool queryHeader){ sqlite3_stmt *stmt; const char *tail; bool addHeaderflag = false; QStringList header; int ncol; int rc = 0; QStringList r; recList_t browseRecs; rc = sqlite3_prepare(m_db,(const char *)sql.toUtf8(),sql.length(), &stmt, &tail); if( SQLITE_OK == rc ){ while ( sqlite3_step(stmt) == SQLITE_ROW ){ r.clear(); ncol = sqlite3_data_count(stmt); for(int i=0; i<ncol; ++i){ if(!addHeaderflag && queryHeader){ const char *headerName = sqlite3_column_name(stmt, i); QString rv = QString::fromUtf8(headerName); header << rv; } char *strresult = 0; strresult = (char *)sqlite3_column_text(stmt, i); QString rv = QString::fromUtf8(strresult); r << rv; } if(!addHeaderflag && queryHeader){ browseRecs.append(header); addHeaderflag = true; } browseRecs.append(r); } sqlite3_finalize(stmt); } else { m_lastErrMsg = QString ("could not get fields"); } return browseRecs; }
sqlite3_stmt *Query::get_result(const std::string& sql) { // query, result m_last_query = sql; if (odb && res) { GetDatabase().error(*this, "get_result: query busy"); } if (odb && !res) { const char *s = NULL; int rc = sqlite3_prepare(odb -> db, sql.c_str(), sql.size(), &res, &s); if (rc != SQLITE_OK) { GetDatabase().error(*this, "get_result: prepare query failed"); return NULL; } if (!res) { GetDatabase().error(*this, "get_result: query failed"); return NULL; } // get column names from result { int i = 0; do { const char *p = sqlite3_column_name(res, i); if (!p) break; m_nmap[p] = ++i; } while (true); m_num_cols = i; } cache_rc = sqlite3_step(res); cache_rc_valid = true; m_row_count = (cache_rc == SQLITE_ROW) ? 1 : 0; } return res; }
static knh_dbcur_t *knh_dbquery__sqlite3(Ctx *ctx, knh_db_t *hdr, knh_bytes_t sql, ResultSet *rs) { if(rs == NULL) { int r = sqlite3_exec((sqlite3*)hdr, (const char*)sql.buf, NULL, NULL, NULL); if(r != SQLITE_OK) { knh_sqlite3_perror(ctx, (sqlite3*)hdr, r); } return NULL; } else { sqlite3_stmt *stmt = NULL; sqlite3_prepare((sqlite3*)hdr, (char*)sql.buf, sql.len, &stmt, NULL); // if (r != SQLITE_OK) { // sqlite3_finalize(stmt); // DBG2_P("msg='%s', sqlite3_errmsg((sqlite3)hdr)); // return NULL; // } // r = sqlite3_reset(stmt); // if(r != SQLITE_OK) { // sqlite3_finalize(stmt); // return NULL; // } size_t column_size = (size_t)sqlite3_column_count(stmt); //DBG2_P("column_size=%d", column_size); knh_ResultSet_initColumn(ctx, rs, column_size); if(column_size > 0) { size_t i; for(i = 0; i < DP(rs)->column_size; i++) { char *n = (char*)sqlite3_column_name(stmt, i); //DBG2_P("(%d) name = '%s'", i, n); if(n != NULL) { knh_ResultSet_setName(ctx, rs, i, new_String(ctx, B(n), NULL)); } } } return (knh_dbcur_t*)stmt; } }
// Return a copy of the column data specified by its column name starting at 0 // (use the Column copy-constructor) Column Statement::getColumn(const char* apName) { checkRow(); if (mColumnNames.empty()) { for (int i = 0; i < mColumnCount; ++i) { const char* pName = sqlite3_column_name(mStmtPtr, i); mColumnNames[pName] = i; } } const TColumnNames::const_iterator iIndex = mColumnNames.find(apName); if (iIndex == mColumnNames.end()) { throw SQLite::Exception("Unknown column name."); } // Share the Statement Object handle with the new Column created return Column(mStmtPtr, (*iIndex).second); }
const char *pomfit_db_fetch_one_col(char *column) { int i , rv = 0; const unsigned char *val = NULL; rv = sqlite3_step(PomfitDB_stmt); if(rv == SQLITE_ROW) { for( i = 0 ; i < SQLite.iCol ; i++ ) { if(strcmp(column, sqlite3_column_name(PomfitDB_stmt,i)) == 0) { val = sqlite3_column_text(PomfitDB_stmt,i); return (const char*)val; } } return NULL; } else if(rv == SQLITE_DONE) { sqlite3_finalize(PomfitDB_stmt); return NULL; } else return NULL; }