예제 #1
0
 /// <inheritdoc/>
 public override DataSet Select(string q)
 {
     if (data == null)
     {
         data = new DataSet();
     }
     data.Tables.Clear(); using (SQLiteDb db = new SQLiteDb(datafile)) data = db.Select(Context.TableName, q, AdapterSelect, FillSelect); return(data);
 }
예제 #2
0
 public override DataSet SelectCategory(string q)
 {
     category.Tables.Clear();
     category.Tables.Add(Context.CategoryName);
     using (SQLiteDb db = new SQLiteDb(datafile))
         category = db.Select(Context.CategoryName, q, SelectCategoryAdapter, SelectCategoryFillOperation);
     return(category);
 }
예제 #3
0
        /// <summary>
        /// Loads the application's templates.
        /// In the future the application should be set up to call on this method to re-load the templates.
        /// </summary>
        void Initialize(string datafile_sqlite)
        {
            if (CheckPathForErrors(datafile_sqlite))
            {
                return;
            }
            TemplateElement ele;

            Templates.Clear();
            using (SQLiteDb db = new SQLiteDb(datafile_sqlite))
                using (DataSet ds = db.Select("templates", sql_select_templates, SelectTemplatesAdapter))
                    using (DataView v = ds.GetDataView("templates"))
                        foreach (DataRowView rv in v)
                        {
                            Templates.Add(TemplateElement.FromRowView(rv));
                        }
        }
예제 #4
0
 void Event_ExecuteSelectQuery(object sender, RoutedEventArgs args)
 {
     if (!database.IsLoaded)
     {
         return;
     }
     using (var db = new SQLiteDb(database.DataFile))
     {
         try {
             data = db.Select("mytable", edit.Text, DBSelect, Adapt);
             if (data.Tables.Count > 0)
             {
                 grid.ItemsSource = data.Tables["mytable"].DefaultView;
             }
         }
         catch (Exception error) { ThrowException(error, selectError: true); }
     }
 }
예제 #5
0
            public setting GetValue(SQLiteDb db, string name, string typ, string grp)
            {
                AdapterSelectAction = delegate(DbOp op, string Query, SQLiteConnection c){
                    SQLiteDataAdapter a = new SQLiteDataAdapter(Query, c);
                    a.SelectCommand.Parameters.AddWithValue("@name", name);
                    if (grp != null)
                    {
                        a.SelectCommand.Parameters.AddWithValue("@grp", grp);
                    }
                    if (typ != null)
                    {
                        a.SelectCommand.Parameters.AddWithValue("@type", typ);
                    }
                    return(a);
                };
                string q = @"select * from [settings] where [name] = @name;";

                if (typ != null)
                {
                    q.Replace(";", " and [type] = @type;");
                }
                if (grp != null)
                {
                    q.Replace(";", " and [grp] = @grp;");
                }

                setting s = null;

                using (DataSet ds = db.Select(Context.TableName, q, AdapterSelectAction, FillSelect))
                {
                    if (ds.Tables[0].Rows.Count == 1)
                    {
                        s = new setting(ds.Tables[0].DefaultView[0]);
                    }
                    else
                    {
                        Logger.Warn("GetValue: ERROR", "NOTHING RETURNED!");
                    }
                }
                return(s);
            }
예제 #6
0
        /// <summary>
        /// Applies a set of values from a Template to the results of a SQLite Data Operation.
        /// <para>Note that currently this class requires a COMPILER-LEVEL VARIABLE of 'NET35'</para>
        /// </summary>
        /// <remarks>This method is particularly for a personal project or two, however
        /// the methods for this are here to suggest the extension of this namespace
        /// to include more support to data-template operations.</remarks>
        /// <returns>THe template-formatted string.</returns>
        /// <param name="sqliteConnection">SQLiteConnection.</param>
        /// <param name="query">A SQL SELECT query.</param>
        /// <param name="dataFillCallback">A callback to fill generated dataset.</param>
        /// <param name="rowContainer">A Row-level string providing a container for subsequent rows.</param>
        /// <param name="rowContainerTag">The supplied tag such as '{0}' which is used as a string replacement value for the row-container.
        /// The templated row-results be stacked where this token was placed.</param>
        /// <param name="rowTemplate">A template applied to each resulting row.</param>
        /// <param name="rowSeparator">usually an empty sting, or a EOL terminator.</param>
        /// <param name="replaceMethod">User supplied callback to provide row-field specific filters to data results.</param>
        /// <exception cref="ArgumentException">is thrown if any paraemter is null.</exception>
        static public string SQLiteSelect_Tpl(
            // database constructs
            string sqliteConnection,
            string query,
            SQLiteDb.CBRowParam dataFillCallback,
            // template constructs
            string rowContainer,
            string rowContainerTag,
            string rowTemplate,
            string rowSeparator,
            Func <string, DataRowView, string> replaceMethod)
        {
            List <string> list   = new List <string>();
            string        output = null;

            using (SQLiteDb db = new SQLiteDb(sqliteConnection))
                using (DataSet ds = db.Select("settings", query, dataFillCallback))
                    using (DataView v = ds.GetDataView("settings"))
                    {
                        output = v.DataViewReplace(rowContainer, rowTemplate, rowSeparator, rowContainerTag, replaceMethod);
                    }
            return(output);
        }