private RowsRet ExecuteCommand(string szCommand, IntPtr hBind) { if (ShowAllCommands) { Debug.WriteLine("Command: " + szCommand); } RowsRet ret = new RowsRet(); IntPtr hRet = IntPtr.Zero; lock (DbWorker) { using (StringMarshal sm = new StringMarshal(szCommand)) { #if SQL_LITE_Time_Commands SQLCommandTime time; string normalized = szCommand.ToLower(); System.Text.RegularExpressions.Regex re = new System.Text.RegularExpressions.Regex( "'[^']+'"); normalized = re.Replace(normalized, "-"); re = new System.Text.RegularExpressions.Regex( "[0-9]+"); normalized = re.Replace(normalized, "#"); if (normalized.StartsWith("BEGIN")) { normalized = "[Compound query]"; } normalized = SQLCommandTime.CurrentThreadID + " - " + normalized; if (m_timings.ContainsKey(normalized)) { time = m_timings[normalized]; } else { time = new SQLCommandTime(); time.Command = szCommand; m_timings.Add(normalized, time); } time.LastStart = DateTime.Now; long temp; long kernelStart; long userStart; WinAPI.GetThreadTimes(WinAPI.GetCurrentThread(), out temp, out temp, out kernelStart, out userStart); #endif hRet = m_imports.delegates.ExecuteCommand( m_hDB, sm.Native, hBind); #if SQL_LITE_Time_Commands long kernelEnd; long userEnd; WinAPI.GetThreadTimes( WinAPI.GetCurrentThread(), out temp, out temp, out kernelEnd, out userEnd); time.LastEnd = DateTime.Now; time.TotalThreadTime += (kernelEnd - kernelStart) + (userEnd - userStart); time.TotalTime += time.LastEnd - time.LastStart; time.TotalCalls++; #endif } } if (hRet == IntPtr.Zero) { throw new SQL_Lite_Exception("SQL Error: " + StringMarshal.Convert( m_imports.delegates.GetDBLastError(m_hDB))); } else { int rows = 0; int cols = 0; m_imports.delegates.GetTableSize(m_hDB, hRet, ref rows, ref cols); ret.Rows.Capacity = rows; for (int row = 0; row < rows; row++) { Row currow = new Row(ret); if (!(row == 0 && m_startRow == 1)) { ret.Rows.Add(currow); } if (row == 0) { ret.Headers = currow; } for (int col = 0; col < cols; col++) { currow.Cols.Add(StringMarshal.Convert( m_imports.delegates.GetString( m_hDB, hRet, row, col))); } } m_imports.delegates.CloseReturn(m_hDB, hRet); } return(ret); }
public string GetSQLiteVersion() { return(StringMarshal.Convert( m_imports.delegates.GetSQLiteVersion())); }