bool SQLiteStatementImpl::hasNext() { if (_stepCalled) return (_nextResponse == SQLITE_ROW); // _pStmt is allowed to be null for conditional SQL statements if (_pStmt == 0) { _stepCalled = true; _nextResponse = SQLITE_DONE; return false; } _stepCalled = true; _nextResponse = sqlite3_step(_pStmt); if (_affectedRowCount == POCO_SQLITE_INV_ROW_CNT) _affectedRowCount = 0; if (!sqlite3_stmt_readonly(_pStmt)) _affectedRowCount += sqlite3_changes(_pDB); if (_nextResponse != SQLITE_ROW && _nextResponse != SQLITE_OK && _nextResponse != SQLITE_DONE) Utility::throwException(_pDB, _nextResponse); _pExtractor->reset();//clear the cached null indicators return (_nextResponse == SQLITE_ROW); }
SWIGEXPORT jint JNICALL Java_com_almworks_sqlite4java__1SQLiteSwiggedJNI_sqlite3_1stmt_1readonly(JNIEnv *jenv, jclass jcls, jlong jarg1) { jint jresult = 0 ; sqlite3_stmt *arg1 = (sqlite3_stmt *) 0 ; int result; (void)jenv; (void)jcls; arg1 = *(sqlite3_stmt **)&jarg1; result = (int)sqlite3_stmt_readonly(arg1); jresult = (jint)result; return jresult; }
jboolean JNICALL Java_com_baidu_javalite_PrepareStmt_sqlite3_1stmt_1readonly( JNIEnv *env, jclass cls, jlong handle) { if (handle == 0) { throwSqliteException(env, "handle is NULL"); return 0; } sqlite3_stmt* stmt = (sqlite3_stmt*) handle; return sqlite3_stmt_readonly(stmt) != 0; }
static int pdo_sqlite_stmt_get_attribute(pdo_stmt_t *stmt, zend_long attr, zval *val) { pdo_sqlite_stmt *S = (pdo_sqlite_stmt*)stmt->driver_data; switch (attr) { case PDO_SQLITE_ATTR_READONLY_STATEMENT: ZVAL_FALSE(val); #if SQLITE_VERSION_NUMBER >= 3007004 if (sqlite3_stmt_readonly(S->stmt)) { ZVAL_TRUE(val); } #endif break; default: return 0; } return 1; }
int SQLiteStatementImpl::affectedRowCount() const { if (_affectedRowCount != POCO_SQLITE_INV_ROW_CNT) return _affectedRowCount; return _pStmt == 0 || sqlite3_stmt_readonly(_pStmt) ? 0 : sqlite3_changes(_pDB); }
static jboolean nativeIsReadOnly(JNIEnv* env, jclass clazz, jlong connectionPtr, jlong statementPtr) { sqlite3_stmt* statement = reinterpret_cast<sqlite3_stmt*>(statementPtr); return sqlite3_stmt_readonly(statement) != 0; }
bool Database::Query::isReadOnly() { return _stmt ? sqlite3_stmt_readonly(_stmt) != 0 : true; }
array_header *proxy_db_exec_prepared_stmt(pool *p, const char *stmt, const char **errstr) { sqlite3_stmt *pstmt; int readonly = FALSE, res; array_header *results = NULL; if (p == NULL || stmt == NULL) { errno = EINVAL; return NULL; } if (prepared_stmts == NULL) { errno = ENOENT; return NULL; } pstmt = pr_table_get(prepared_stmts, stmt, NULL); if (pstmt == NULL) { pr_trace_msg(trace_channel, 19, "unable to find prepared statement for '%s'", stmt); errno = ENOENT; return NULL; } readonly = sqlite3_stmt_readonly(pstmt); if (!readonly) { /* Assume this is an INSERT/UPDATE/DELETE. */ res = sqlite3_step(pstmt); if (res != SQLITE_DONE) { const char *errmsg; errmsg = sqlite3_errmsg(proxy_dbh); if (errstr) { *errstr = pstrdup(p, errmsg); } pr_trace_msg(trace_channel, 2, "error executing '%s': %s", stmt, errmsg); errno = EPERM; return NULL; } /* Indicate success for non-readonly statements by returning an empty * result set. */ pr_trace_msg(trace_channel, 13, "successfully executed '%s'", stmt); results = make_array(p, 0, sizeof(char *)); return results; } results = make_array(p, 0, sizeof(char *)); res = sqlite3_step(pstmt); while (res == SQLITE_ROW) { register unsigned int i; int ncols; ncols = sqlite3_column_count(pstmt); pr_trace_msg(trace_channel, 12, "executing prepared statement '%s' returned row (columns: %d)", stmt, ncols); for (i = 0; i < ncols; i++) { char *val = NULL; pr_signals_handle(); /* By using sqlite3_column_text, SQLite will coerce the column value * into a string. */ val = pstrdup(p, (const char *) sqlite3_column_text(pstmt, i)); pr_trace_msg(trace_channel, 17, "column %s [%u]: %s", sqlite3_column_name(pstmt, i), i, val); *((char **) push_array(results)) = val; } res = sqlite3_step(pstmt); } if (res != SQLITE_DONE) { const char *errmsg; errmsg = sqlite3_errmsg(proxy_dbh); if (errstr != NULL) { *errstr = pstrdup(p, errmsg); } (void) pr_log_writefile(proxy_logfd, MOD_PROXY_VERSION, "executing prepared statement '%s' did not complete successfully: %s", stmt, errmsg); errno = EPERM; return NULL; } pr_trace_msg(trace_channel, 13, "successfully executed '%s'", stmt); return results; }
DLL_FUNCTION(int32_t) BU_SQLite_Statement_ReadOnly(sqlite3_stmt* pStmt) { #pragma comment(linker, "/EXPORT:BU_SQLite_Statement_ReadOnly=_BU_SQLite_Statement_ReadOnly@4") return sqlite3_stmt_readonly(pStmt); }
/* ** Implementation of the sha3_query(SQL,SIZE) function. ** ** This function compiles and runs the SQL statement(s) given in the ** argument. The results are hashed using a SIZE-bit SHA3. The default ** size is 256. ** ** The format of the byte stream that is hashed is summarized as follows: ** ** S<n>:<sql> ** R ** N ** I<int> ** F<ieee-float> ** B<size>:<bytes> ** T<size>:<text> ** ** <sql> is the original SQL text for each statement run and <n> is ** the size of that text. The SQL text is UTF-8. A single R character ** occurs before the start of each row. N means a NULL value. ** I mean an 8-byte little-endian integer <int>. F is a floating point ** number with an 8-byte little-endian IEEE floating point value <ieee-float>. ** B means blobs of <size> bytes. T means text rendered as <size> ** bytes of UTF-8. The <n> and <size> values are expressed as an ASCII ** text integers. ** ** For each SQL statement in the X input, there is one S segment. Each ** S segment is followed by zero or more R segments, one for each row in the ** result set. After each R, there are one or more N, I, F, B, or T segments, ** one for each column in the result set. Segments are concatentated directly ** with no delimiters of any kind. */ static void sha3QueryFunc( sqlite3_context *context, int argc, sqlite3_value **argv ){ sqlite3 *db = sqlite3_context_db_handle(context); const char *zSql = (const char*)sqlite3_value_text(argv[0]); sqlite3_stmt *pStmt = 0; int nCol; /* Number of columns in the result set */ int i; /* Loop counter */ int rc; int n; const char *z; SHA3Context cx; int iSize; if( argc==1 ){ iSize = 256; }else{ iSize = sqlite3_value_int(argv[1]); if( iSize!=224 && iSize!=256 && iSize!=384 && iSize!=512 ){ sqlite3_result_error(context, "SHA3 size should be one of: 224 256 " "384 512", -1); return; } } if( zSql==0 ) return; SHA3Init(&cx, iSize); while( zSql[0] ){ rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zSql); if( rc ){ char *zMsg = sqlite3_mprintf("error SQL statement [%s]: %s", zSql, sqlite3_errmsg(db)); sqlite3_finalize(pStmt); sqlite3_result_error(context, zMsg, -1); sqlite3_free(zMsg); return; } if( !sqlite3_stmt_readonly(pStmt) ){ char *zMsg = sqlite3_mprintf("non-query: [%s]", sqlite3_sql(pStmt)); sqlite3_finalize(pStmt); sqlite3_result_error(context, zMsg, -1); sqlite3_free(zMsg); return; } nCol = sqlite3_column_count(pStmt); z = sqlite3_sql(pStmt); n = (int)strlen(z); hash_step_vformat(&cx,"S%d:",n); SHA3Update(&cx,(unsigned char*)z,n); /* Compute a hash over the result of the query */ while( SQLITE_ROW==sqlite3_step(pStmt) ){ SHA3Update(&cx,(const unsigned char*)"R",1); for(i=0; i<nCol; i++){ switch( sqlite3_column_type(pStmt,i) ){ case SQLITE_NULL: { SHA3Update(&cx, (const unsigned char*)"N",1); break; } case SQLITE_INTEGER: { sqlite3_uint64 u; int j; unsigned char x[9]; sqlite3_int64 v = sqlite3_column_int64(pStmt,i); memcpy(&u, &v, 8); for(j=8; j>=1; j--){ x[j] = u & 0xff; u >>= 8; } x[0] = 'I'; SHA3Update(&cx, x, 9); break; } case SQLITE_FLOAT: { sqlite3_uint64 u; int j; unsigned char x[9]; double r = sqlite3_column_double(pStmt,i); memcpy(&u, &r, 8); for(j=8; j>=1; j--){ x[j] = u & 0xff; u >>= 8; } x[0] = 'F'; SHA3Update(&cx,x,9); break; } case SQLITE_TEXT: { int n2 = sqlite3_column_bytes(pStmt, i); const unsigned char *z2 = sqlite3_column_text(pStmt, i); hash_step_vformat(&cx,"T%d:",n2); SHA3Update(&cx, z2, n2); break; } case SQLITE_BLOB: { int n2 = sqlite3_column_bytes(pStmt, i); const unsigned char *z2 = sqlite3_column_blob(pStmt, i); hash_step_vformat(&cx,"B%d:",n2); SHA3Update(&cx, z2, n2); break; } } } } sqlite3_finalize(pStmt); } sqlite3_result_blob(context, SHA3Final(&cx), iSize/8, SQLITE_TRANSIENT); }