public void SetupServer() { CSConfig.SetDB(new CSDataProviderSqlServer("Initial Catalog=cstest;Data Source=DBSERV;User ID=nunit;PWD=nunit;")); CSDatabase.ExecuteNonQuery(_sqlCreateTables); }
public void SetupServer() { string path = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..\\Data\\coolstorage.vdb3")); if (File.Exists(path)) { File.Delete(path); } IVistaDBDatabase database = VistaDBEngine.Connections.OpenDDA().CreateDatabase(path, false, null, 0, 0, false); database.Close(); CSConfig.SetDB(new CSDataProviderVistaDB(@"Data Source=" + path)); CSDatabase.ExecuteNonQuery(_sqlCreateTables); }
public ProductsTableViewCtrl(IntPtr handle) : base(handle) { string dbDirectory = Path.Combine( NSBundle.MainBundle.BundlePath, DataDirectory ); string dbPath = Path.Combine(dbDirectory, DataFile); CSConfig.SetDB(dbPath, SqliteOption.CreateIfNotExists, () => { CSDatabase.ExecuteNonQuery(AmazonProductInfo.CreateDbQuery); } ); TableView.Source = new TableSource(this, AmazonProductInfo.All()); }
public static void ConnectDatabase(string databaseWorkingCopyPath) { try { if (!FileExists(databaseWorkingCopyPath)) { Manager.Instance.RestoreWorkingCopyOfDatabase(databaseWorkingCopyPath); } CSConfig.SetDB(new CSDataProviderSqlite("Data Source=" + databaseWorkingCopyPath)); DLogger.WriteLog(string.Format("Connected to Db: " + databaseWorkingCopyPath)); return; } catch (Exception ex) { DLogger.WriteLog(ex); throw new Exception(string.Format("Can't connect to database at \"{0}\"", databaseWorkingCopyPath), ex); } }
// This method checks to see if the database exists, and if it doesn't, it creates // it and inserts some data. It also sets our database to be the default database // connection. protected void CheckAndCreateDatabase(string dbName) { // determine whether or not the database exists bool dbExists = File.Exists(GetDBPath(dbName)); // configure the current database, create if it doesn't exist, and then run the anonymous // delegate method after it's created CSConfig.SetDB(GetDBPath(dbName), SqliteOption.CreateIfNotExists, () => { CSDatabase.ExecuteNonQuery("CREATE TABLE People (PersonID INTEGER PRIMARY KEY AUTOINCREMENT, FirstName text, LastName text)"); // if the database had to be created, let's populate with initial data if (!dbExists) { // declare vars CSList <Person> people = new CSList <Person> (); Person person; // create a list of people that we're going to insert person = new Person() { FirstName = "Peter", LastName = "Gabriel" }; people.Add(person); person = new Person() { FirstName = "Thom", LastName = "Yorke" }; people.Add(person); person = new Person() { FirstName = "J", LastName = "Spaceman" }; people.Add(person); person = new Person() { FirstName = "Benjamin", LastName = "Gibbard" }; people.Add(person); // save the people collection to the database people.Save(); } }); }
public static void SetDB(string dbName, SqliteOption sqliteOption, Action creationDelegate) { bool exists = File.Exists(dbName); bool createIfNotExists = (sqliteOption & SqliteOption.CreateIfNotExists) != 0; bool usePooling = (sqliteOption & SqliteOption.UseConnectionPooling) != 0; if (!exists && createIfNotExists) { SqliteConnection.CreateFile(dbName); } CSConfig.SetDB(new CSDataProviderSqlite("Data Source=" + dbName + ";Pooling=" + usePooling), CSConfig.DEFAULT_CONTEXTNAME); if (!exists && createIfNotExists && creationDelegate != null) { creationDelegate(); } }
protected void InitDB(string dbName) { // The following line will tell CoolStorage where the database is, // create it if it does not exist, and call a delegate which // creates the necessary tables (only if the database file was // created new) CSConfig.SetDB(dbName, SqliteOption.CreateIfNotExists, () => { CSDatabase.ExecuteNonQuery(_sqlCreateApplicationState); CSDatabase.ExecuteNonQuery(_sqlCreateLog); CSDatabase.ExecuteNonQuery(_sqlCreateMoodCategory); CSDatabase.ExecuteNonQuery(_sqlCreateMood); CSDatabase.ExecuteNonQuery(_sqlCreateActivity); CSDatabase.ExecuteNonQuery(_sqlCreateMoodPrompt); CSDatabase.ExecuteNonQuery(_sqlCreateMoodResponse); CSDatabase.ExecuteNonQuery(_sqlCreateMoodReport); CSDatabase.ExecuteNonQuery(_sqlCreateSnapshot); CSDatabase.ExecuteNonQuery(_sqlCreateMoodSnapshot); //indexes CSDatabase.ExecuteNonQuery(_sqlCreateIxMoodPrompt); CSDatabase.ExecuteNonQuery(_sqlCreateIxMoodResponse); CSDatabase.ExecuteNonQuery(_sqlCreateIxMoodReport); CSDatabase.ExecuteNonQuery(_sqlCreateIxSnapshot); CSDatabase.ExecuteNonQuery(_sqlCreateIxMoodSnapshot); }); MoodReport.AnyObjectDeleting += (MoodReport sender, ObjectDeleteEventArgs e) => { Console.WriteLine("Delete report event"); sender.Snapshots.DeleteAll(); }; Snapshot.AnyObjectDeleting += (Snapshot sender, ObjectDeleteEventArgs e) => { Console.WriteLine("Delete snapshot event"); sender.Moods.DeleteAll(); }; }
public void SetupServer() { CSConfig.SetDB(new CSDataProviderMySql("Server=192.168.1.41;Database=cstest;UID=nunit;PWD=nunit")); CSDatabase.ExecuteNonQuery("drop table if exists tblCustomers"); CSDatabase.ExecuteNonQuery("drop table if exists tblCustomerPaymentMethodLinks"); CSDatabase.ExecuteNonQuery("drop table if exists tblOrderItems"); CSDatabase.ExecuteNonQuery("drop table if exists tblOrders"); CSDatabase.ExecuteNonQuery("drop table if exists tblSalesPeople"); CSDatabase.ExecuteNonQuery("drop table if exists tblCoolData"); CSDatabase.ExecuteNonQuery("drop table if exists tblPaymentMethods"); CSDatabase.ExecuteNonQuery( "CREATE TABLE tblCustomers (CustomerID INTEGER PRIMARY KEY AUTO_INCREMENT,Name VARCHAR(50) NOT NULL)"); CSDatabase.ExecuteNonQuery( @"CREATE INDEX tblCustomers_Name ON tblCustomers (Name)"); CSDatabase.ExecuteNonQuery( @"CREATE TABLE tblCustomerPaymentMethodLinks ( CustomerID integer NOT NULL, PaymentMethodID integer NOT NULL, primary key (CustomerID,PaymentMethodID) )"); CSDatabase.ExecuteNonQuery( @"CREATE TABLE tblOrderItems ( OrderItemID INTEGER PRIMARY KEY AUTO_INCREMENT, OrderID integer NOT NULL, Qty integer NOT NULL, Price real NOT NULL, Description varchar(200) NOT NULL ) "); CSDatabase.ExecuteNonQuery( @"CREATE INDEX tblOrderItems_OrderID ON tblOrderItems (OrderID)"); CSDatabase.ExecuteNonQuery( @"CREATE TABLE tblOrders ( OrderID INTEGER PRIMARY KEY AUTO_INCREMENT, Date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, CustomerID integer NOT NULL, SalesPersonID integer NULL, DataState varchar(50))"); CSDatabase.ExecuteNonQuery( @"CREATE INDEX tblOrders_CustomerID ON tblOrders (CustomerID)"); CSDatabase.ExecuteNonQuery( @"CREATE INDEX tblOrders_SalesPersonID ON tblOrders (SalesPersonID)"); CSDatabase.ExecuteNonQuery( @"CREATE TABLE tblPaymentMethods ( PaymentMethodID integer primary key auto_increment, Name varchar(50) NOT NULL, MonthlyCost integer NOT NULL )"); CSDatabase.ExecuteNonQuery( @"CREATE TABLE tblSalesPeople ( SalesPersonID integer primary key auto_increment, Name varchar(50) NOT NULL, SalesPersonType integer NULL) "); CSDatabase.ExecuteNonQuery( @"CREATE TABLE tblCoolData ( CoolDataID varchar(50) PRIMARY KEY, Name varchar(50) NULL)"); // CSDatabase.ExecuteNonQuery( //@"CREATE TABLE tblColdData ( // ColdDataID varchar(50) PRIMARY KEY, // Name varchar(50) NULL)"); // // // CSDatabase.ExecuteNonQuery( // // @"CREATE TRIGGER //newid //BEFORE INSERT ON //tblColdData //FOR EACH ROW //SET NEW.id = UUID()" // // ); }
public void SetupServer() { CSConfig.SetDB(new CSDataProviderOracle("user id=CS;password=ABCDEFG;data source=dev-cweber/xe")); /* * -- Script to create the user with necessary roles * -- USER SQL * CREATE USER CS IDENTIFIED BY ABCDEFG * DEFAULT TABLESPACE "SYSTEM" * TEMPORARY TABLESPACE "TEMP"; * * -- ROLES * GRANT "CONNECT" TO CS ; * GRANT "DBA" TO "CS" ; * ALTER USER "CS" DEFAULT ROLE "DBA","CONNECT"; */ DontCare(() => CSDatabase.ExecuteNonQuery("drop table tblCustomers")); DontCare(() => CSDatabase.ExecuteNonQuery("drop table tblCustomerPaymentMethodLinks")); DontCare(() => CSDatabase.ExecuteNonQuery("drop table tblOrderItems")); DontCare(() => CSDatabase.ExecuteNonQuery("drop table tblOrders")); DontCare(() => CSDatabase.ExecuteNonQuery("drop table tblSalesPeople")); DontCare(() => CSDatabase.ExecuteNonQuery("drop table tblCoolData")); DontCare(() => CSDatabase.ExecuteNonQuery("drop table tblPaymentMethods")); DontCare(() => CSDatabase.ExecuteNonQuery("drop sequence Customer_seq")); DontCare(() => CSDatabase.ExecuteNonQuery("drop sequence Order_seq")); DontCare(() => CSDatabase.ExecuteNonQuery("drop sequence SalesPerson_seq")); DontCare(() => CSDatabase.ExecuteNonQuery("drop sequence PaymentMethod_seq")); DontCare(() => CSDatabase.ExecuteNonQuery("drop sequence OrderItem_seq")); CSDatabase.ExecuteNonQuery( @"CREATE TABLE tblCustomers ( CustomerID INTEGER PRIMARY KEY, Name VARCHAR2(50) NOT NULL )"); CSDatabase.ExecuteNonQuery( @"CREATE INDEX tblCustomers_Name ON tblCustomers (Name)"); CSDatabase.ExecuteNonQuery( @"CREATE TABLE tblCustomerPaymentMethodLinks ( CustomerID integer NOT NULL, PaymentMethodID integer NOT NULL, primary key (CustomerID,PaymentMethodID) )"); CSDatabase.ExecuteNonQuery( @"CREATE TABLE tblOrderItems ( OrderItemID INTEGER PRIMARY KEY, OrderID integer NOT NULL, Qty integer NOT NULL, Price float NOT NULL, Description varchar2(200) NOT NULL )"); CSDatabase.ExecuteNonQuery( @"CREATE INDEX tblOrderItems_OrderID ON tblOrderItems (OrderID)"); CSDatabase.ExecuteNonQuery( @"CREATE TABLE tblOrders ( OrderID INTEGER PRIMARY KEY, ""DATE"" DATE DEFAULT sysdate, CustomerID integer NOT NULL, SalesPersonID integer NULL, DataState varchar2(50) )"); CSDatabase.ExecuteNonQuery( @"CREATE INDEX tblOrders_CustomerID ON tblOrders (CustomerID)"); CSDatabase.ExecuteNonQuery( @"CREATE INDEX tblOrders_SalesPersonID ON tblOrders (SalesPersonID)"); CSDatabase.ExecuteNonQuery( @"CREATE TABLE tblPaymentMethods ( PaymentMethodID integer primary key, Name varchar2(50) NOT NULL, MonthlyCost integer NOT NULL )"); CSDatabase.ExecuteNonQuery( @"CREATE TABLE tblSalesPeople ( SalesPersonID integer primary key, Name varchar2(50) NOT NULL, SalesPersonType integer NULL )"); CSDatabase.ExecuteNonQuery( @"CREATE TABLE tblCoolData ( CoolDataID RAW(16) PRIMARY KEY, Name varchar2(50) NULL )"); CSDatabase.ExecuteNonQuery(@"create sequence Customer_seq start with 1 increment by 1 nomaxvalue "); CSDatabase.ExecuteNonQuery(@"create sequence Order_seq start with 1 increment by 1 nomaxvalue "); CSDatabase.ExecuteNonQuery(@"create sequence SalesPerson_seq start with 1 increment by 1 nomaxvalue "); CSDatabase.ExecuteNonQuery(@"create sequence PaymentMethod_seq start with 1 increment by 1 nomaxvalue "); CSDatabase.ExecuteNonQuery(@"create sequence OrderItem_seq start with 1 increment by 1 nomaxvalue "); }
public void SetupServer() { string fn = Path.GetTempFileName(); string path = Path.GetFullPath(fn); if (File.Exists(path)) { File.Delete(path); } if (File.Exists(path + "-journal")) { File.Delete(path + "-journal"); } CSConfig.SetDB(new CSDataProviderSQLite(@"data source=" + path)); CSDatabase.ExecuteNonQuery( "CREATE TABLE tblCustomers (CustomerID INTEGER PRIMARY KEY AUTOINCREMENT,Name TEXT(50) NOT NULL)"); CSDatabase.ExecuteNonQuery( @"CREATE INDEX tblCustomers_Name ON tblCustomers (Name)"); CSDatabase.ExecuteNonQuery( @"CREATE TABLE tblCustomerPaymentMethodLinks ( CustomerID integer NOT NULL, PaymentMethodID integer NOT NULL, primary key (CustomerID,PaymentMethodID) )"); CSDatabase.ExecuteNonQuery( @"CREATE TABLE tblOrderItems ( OrderItemID INTEGER PRIMARY KEY AUTOINCREMENT, OrderID integer NOT NULL, Qty integer NOT NULL, Price real NOT NULL, Description TEXT(200) NOT NULL ) "); CSDatabase.ExecuteNonQuery( @"CREATE INDEX tblOrderItems_OrderID ON tblOrderItems (OrderID)"); CSDatabase.ExecuteNonQuery( @"CREATE TABLE tblOrders ( OrderID INTEGER PRIMARY KEY AUTOINCREMENT, Date TEXT(30) NOT NULL DEFAULT CURRENT_TIMESTAMP, CustomerID integer NOT NULL, SalesPersonID integer NULL, DataState text(50))"); CSDatabase.ExecuteNonQuery( @"CREATE INDEX tblOrders_CustomerID ON tblOrders (CustomerID)"); CSDatabase.ExecuteNonQuery( @"CREATE INDEX tblOrders_SalesPersonID ON tblOrders (SalesPersonID)"); CSDatabase.ExecuteNonQuery( @"CREATE TABLE tblPaymentMethods ( PaymentMethodID integer primary key autoincrement, Name text(50) NOT NULL, MonthlyCost integer NOT NULL )"); CSDatabase.ExecuteNonQuery( @"CREATE TABLE tblSalesPeople ( SalesPersonID integer primary key autoincrement, Name text(50) NOT NULL, SalesPersonType integer NULL) "); CSDatabase.ExecuteNonQuery( @"CREATE TABLE tblCoolData ( CoolDataID text(50) PRIMARY KEY, Name text(50) NULL)"); }
public void SetupServer() { string path = "coolstorage.sqlite"; File.Delete(path); CSConfig.SetDB(path, SqliteOption.CreateIfNotExists | SqliteOption.UseConnectionPooling, () => { CSDatabase.ExecuteNonQuery( "CREATE TABLE tblCustomers (CustomerID INTEGER PRIMARY KEY AUTOINCREMENT,Name TEXT(50) NOT NULL)"); CSDatabase.ExecuteNonQuery( @"CREATE INDEX tblCustomers_Name ON tblCustomers (Name)"); CSDatabase.ExecuteNonQuery( @"CREATE TABLE tblCustomerPaymentMethodLinks ( CustomerID integer NOT NULL, PaymentMethodID integer NOT NULL, primary key (CustomerID,PaymentMethodID) )"); CSDatabase.ExecuteNonQuery( @"CREATE TABLE tblOrderItems ( OrderItemID INTEGER PRIMARY KEY AUTOINCREMENT, OrderID integer NOT NULL, Qty integer NOT NULL, Price real NOT NULL, Description TEXT(200) NOT NULL ) "); CSDatabase.ExecuteNonQuery( @"CREATE INDEX tblOrderItems_OrderID ON tblOrderItems (OrderID)"); CSDatabase.ExecuteNonQuery( @"CREATE TABLE tblOrders ( OrderID INTEGER PRIMARY KEY AUTOINCREMENT, Date TEXT(30) NOT NULL DEFAULT CURRENT_TIMESTAMP, CustomerID integer NOT NULL, SalesPersonID integer NULL, DataState text(50))"); CSDatabase.ExecuteNonQuery( @"CREATE INDEX tblOrders_CustomerID ON tblOrders (CustomerID)"); CSDatabase.ExecuteNonQuery( @"CREATE INDEX tblOrders_SalesPersonID ON tblOrders (SalesPersonID)"); CSDatabase.ExecuteNonQuery( @"CREATE TABLE tblPaymentMethods ( PaymentMethodID integer primary key autoincrement, Name text(50) NOT NULL, MonthlyCost integer NOT NULL )"); CSDatabase.ExecuteNonQuery( @"CREATE TABLE tblSalesPeople ( SalesPersonID integer primary key autoincrement, Name text(50) NOT NULL, SalesPersonType integer NULL) "); CSDatabase.ExecuteNonQuery( @"CREATE TABLE tblCoolData ( CoolDataID text(50) PRIMARY KEY, Name text(50) NULL)"); }); }
public void SetupServer() { string path = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..\\Data\\coolstorage.mdb")); if (File.Exists(path)) { File.Delete(path); } ADOX.CatalogClass cat = new ADOX.CatalogClass(); cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Jet OLEDB:Engine Type=5"); CSConfig.SetDB(new CSDataProviderAccess(path)); CSDatabase.ExecuteNonQuery( "CREATE TABLE tblCustomers (CustomerID COUNTER PRIMARY KEY,Name TEXT(50) NOT NULL)"); CSDatabase.ExecuteNonQuery( @"CREATE INDEX tblCustomers_Name ON tblCustomers (Name)"); CSDatabase.ExecuteNonQuery( @"CREATE TABLE tblCustomerPaymentMethodLinks ( CustomerID integer NOT NULL, PaymentMethodID integer NOT NULL, primary key (CustomerID,PaymentMethodID) )"); CSDatabase.ExecuteNonQuery( @"CREATE TABLE tblOrderItems ( OrderItemID counter PRIMARY KEY, OrderID integer NOT NULL, Qty integer NOT NULL, Price double NOT NULL, Description TEXT(200) NOT NULL ) "); CSDatabase.ExecuteNonQuery( @"CREATE INDEX tblOrderItems_OrderID ON tblOrderItems (OrderID)"); CSDatabase.ExecuteNonQuery( @"CREATE TABLE tblOrders ( OrderID counter PRIMARY KEY, [Date] datetime NOT NULL DEFAULT DATE()+TIME(), CustomerID integer NOT NULL, SalesPersonID integer NULL, DataState text(50))"); CSDatabase.ExecuteNonQuery( @"CREATE INDEX tblOrders_CustomerID ON tblOrders (CustomerID)"); CSDatabase.ExecuteNonQuery( @"CREATE INDEX tblOrders_SalesPersonID ON tblOrders (SalesPersonID)"); CSDatabase.ExecuteNonQuery( @"CREATE TABLE tblPaymentMethods ( PaymentMethodID counter primary key, Name text(50) NOT NULL, MonthlyCost integer NOT NULL )"); CSDatabase.ExecuteNonQuery( @"CREATE TABLE tblSalesPeople ( SalesPersonID counter primary key, Name text(50) NOT NULL, SalesPersonType integer NULL) "); CSDatabase.ExecuteNonQuery( @"CREATE TABLE tblCoolData ( CoolDataID guid NOT NULL PRIMARY KEY, Name text(50) NULL)"); CSDatabase.ExecuteNonQuery( @"CREATE TABLE tblColdData (Name text(50) NULL)"); cat.let_ActiveConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path); ADOX.Column column = new ADOX.Column(); column.Name = "ColdDataID"; column.Type = ADOX.DataTypeEnum.adGUID; column.ParentCatalog = cat; column.Properties["AutoIncrement"].Value = false; column.Properties["Fixed Length"].Value = true; column.Properties["Jet OLEDB:AutoGenerate"].Value = true; column.Properties["Jet OLEDB:Allow Zero Length"].Value = true; cat.Tables["tblColdData"].Columns.Append(column, ADOX.DataTypeEnum.adGUID, 0); CSDatabase.ExecuteNonQuery("ALTER TABLE tblColdData ADD CONSTRAINT PK_COLD_DATA PRIMARY KEY (ColdDataID)"); }