MCPcopy Create free account
hub / github.com/2shady4u/godot-sqlite / sha3QueryFunc

Function sha3QueryFunc

src/sqlite/shell.c:2944–3007  ·  view source on GitHub ↗

** 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 : ** R ** N ** I ** F ** B :<bytes

Source from the content-addressed store, hash-verified

2942** with no delimiters of any kind.
2943*/
2944static void sha3QueryFunc(
2945 sqlite3_context *context,
2946 int argc,
2947 sqlite3_value **argv
2948){
2949 sqlite3 *db = sqlite3_context_db_handle(context);
2950 const char *zSql = (const char*)sqlite3_value_text(argv[0]);
2951 sqlite3_stmt *pStmt = 0;
2952 int nCol; /* Number of columns in the result set */
2953 int i; /* Loop counter */
2954 int rc;
2955 int n;
2956 const char *z;
2957 SHA3Context cx;
2958 int iSize;
2959
2960 if( argc==1 ){
2961 iSize = 256;
2962 }else{
2963 iSize = sqlite3_value_int(argv[1]);
2964 if( iSize!=224 && iSize!=256 && iSize!=384 && iSize!=512 ){
2965 sqlite3_result_error(context, "SHA3 size should be one of: 224 256 "
2966 "384 512", -1);
2967 return;
2968 }
2969 }
2970 if( zSql==0 ) return;
2971 SHA3Init(&cx, iSize);
2972 while( zSql[0] ){
2973 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zSql);
2974 if( rc ){
2975 char *zMsg = sqlite3_mprintf("error SQL statement [%s]: %s",
2976 zSql, sqlite3_errmsg(db));
2977 sqlite3_finalize(pStmt);
2978 sqlite3_result_error(context, zMsg, -1);
2979 sqlite3_free(zMsg);
2980 return;
2981 }
2982 if( !sqlite3_stmt_readonly(pStmt) ){
2983 char *zMsg = sqlite3_mprintf("non-query: [%s]", sqlite3_sql(pStmt));
2984 sqlite3_finalize(pStmt);
2985 sqlite3_result_error(context, zMsg, -1);
2986 sqlite3_free(zMsg);
2987 return;
2988 }
2989 nCol = sqlite3_column_count(pStmt);
2990 z = sqlite3_sql(pStmt);
2991 if( z ){
2992 n = (int)strlen(z);
2993 sha3_step_vformat(&cx,"S%d:",n);
2994 SHA3Update(&cx,(unsigned char*)z,n);
2995 }
2996
2997 /* Compute a hash over the result of the query */
2998 while( SQLITE_ROW==sqlite3_step(pStmt) ){
2999 SHA3Update(&cx,(const unsigned char*)"R",1);
3000 for(i=0; i<nCol; i++){
3001 sha3UpdateFromValue(&cx, sqlite3_column_value(pStmt,i));

Callers

nothing calls this directly

Calls 5

SHA3InitFunction · 0.85
sha3_step_vformatFunction · 0.85
SHA3UpdateFunction · 0.85
sha3UpdateFromValueFunction · 0.85
SHA3FinalFunction · 0.85

Tested by

no test coverage detected