static int l_sqlite3_column_text_or_blob(lua_State * L, column_text_blob_t column_text_blob) { sqlite3_stmt * stmt = checkstmt_stmt(L, 1); int column = checkint(L, 2); lua_pushlstring(L, column_text_blob(stmt, column), sqlite3_column_bytes(stmt, column)); return 1; }
static int l_sqlite3_column_info(lua_State * L, const char * (*info_func)(sqlite3_stmt*,int) ) { const char * info = info_func(checkstmt_stmt(L, 1), checkint(L, 2)); if (info) lua_pushstring(L, info); else lua_pushstring(L, ""); return 1; }
/* * 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; }