Browse Source

Change parameter mask for sqlite3_context method "result_double".
Added a sample to show usage of SquiLu function as sqlite3 custom function.

mingodad 13 years ago
parent
commit
6f9cb49c82
2 changed files with 52 additions and 1 deletions
  1. 1 1
      SquiLu-ext/sq_sqlite3.cpp
  2. 51 0
      SquiLu/samples/test-sqlite3.nut

+ 1 - 1
SquiLu-ext/sq_sqlite3.cpp

@@ -1735,7 +1735,7 @@ static SQRegFunction sq_sqlite3_context_methods[] =
 	_DECL_FUNC(aggregate_data,  -1, _SC("x.")),
 	_DECL_FUNC(aggregate_count,  1, _SC("x")),
 	_DECL_FUNC(result_null,  1, _SC("x")),
-	_DECL_FUNC(result_double,  2, _SC("xf")),
+	_DECL_FUNC(result_double,  2, _SC("xn")),
 	_DECL_FUNC(result_int,  2, _SC("xi")),
 	_DECL_FUNC(result_text,  2, _SC("xs")),
 	_DECL_FUNC(result_blob,  2, _SC("xs")),

+ 51 - 0
SquiLu/samples/test-sqlite3.nut

@@ -0,0 +1,51 @@
+local db = SQLite3(":memory:");
+print(db);
+
+db.create_function("multiply3",3,function(ctx,a,b,c){ctx.result_double(a*b*c);});
+
+local sql = "select 1.2*2.5*3.6;";
+local sql_squilu = "select multiply3(1.2,2.5,3.6);";
+
+local stmt = db.prepare(sql);
+local stmt_squilu = db.prepare(sql_squilu);
+
+print(db.exec_get_one(sql_squilu));
+
+local count = 100000;
+
+local now = os.clock();
+for(local i=0; i<count; ++i){
+	local val = db.exec_get_one(sql_squilu);
+}
+print("SquiLu function took:", os.clock() -now);
+
+now = os.clock();
+for(local i=0; i<count; ++i){
+	local val = db.exec_get_one(sql);
+}
+print("SQL function took:", os.clock() -now);
+
+stmt_squilu.reset();
+stmt_squilu.step()
+print(stmt_squilu.col(0));
+
+now = os.clock();
+for(local i=0; i<count; ++i){
+	stmt_squilu.reset();
+	stmt_squilu.step()
+	local val = stmt_squilu.col(0);
+}
+print("SquiLu SQL prepared function took:", os.clock() -now);
+
+now = os.clock();
+for(local i=0; i<count; ++i){
+	stmt.reset();
+	stmt.step()
+	local val = stmt.col(0);
+}
+print("SQL prepared function took:", os.clock() -now);
+
+stmt.finalize();
+stmt_squilu.finalize();
+
+db.close();