public IEnumerable<ParserItem> Find (string prefix, ParserItemType itemType, int depth) { if (s_FindWithType == null) { var command = new SqliteCommand (); command.CommandText = "SELECT " + s_ItemColumns + " FROM Items WHERE FullName LIKE @FullName"; command.CommandType = CommandType.Text; command.Parameters.Add ("FullName", DbType.String); command.Parameters.Add ("ItemType", DbType.Int32); s_FindWithType = command; // Race condition shouldn't matter } var findWithType = s_FindWithType.Clone () as SqliteCommand; if (itemType != ParserItemType.Any) { findWithType.CommandText += " AND ItemType == @ItemType"; findWithType.Parameters.Add ("ItemType", DbType.Int32); findWithType.Parameters ["ItemType"].Value = (int)itemType; } if (depth >= 0) { findWithType.CommandText += " AND Depth == @Depth"; findWithType.Parameters.Add ("Depth", DbType.Int32); findWithType.Parameters ["Depth"].Value = depth; } findWithType.Connection = m_conn; findWithType.Parameters ["FullName"].Value = prefix.Replace ("%", "\\%") + "%"; using (var reader = findWithType.ExecuteReader ()) { while (reader.Read ()) { ParserItem item = new ParserItem (); item.Deserialize (reader); yield return item; } } }
void CopyDatabase (SqliteConnection src) { Console.WriteLine ("Migrating python completion database to version {0}", s_version); int batchSize = 100; var cmd = new SqliteCommand ("SELECT " + s_ItemColumns + " FROM Items;", src); var reader = cmd.ExecuteReader (); int i = 0; var items = new List<ParserItem> (); var rowsCommand = new SqliteCommand ("SELECT count(*) FROM Items;", src); var count = (long)rowsCommand.ExecuteScalar (); var progress = IdeApp.Workbench.ProgressMonitors.GetBackgroundProgressMonitor ("Python Completion Database", Gtk.Stock.Execute); progress.BeginTask ("Migrating completion database", (int)count); while (reader.Read ()) { var item = new ParserItem (); item.Deserialize (reader); items.Add (item); i++; if (i % batchSize == 0) { AddRange (items); progress.Step (items.Count); items.Clear (); } } if (items.Count > 0) AddRange (items); progress.Step (items.Count); items.Clear (); progress.Dispose (); }
public IEnumerable<ParserItem> Find (string prefix) { if (s_Find == null) { var command = new SqliteCommand (); command.CommandText = "SELECT " + s_ItemColumns + " FROM Items WHERE FullName LIKE @FullName;"; command.CommandType = CommandType.Text; command.Parameters.Add ("FullName", DbType.String); s_Find = command; } var find = s_Find.Clone () as SqliteCommand; find.Connection = m_conn; find.Parameters ["FullName"].Value = prefix.Replace ("%", "\\%") + "%"; using (var reader = find.ExecuteReader ()) { while (reader.Read ()) { ParserItem item = new ParserItem (); item.Deserialize (reader); yield return item; } } }