示例#1
0
        private static void PopulateSQLite(SQLiteDba sqliteDba)
        {
            tblTestRow [] rows = new tblTestRow [] {
                new tblTestRow(1, "Number one."),
                new tblTestRow(2, "Number two."),
                new tblTestRow(3, "Number three.")
            };

            sqliteDba.ExecuteSqlCommand(_sqlCreateTable);

            foreach(tblTestRow row in rows) {
                DbParameter[] parameters = new DbParameter [] {
                    new SQLiteParameter("@id", row.Id),
                    new SQLiteParameter("@description", row.Description)
                };
                sqliteDba.ExecuteSqlCommand(_sqlInsertRow, parameters);
            }
            string [] columnData = sqliteDba.GetColumnAsStringArray("tblTest", "description");
            Assert.AreEqual(columnData.Length, 3, "Inserted 3 rows and retrieved {0}", new object[] {columnData.Length});
        }
示例#2
0
        void CmdConvertClick(object sender, EventArgs e)
        {
            txtLog.Text = String.Format("Start Time: {0}", DateTime.Now.ToLongTimeString());
            OdbcDba JetDb = new OdbcDba();
            SQLiteDba SQLiteDb = new SQLiteDba();

            try {
                File.Delete(this.SQLiteFile);
            } catch (IOException) {
                string Msg = String.Format("Cannot delete the existing SQLite file {0}", SQLiteFile);
                MessageBox.Show(Msg);
                return;
            }
            try {
                JetDb.ConnectMDB(this.JetSqlFile);
            } catch (OdbcException ex) {
                //TODO: this is the error code for incorrect access password. Make this a constant.
                if (ex.ErrorCode == -2147217843 || ex.ErrorCode == -2146232009) {
                    DialogResult Result;
                    InputDialog GetPassword = new InputDialog();
                    Result = GetPassword.ShowDialog("Enter the password for the database");
                    if (Result == DialogResult.OK) {
                        try {
                            ((OdbcDba) JetDb).ConnectMDB(JetSqlFile, GetPassword.Input);
                        } catch (OdbcException exSecond) {
                            if (ex.ErrorCode == -2147217843 || ex.ErrorCode == -2146232009) {
                                MessageBox.Show("Incorrect Password");
                            } else {
                                throw exSecond;
                            }
                            return;
                        } finally { GetPassword.Dispose(); }
                    }
                } else if (ex.ErrorCode == -2147467259) {
                    Text = "PlaneDisaster.NET";
                    string Msg = String.Format("File [{0}] not found.", JetSqlFile);
                    MessageBox.Show(Msg, "Error Opening File");
                    return;
                } else {
                    throw ex;
                }
            }

            SQLiteDb.Connect(this.SQLiteFile);

            string [] Tables = JetDb.GetTables();

            foreach (string Table in Tables ) {
                try {
                    SQLiteDb.DataTable2SQLiteTable(JetDb.GetTableAsDataTable(Table));
                } catch (OdbcException ex) {
                    string Message = String.Format("{0}: {1}\n", Table, ex.Message);
                    File.AppendAllText(String.Concat(SQLiteFile, ".log"), Message);
                }
            }
            JetDb.Disconnect();
            SQLiteDb.Disconnect();
            MessageBox.Show("Database Successfully converted.");
            txtLog.Text += String.Format(" End Time: {0}", DateTime.Now.ToLongTimeString());
        }
示例#3
0
        public void TestSQLite()
        {
            string fileName = Path.Combine(_tempDirectory, _tempFilePrefix + ".sqlite");
            try {
                CreateSQLite(fileName);

                SQLiteDba sqliteDba = new SQLiteDba();
                sqliteDba.Connect(fileName);

                PopulateSQLite(sqliteDba);

                sqliteDba.ExecuteSqlCommand(_sqlDropTable);

                sqliteDba.Disconnect();
            }
            finally
            {
                File.Delete(fileName);
                Assert.IsFalse(File.Exists(fileName), "Failed to delete " + fileName);
            }
        }