sqlite> .v
SQLite 3.22.0 2018-01-12 23:38:10
dec3ea4e4e6c4b1761ddc883a29eaa50dcd663ce6199667cc0ff82f7849d4f2a

sqlite> WITH blob_tab AS (SELECT blob()blob) SELECT subtype(blob) FROM
blob_tab;
subtype(blob)
1

sqlite> WITH blob_tab AS (SELECT blob()blob), other_tab(i) AS (values (1))
SELECT subtype(blob),i FROM blob_tab,other_tab;
subtype(blob),i
0,1

--expected output is 1,1.  Subtype is constant 1.  What happened to it?

Source of test extension subtype.c:
--------------------------------------------
#include "sqlite3ext.h"
SQLITE_EXTENSION_INIT1
static void free(void*pBLOB) {if (pBLOB) sqlite3_free(pBLOB);}

/*return a one byte test blob with constant subtype=1*/
static void blob(sqlite3_context *context, int argc, sqlite3_value **argv) {
  sqlite3_result_blob(context, sqlite3_malloc(1), 1, free);
  sqlite3_result_subtype(context, 1);
}

 /*return the subtype of arg0*/
static void subtype(sqlite3_context *context, int argc, sqlite3_value
**argv) {
  sqlite3_result_int(context,sqlite3_value_subtype(argv[0]));
}

int sqlite3_subtype_init(sqlite3 *db, char **pzErrMsg, const
sqlite3_api_routines *pApi) {
  SQLITE_EXTENSION_INIT2(pApi);
  int rc = sqlite3_create_function(db, "blob", 0, SQLITE_UTF8, 0, blob, 0,
0);
  if (SQLITE_OK == rc) rc = sqlite3_create_function(db, "subtype", 1,
SQLITE_UTF8, 0, subtype, 0, 0);
  return rc;
}
--------------------------------------------
Peter
_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to