Example #1
0
        public void DiskMerge()
        {
            string strQueryFront = "ATTACH database '" + dbToMergeWith + "' AS disk;";

            Sqlite3.sqlite3_exec(pDb, strQueryFront, 0, 0, 0);
            rc = Sqlite3.sqlite3_errcode(pDb);
            if (rc == 0)
            {
                foreach (string table in tables)
                {
                    Sqlite3.sqlite3_exec(pDb, "CREATE TABLE disk." + table + " AS SELECT * FROM " + table + ";", 0, 0, 0);
                    rc = Sqlite3.sqlite3_errcode(pDb);
                    if (rc != 0)
                    {
                        Sqlite3.sqlite3_close(pDb);
                        return;
                    }
                }
                rc = Sqlite3.exec(pDb, "DETACH disk;", 0, 0, 0);
            }
            Sqlite3.sqlite3_close(pDb);
        }
Example #2
0
        public DataSet GetDBTables()
        {
            DataSet       fredDs = new DataSet("FRED");
            List <string> tables = run_table_names_query(pDb);
            int           rc     = 0;

            foreach (string table in tables)
            {
                bool          firstRun = true;
                List <string> names    = new List <string>();
                List <string> arrRows  = new List <string>();
                List <string> colNames = run_column_name_query(pDb, table);
                string        zSql     = "SELECT * from " + table + ";";
                sqlite3_stmt  pSelect  = new sqlite3_stmt();
                string        sDummy   = null;
                rc = Sqlite3.sqlite3_prepare(pDb, zSql, -1, ref pSelect, ref sDummy);
                if (rc != Sqlite3.SQLITE_OK || null == pSelect)
                {
                    continue;
                }
                rc = Sqlite3.sqlite3_step(pSelect);
                DataTable dt = new DataTable(table);
                while (rc == Sqlite3.SQLITE_ROW)
                {
                    //Get the data in the cell
                    int     total = Sqlite3.sqlite3_column_count(pSelect);
                    DataRow dr    = dt.NewRow();

                    List <string> values = new List <string>();
                    for (int i = 0; i < total; i++)
                    {
                        int           valInt = 0;
                        string        value  = "";
                        sqlite3_value val    = Sqlite3.sqlite3_column_value(pSelect, i);
                        if (val.type == 1)
                        {
                            valInt = Sqlite3.sqlite3_column_int(pSelect, i);
                            value  = valInt.ToString();
                        }
                        else
                        {
                            value = val.z;
                        }
                        values.Add(value);
                        if (firstRun)
                        {
                            string name = Sqlite3.sqlite3_column_name(pSelect, i);
                            if (name == null)
                            {
                                continue;
                            }
                            names.Add(name);
                            dt.Columns.Add(name);
                        }
                    }
                    rc       = Sqlite3.sqlite3_step(pSelect);
                    firstRun = false;
                    for (int i = 0; i < names.Count && i < values.Count; i++)
                    {
                        dr[names[i]] = values[i];
                    }
                    dt.Rows.Add(dr);
                }
                Sqlite3.sqlite3_finalize(pSelect);
                fredDs.Tables.Add(dt);
            }
            Sqlite3.sqlite3_close(pDb);
            return(fredDs);
        }