/// <summary> /// Executes only read-only SQL. /// </summary> /// <returns>The query.</returns> /// <param name="sql">Sql.</param> /// <param name="paramArgs">Parameter arguments.</param> public Cursor RawQuery(String sql, params Object[] paramArgs) { if (!IsOpen) { throw Misc.CreateExceptionAndLog(Log.To.Database, StatusCode.BadRequest, TAG, "RawQuery called on closed database"); } Cursor cursor = null; sqlite3_stmt command = null; var t = Factory.StartNew(() => { try { Log.To.Database.V(TAG, "RawQuery sql: {0} ({1})", sql, String.Join(", ", paramArgs.ToStringArray())); command = BuildCommand(_readConnection, sql, paramArgs); cursor = new Cursor(command); } catch (Exception e) { if (command != null) { command.Dispose(); } var args = new SecureLogJsonString(paramArgs, LogMessageSensitivity.PotentiallyInsecure); Log.To.Database.E(TAG, String.Format("Error executing raw query '{0}' with values '{1}', rethrowing...", sql, paramArgs == null ? (object)String.Empty : new SecureLogJsonString(args, LogMessageSensitivity.PotentiallyInsecure)), e); LastErrorCode = raw.sqlite3_errcode(_readConnection); throw; } return(cursor); }); return(t.Result); }
/// <summary> /// Executes only read-only SQL. /// </summary> /// <returns>The query.</returns> /// <param name="sql">Sql.</param> /// <param name="paramArgs">Parameter arguments.</param> public Cursor RawQuery(String sql, params Object[] paramArgs) { if (!IsOpen) { throw Misc.CreateExceptionAndLog(Log.To.Database, StatusCode.BadRequest, TAG, "RawQuery called on closed database"); } Cursor cursor = null; sqlite3_stmt command = null; var connection = default(Connection); //Log.To.TaskScheduling.V(TAG, "Scheduling RawQuery"); //var t = Factory.StartNew (() => //{ Log.To.TaskScheduling.V(TAG, "Running RawQuery"); try { connection = IsOnDBThread ? new Connection(_writeConnection, null) : _readerConnections.Acquire(); Log.To.Database.V(TAG, "RawQuery sql ({2}): {0} ({1})", sql, String.Join(", ", paramArgs.ToStringArray()), IsOnDBThread ? "read uncommit" : "read commit"); command = BuildCommand(connection.Raw, sql, paramArgs); cursor = new Cursor(command, connection); } catch (Exception e) { if (command != null) { command.Dispose(); } var args = new SecureLogJsonString(paramArgs, LogMessageSensitivity.PotentiallyInsecure); Log.To.Database.E(TAG, String.Format("Error executing raw query '{0}' with values '{1}', rethrowing...", sql, paramArgs == null ? (object)String.Empty : new SecureLogJsonString(args, LogMessageSensitivity.PotentiallyInsecure)), e); LastErrorCode = raw.sqlite3_errcode(connection.Raw); throw; } return(cursor); //}); //return t.Result; }