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;
				}
			}
		}
		static string IconForType (ParserItem item)
		{
			switch (item.ItemType) {
			case ParserItemType.Module:
				return s_ImgModule;
			case ParserItemType.Class:
				return s_ImgClass;
			case ParserItemType.Function:
				return s_ImgFunc;
			case ParserItemType.Attribute:
			case ParserItemType.Local:
				return s_ImgAttr;
			default:
				return String.Empty;
			}
		}
		static CompletionData CreateCompletionData (ParserItem item, string triggerWord, string suffix)
		{
			var name = item.FullName.Substring (triggerWord.Length);
			return new CompletionData (name, IconForType (item), item.Documentation, name + suffix);
		}
		static CompletionData CreateCompletionData (ParserItem item, string triggerWord)
		{
			return CreateCompletionData (item, triggerWord, "");
		}
Example #7
0
		public void Add (ParserItem item)
		{
			m_rwLock.AcquireWriterLock (s_lockTimeout);
			try {
				item.Serialize (m_conn);
			}
			finally {
				m_rwLock.ReleaseWriterLock ();
			}
		}