private DatabaseTable LoadCountryFromSakila() { if (_categoriesTable != null) return _categoriesTable; ProviderChecker.Check(ProviderName, _connectionString); var dbReader = new DatabaseReader(_connectionString, ProviderName); dbReader.DataTypes(); //ensure we have datatypes (this doesn't hit the database) _categoriesTable = dbReader.Table("country"); //this hits database for columns and constraints return _categoriesTable; }
private DatabaseTable LoadTable() { if (_table != null) return _table; ProviderChecker.Check(ProviderName, ConnectionString); var dbReader = new DatabaseReader(ConnectionString, ProviderName); dbReader.DataTypes(); //ensure we have datatypes (this doesn't hit the database) _table = dbReader.Table("STAFF"); //this hits database for columns and constraints return _table; }
private DatabaseTable LoadRegionsFromHr() { if (_regionsTable != null) return _regionsTable; ProviderChecker.Check(ProviderName, ConnectionString); var dbReader = new DatabaseReader(ConnectionString, ProviderName); dbReader.Owner = "HR"; dbReader.DataTypes(); //ensure we have datatypes (this doesn't hit the database) _regionsTable = dbReader.Table("REGIONS"); //this hits database for columns and constraints return _regionsTable; }
private DatabaseTable LoadTable() { if (_table != null) return _table; ProviderChecker.Check(ProviderName, _connectionString); var dbReader = new DatabaseReader(_connectionString, ProviderName); dbReader.Owner = "public"; //otherwise you have "postgres" owned tables and views dbReader.DataTypes(); //ensure we have datatypes (this doesn't hit the database) _table = dbReader.Table("country"); //this hits database for columns and constraints return _table; }
private DatabaseTable LoadCategoriesFromNorthwind() { if (_categoriesTable != null) return _categoriesTable; if (!File.Exists(_databaseFile)) Assert.Inconclusive("SQLite database file not found: " + _databaseFile); ProviderChecker.Check(ProviderName, _connectionString); var dbReader = new DatabaseReader(_connectionString, ProviderName); dbReader.DataTypes(); //ensure we have datatypes (this doesn't hit the database) _categoriesTable = dbReader.Table("Categories"); //this hits database for columns and constraints if (_categoriesTable == null) Assert.Inconclusive("Could not load Categories table from SQLite file"); return _categoriesTable; }
private DatabaseTable LoadCategoriesFromNorthwind() { if (_categoriesTable != null) return _categoriesTable; if (!File.Exists(FilePath)) { Assert.Inconclusive("Cannot test SqlServerCe.4.0 as no database file " + FilePath); } _connectionString = string.Format(CultureInfo.InvariantCulture, "DataSource=\"{0}\";", FilePath); ProviderChecker.Check(ProviderName, _connectionString); var dbReader = new DatabaseReader(_connectionString, ProviderName); dbReader.DataTypes(); //ensure we have datatypes (this doesn't hit the database) _categoriesTable = dbReader.Table("Categories"); //this hits database for columns and constraints return _categoriesTable; }
//[TestMethod] public void TestGeneratedSqlForInsert() { //arrange ProviderChecker.Check(ProviderName, ConnectionString); var dbReader = new DatabaseReader(ConnectionString, ProviderName); dbReader.DataTypes(); //ensure we have datatypes (this doesn't hit the database) var table = dbReader.Table("TABWITHIDENTITY"); //this hits database for columns and constraints var writer = new SqlWriter(table, SqlType.Db2); var sql = writer.InsertSqlWithoutOutputParameter(); Console.WriteLine(sql); int identity; //run generated sql using (var con = _factory.CreateConnection()) { con.ConnectionString = ConnectionString; con.Open(); using (var transaction = con.BeginTransaction()) { using (var cmd = con.CreateCommand()) { cmd.CommandText = sql; cmd.Transaction = transaction; foreach (var column in table.Columns) { if (column.IsAutoNumber) continue; var par = cmd.CreateParameter(); par.ParameterName = writer.ParameterName(column.Name); object value = DummyDataCreator.CreateData(column); par.Value = value ?? DBNull.Value; cmd.Parameters.Add(par); } identity = Convert.ToInt32(cmd.ExecuteScalar()); } //explicit rollback. If we errored, implicit rollback. transaction.Rollback(); } } //assert Assert.AreNotEqual(0, identity); }