public void stepCallback(Sqlite3.sqlite3_context ctx, int argc, sqlite3_value[] param) { if (instance == null) { try { instance = PythonCalls.Call(context, aggregate_class); } catch (Exception) { Sqlite3.sqlite3_result_error(ctx, "user-defined aggregate's '__init__' method raised error", -1); return; } } try { object step = context.LanguageContext.Operations.GetMember(instance, "step"); object[] args = buildPyParams(context, ctx, argc, param); PythonCalls.CallWithKeywordArgs(context, step, args, new Dictionary <object, object>()); } catch (Exception e) { if (e is MissingMemberException) { throw; } Sqlite3.sqlite3_result_error(ctx, "user-defined aggregate's 'step' method raised error", -1); } }
private static void setResult(Sqlite3.sqlite3_context ctx, object result) { if (result == null) { Sqlite3.sqlite3_result_null(ctx); } else if (result is bool) { Sqlite3.sqlite3_result_int64(ctx, ((bool)result) ? 1 : 0); } else if (result is int) { Sqlite3.sqlite3_result_int64(ctx, (int)result); } else if (result is long) { Sqlite3.sqlite3_result_int64(ctx, (long)result); } else if (result is System.Numerics.BigInteger) { Sqlite3.sqlite3_result_int64(ctx, (long)((System.Numerics.BigInteger)result)); } else if (result is float) { Sqlite3.sqlite3_result_double(ctx, (float)result); } else if (result is double) { Sqlite3.sqlite3_result_double(ctx, (double)result); } else if (result is string) { Sqlite3.sqlite3_result_text(ctx, (string)result, -1, Sqlite3.SQLITE_TRANSIENT); } else if (result is byte[]) { byte[] b = (byte[])result; string s = Latin1.GetString(b, 0, b.Length); Sqlite3.sqlite3_result_blob(ctx, s, s.Length, Sqlite3.SQLITE_TRANSIENT); } else if (result is PythonBuffer) { PythonBuffer buffer = (PythonBuffer)result; string s = buffer.__getslice__(0, null).ToString(); Sqlite3.sqlite3_result_blob(ctx, s, s.Length, Sqlite3.SQLITE_TRANSIENT); } else { // TODO raise error } }
public static void SyncBlob_DeleteSchemaCallback(Sqlite3.sqlite3_context dbContext, int nArgs, Sqlite3.Mem[] Args) { String value = Sqlite3.sqlite3_value_text(Args[0]); if (value == null) { return; } String strFilePath = RHODESAPP().resolveDBFilesPath(value); if (strFilePath != "") { CRhoFile.deleteFile(strFilePath); } }
public void finalCallback(Sqlite3.sqlite3_context ctx) { if (instance == null) { return; } try { object function_result = context.LanguageContext.Operations.InvokeMember(instance, "finalize"); setResult(ctx, function_result); } catch (Exception) { Sqlite3.sqlite3_result_error(ctx, "user-defined aggregate's 'finalize' method raised error", -1); } }
private static void callUserFunction(Sqlite3.sqlite3_context ctx, int argc, sqlite3_value[] argv) { object[] data = (object[])Sqlite3.sqlite3_user_data(ctx); CodeContext context = (CodeContext)data[0]; object func = data[1]; object[] args = buildPyParams(context, ctx, argc, argv); try { object result = PythonCalls.CallWithKeywordArgs(context, func, args, emptyKwargs); setResult(ctx, result); } catch (Exception) { Sqlite3.sqlite3_result_error(ctx, "user-defined function raised exception", -1); } }
public static void SyncBlob_UpdateCallback(Sqlite3.sqlite3_context dbContext, int nArgs, Sqlite3.Mem[] Args) { if (nArgs < 3) { return; } DBAttrManager attrMgr = getDBByHandle(Sqlite3.sqlite3_context_db_handle(dbContext)).getAttrMgr(); String szAttrName = Sqlite3.sqlite3_value_text(Args[2]); int nSrcID = Sqlite3.sqlite3_value_int(Args[1]); if (attrMgr.isBlobAttr(nSrcID, szAttrName)) { String strFilePath = RHODESAPP().resolveDBFilesPath(Sqlite3.sqlite3_value_text(Args[0])); CRhoFile.deleteFile(strFilePath); } }
public static void SyncBlob_UpdateSchemaCallback(Sqlite3.sqlite3_context dbContext, int nArgs, Sqlite3.Mem[] Args) { String szOldValue = Sqlite3.sqlite3_value_text(Args[0]); String szNewValue = Sqlite3.sqlite3_value_text(Args[1]); if (szOldValue == szNewValue || szOldValue == null) { return; } if (szOldValue != null && szNewValue != null && szOldValue == szNewValue) { return; } if (szOldValue != null) { String strFilePath = RHODESAPP().resolveDBFilesPath(szOldValue); CRhoFile.deleteFile(strFilePath); } }
private static object[] buildPyParams(CodeContext context, Sqlite3.sqlite3_context ctx, int argc, sqlite3_value[] argv) { object[] args = new object[argc]; for (int i = 0; i < argc; ++i) { sqlite3_value cur_value = argv[i]; object cur_py_value = null; switch (Sqlite3.sqlite3_value_type(cur_value)) { case Sqlite3.SQLITE_INTEGER: cur_py_value = (int)Sqlite3.sqlite3_value_int64(cur_value); break; case Sqlite3.SQLITE_FLOAT: cur_py_value = Sqlite3.sqlite3_value_double(cur_value); break; case Sqlite3.SQLITE_TEXT: cur_py_value = Sqlite3.sqlite3_value_text(cur_value); break; case Sqlite3.SQLITE_BLOB: byte[] result = Sqlite3.sqlite3_value_blob(cur_value); PythonBuffer buffer = new PythonBuffer(context, result); cur_py_value = buffer; break; case Sqlite3.SQLITE_NULL: default: cur_py_value = null; break; } args[i] = cur_py_value; } return(args); }
private static object[] buildPyParams(CodeContext context, Sqlite3.sqlite3_context ctx, int argc, sqlite3_value[] argv) { object[] args = new object[argc]; for (int i = 0; i < argc; ++i) { sqlite3_value cur_value = argv[i]; object cur_py_value = null; switch (Sqlite3.sqlite3_value_type(cur_value)) { case Sqlite3.SQLITE_INTEGER: cur_py_value = (int)Sqlite3.sqlite3_value_int64(cur_value); break; case Sqlite3.SQLITE_FLOAT: cur_py_value = Sqlite3.sqlite3_value_double(cur_value); break; case Sqlite3.SQLITE_TEXT: cur_py_value = Sqlite3.sqlite3_value_text(cur_value); break; case Sqlite3.SQLITE_BLOB: cur_py_value = new Bytes(Sqlite3.sqlite3_value_blob(cur_value)); // TODO: avoid creating a copy break; case Sqlite3.SQLITE_NULL: default: cur_py_value = null; break; } args[i] = cur_py_value; } return(args); }