public RowsRet Explain(string sql, bool queryPlan) { RowsRet ret = ExecuteCommand( "EXPLAIN " + (queryPlan ? "QUERY PLAN " : "") + sql); return(ret); }
public bool DatabaseObjectExists(string name) { RowsRet rows = null; rows = ExecuteCommand( "SELECT COUNT(*) FROM sqlite_master WHERE name=?", name); if (rows == null || rows.Rows.Count < ((m_startRow == 0) ? 2 : 1)) { return(false); } else { int count = int.Parse(rows.Rows[(m_startRow == 0) ? 1 : 0].Cols[0]); if (count >= 1) { return(true); } else { return(false); } } }
public static RowDictionary RowsToDict(RowsRet rows) { RowDictionary rowDict = new RowDictionary(); List <string> .Enumerator headerRow = rows.Rows[0].Cols.GetEnumerator(); foreach (string cell in rows.Rows[1].Cols) { headerRow.MoveNext(); rowDict.Add(headerRow.Current, cell); } return(rowDict); }
public RowReader(RowsRet ret) { bool header = true; if (ret.Rows.Count > 1) { Capacity = ret.Rows.Count - 1; foreach (Row row in ret.Rows) { if (!header) { Add(SQL_Lite.RowsToDict(ret.Rows[0], row)); } else { header = false; } } } }
public Row(RowsRet ResultSet) { this._ResultSet = ResultSet; }
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 RowsRet ExecuteCommandParams(string szCommand, object[] args) { IntPtr hBind = m_imports.delegates.CreateBindObject(m_hDB); foreach (object arg in args) { StringMarshal sm; if (arg is Int64) { sm = new StringMarshal(ToString((Int64)arg)); m_imports.delegates.AddStringToBind( m_hDB, hBind, sm.OwnNative); } else if (arg is Boolean) { sm = new StringMarshal(ToString((Boolean)arg)); m_imports.delegates.AddStringToBind( m_hDB, hBind, sm.OwnNative); } else if (arg is DateTime) { sm = new StringMarshal(ToString((DateTime)arg)); m_imports.delegates.AddStringToBind( m_hDB, hBind, sm.OwnNative); } else if (arg is Int32) { sm = new StringMarshal((ToString((Int32)arg))); m_imports.delegates.AddStringToBind( m_hDB, hBind, sm.OwnNative); } else if (arg is Single) { sm = new StringMarshal((ToString((Single)arg))); m_imports.delegates.AddStringToBind( m_hDB, hBind, sm.OwnNative); } else if (arg is Double) { sm = new StringMarshal((ToString((Double)arg))); m_imports.delegates.AddStringToBind( m_hDB, hBind, sm.OwnNative); } else if (arg is string) { sm = new StringMarshal((string)arg); m_imports.delegates.AddStringToBind( m_hDB, hBind, sm.OwnNative); } else if (arg == null) { sm = new StringMarshal(IntPtr.Zero); m_imports.delegates.AddStringToBind( m_hDB, hBind, sm.OwnNative); } else { throw new Exception("Unknown type: " + arg.GetType().ToString()); } } RowsRet ret = ExecuteCommand(szCommand, hBind); m_imports.delegates.CloseBindObject(m_hDB, hBind); return(ret); }