/// <summary> /// Executes an SQL statemant on an opened connection. Before using /// execute ensure that you have opened up the connection using the /// open method. This method shell be used for data manipulation /// statemants. If you'd like to query data use query(). /// </summary> /// <param name="sql">The SQL statemant to execute.</param> public void execute(string sql) { try { IntPtr errMsgPtr = IntPtr.Zero; if (SQLitePInvoke.sqlite3_exec(db, sql, ref errMsgPtr) != SQLitePInvoke.SQLITE_OK) { var errMsg = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(errMsgPtr); SQLitePInvoke.sqlite3_free(errMsgPtr); throw new Exception( String.Format("Error executing sqlite3_exec() - {0}!", errMsg)); } } catch (Exception e) { throw new Exception("Could not execute SQL statement.", e); } }
/// <summary> /// Execute a data query statemant (\c SELECT). This method differs from /// execute() only in that it fills the LastQuery property. You may use /// this method for data manipulation statemants as well but this would /// clear the LastQuery property. /// </summary> /// <param name="sql">The sql statemant to query the database.</param> public void query(string sql) { LastQuery = new List <Dictionary <string, string> >(); try { IntPtr errMsgPtr = IntPtr.Zero; if (SQLitePInvoke.sqlite3_exec(db, sql, ref errMsgPtr, query) != SQLitePInvoke.SQLITE_OK) { var errMsg = Marshal.PtrToStringAnsi(errMsgPtr); SQLitePInvoke.sqlite3_free(errMsgPtr); throw new Exception( String.Format("Error executing sqlite3_exec() - {0}!", errMsg)); } } catch (Exception e) { throw new Exception("Could not execute SQL statement.", e); } }