예제 #1
0
    public void CloseSqlConnection()
    {
        if (dbCommand != null)
        {
            dbCommand.Clone();
        }

        dbCommand = null;

        if (reader != null)
        {
            reader.Close();
        }

        reader = null;

        if (dbConnection != null)
        {
            dbConnection.Close();
        }

        dbConnection = null;

        Debug.Log("Disconnected from db.关闭数据库!");
    }
        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);
                }
            }
        }
예제 #3
0
    private void UpdateDatabase(string query, params SqliteParameter[] queryParams)
    {
        SqliteConnection connection = new SqliteConnection(dbPath);

        connection.Open();
        SqliteCommand command = connection.CreateCommand();

        command.Clone();
        command.CommandType = CommandType.Text;
        command.CommandText = query;
        command.Parameters.AddRange(queryParams);
        command.ExecuteNonQuery();
        connection.Close();
    }
예제 #4
0
		public void RemoveByFilePrefix (string prefix)
		{
			if (s_RemoveByFilePrefix == null) {
				var command = new SqliteCommand ();
				command.CommandText = "DELETE FROM Items WHERE FileName LIKE @FileName;";
				command.CommandType = CommandType.Text;
				command.Parameters.Add ("FileName", DbType.String);
				s_RemoveByFilePrefix = command;
			}
			
			var copyCommand = s_RemoveByFilePrefix.Clone () as SqliteCommand;
			copyCommand.Connection = m_conn;
			copyCommand.Parameters ["FileName"].Value = prefix + "%";
			copyCommand.ExecuteNonQuery ();
		}
        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);
                }
            }
        }
예제 #6
0
        SqliteCommand GetInsertCommand()
        {
            if (s_InsertCommand == null)
            {
                var command = new SqliteCommand();
                command.CommandText =
                    "INSERT OR REPLACE into Items (" +
                    "FullName, Depth, FileName, LineNumber, ItemType, Pydoc, Extra) " +
                    "VALUES (@FullName, @Depth, @FileName, @LineNumber, @ItemType, @Pydoc, @Extra)";
                command.Parameters.Add("FullName", DbType.String);
                command.Parameters.Add("Depth", DbType.Int32);
                command.Parameters.Add("FileName", DbType.String);
                command.Parameters.Add("LineNumber", DbType.Int32);
                command.Parameters.Add("ItemType", DbType.Int32);
                command.Parameters.Add("Pydoc", DbType.String);
                command.Parameters.Add("Extra", DbType.String);
                s_InsertCommand = command;
            }

            var copyCommand = s_InsertCommand.Clone() as SqliteCommand;

            return(copyCommand);
        }
예제 #7
0
 public void close()
 {
     COM.Clone();
     CON.Clone();
 }