Пример #1
0
        /// <summary>
        /// Executes the query. The first row in the results will be the column names
        /// </summary>
        /// <param name="query">SQL query to execute</param>
        /// <param name="includeColumnNames"> If true first row in results are the clumn names</param>
        /// <returns>Query results</returns>
        public override List <string[]> ExecuteQuery(string query, bool includeColumnNames)
        {
            Trace.TraceInformation($"SQLite ExecuteQuery '{query}'");
            var result  = new List <string[]>();
            var c1      = new SQLiteVdbe(Db, query);
            int columns = 0;

            while (c1.ExecuteStep() == Sqlite3.SQLITE_ROW)
            {
                columns = c1.ResultColumnCount();
                var data = new string[columns];
                for (int i = 0; i < columns; i++)
                {
                    data[i] = c1.Result_Text(i);
                }
                result.Add(data);
            }

            if (includeColumnNames)
            {
                var columnNames = new List <string>();
                for (int i = 0; i < columns; i++)
                {
                    columnNames.Add(c1.ColumnName(i));
                }
                result.Insert(0, columnNames.ToArray());
            }

            c1.Close();
            return(result);
        }