public BaseRepositorio(string stringConnection) { DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.SqlClient"); var database = new GenericDatabase(stringConnection, factory); DataContext = new DataContext(database); }
public void EnumParsedToString() { var dataApiClient = new Mock <IDataApiClient>(); string actualQuery = null; dataApiClient .Setup(x => x.SearchAsync(It.IsAny <string>(), ResultFormat.Json)) .Callback <string, ResultFormat>((query, format) => actualQuery = query) .Returns(Task.FromResult(Stream.Null)); var sut = new GenericDatabase <ClassWithEnum>(dataApiClient.Object); // Test 1 sut.Where(x => x.Role == Role.Analyst).ToList(); Assert.That(actualQuery, Is.EqualTo("FROM ClassWithEnum WHERE Data.Role = 'Analyst'")); // Test 2 sut.Where(x => x.Role.InSet(Role.Viewer, Role.DataProducer)).ToList(); Assert.That(actualQuery, Is.EqualTo("FROM ClassWithEnum WHERE Data.Role IN ['Viewer', 'DataProducer']")); // Test 3 var test3Roles = new[] { Role.UserManager, Role.Analyst }; sut.Where(x => test3Roles.Contains(x.Role)).ToList(); Assert.That(actualQuery, Is.EqualTo("FROM ClassWithEnum WHERE Data.Role IN ['UserManager', 'Analyst']")); }
public void GenericDatabaseThrowsWhenAskedToDeriveParameters() { Database db = new GenericDatabase(String.Format(@"server={0};database=Northwind;Integrated Security=true", ConfigurationManager.AppSettings["SqlServerDatabaseInstance"]), SqlClientFactory.Instance); DbCommand storedProcedure = db.GetStoredProcCommand("CustOrdersOrders"); db.DiscoverParameters(storedProcedure); }
public void GenericDatabaseThrowsWhenAskedToDeriveParameters() { Database db = new GenericDatabase(@"server=(localdb)\v11.0;database=Northwind;Integrated Security=true", SqlClientFactory.Instance); DbCommand storedProcedure = db.GetStoredProcCommand("CustOrdersOrders"); db.DiscoverParameters(storedProcedure); }
private void _generateGrid(ref int line, GenericDatabase database, TabControl control, DisplayableProperty <TKey, ReadableTuple <TKey> > generalProperties, BaseDb gdb) { if (gdb.LayoutIndexes != null) { AbstractProvider metaProvider = AbstractProvider.GetProvider(gdb.LayoutIndexes); if (metaProvider is GroupIndexProvider) { AbstractProvider gridProvider = AbstractProvider.GetProvider(gdb.GridIndexes); gridProvider.GroupAs = typeof(SpecifiedIndexProvider); bool col = false; foreach (IIndexProvider provider in metaProvider.Providers) { AbstractProvider gridLayout = gridProvider.Next <AbstractProvider>(); GTabsMaker.PrintGrid(ref line, (col = !col) ? 0 : 3, 1, 2, provider, gridLayout, generalProperties, gdb.AttributeList); if (col) { line--; } } } else { GTabsMaker.Print(ref line, metaProvider, generalProperties, gdb.AttributeList); } } else { GTabsMaker.Print(ref line, new SpecifiedRangeIndexProvider(new int[] { 0, gdb.AttributeList.Attributes.Count }), generalProperties, gdb.AttributeList); } }
/// <summary> /// 构造 Database 对象 /// </summary> /// <returns></returns> public static Database CreateDatabaseStaffing() { ConnectionStringSettings _connectSettingStaffing; string strConnectString = string.Empty; string strProviderName = string.Empty; Database db = null; try { //if (_connectSetting == null) //{ // _connectSetting = ConfigurationManager.ConnectionStrings[ConnectionControl.StaffingConnectionstring]; // _connectString = _connectSetting.ConnectionString; // _providerName = _connectSetting.ProviderName; //} _connectSettingStaffing = ConfigurationManager.ConnectionStrings[ConnectionControl.StaffingConnectionstring]; strConnectString = _connectSettingStaffing.ConnectionString; strProviderName = _connectSettingStaffing.ProviderName; // 构造连接对象 GenericDatabase dbSqlServer = new GenericDatabase(strConnectString, DbProviderFactories.GetFactory(strProviderName)); db = dbSqlServer; } catch (Exception ex) { LogManager.GetInstance().ErrorLog(ex.Message, ex); } return(db); }
public DropEdit(string id, string dropChance, ServerDbs sdb, GenericDatabase gdb) : base("Item edit", "cde.ico", SizeToContent.Height, ResizeMode.NoResize) { _id = id; _dropChance = dropChance; _sdb = sdb; _gdb = gdb; InitializeComponent(); _tbChance.Text = _dropChance; _tbId.Text = _id; PreviewKeyDown += new KeyEventHandler(_dropEdit_PreviewKeyDown); Loaded += delegate { _tbChance.SelectAll(); _tbChance.Focus(); }; if (sdb != null) { _buttonQuery.Click += new RoutedEventHandler(_buttonQuery_Click); } else { _buttonQuery.Visibility = Visibility.Collapsed; } }
public virtual void Instantiate(GenericDatabase database) { Database = database; _dbs.Add(new DbClientResource()); _dbs.Add(new DbItems()); _dbs.Add(new DbItems2()); _dbs.Add(new DbItemCombos()); _dbs.Add(new DbItemGroups()); _dbs.Add(new DbSkills()); _dbs.Add(new DbSkillRequirements()); _dbs.Add(new DbMobs()); _dbs.Add(new DbMobs2()); _dbs.Add(new DbMobSkills()); _dbs.Add(new DbMobSkills2()); _dbs.Add(new DbMobBoss()); _dbs.Add(new DbMobBranch()); _dbs.Add(new DbMobPoring()); _dbs.Add(new DbMobPouch()); _dbs.Add(new DbMobClasschange()); _dbs.Add(new DbHomuns()); _dbs.Add(new DbPet()); _dbs.Add(new DbPet2()); _dbs.Add(new DbCastle()); _dbs.Add(new DbConstants()); _dbs.ForEach(p => p.Holder = this); _dbs.ForEach(p => p.Init(database)); }
public virtual void Instantiate(GenericDatabase database) { Database = database; _dbs.Add(new DbClientResource()); _dbs.Add(new DbItems()); _dbs.Add(new DbItems2()); _dbs.Add(new DbItemCombos()); _dbs.Add(new DbItemGroups()); _dbs.Add(new DbSkills()); _dbs.Add(new DbSkillRequirements()); _dbs.Add(new DbMobs()); _dbs.Add(new DbMobs2()); _dbs.Add(new DbMobSkills()); _dbs.Add(new DbMobSkills2()); _dbs.Add(new DbMobBoss()); _dbs.Add(new DbMobBranch()); _dbs.Add(new DbMobPoring()); _dbs.Add(new DbMobPouch()); _dbs.Add(new DbMobClasschange()); _dbs.Add(new DbHomuns()); _dbs.Add(new DbPet()); _dbs.Add(new DbPet2()); _dbs.Add(new DbCastle()); _dbs.Add(new DbConstants()); _dbs.ForEach(p => p.Holder = this); _dbs.ForEach(p => p.Init(database)); }
public static int TExecuteNonQuery(string sqlCommand, IDataParameter[] parameters, DbTransaction transaction) { int affectRows = 0; DbCommand dbCommand = DbProviderFactory.CreateCommand(); dbCommand.CommandText = sqlCommand; if (parameters != null) { dbCommand.Parameters.AddRange(parameters); } GenericDatabase db = new GenericDatabase(ConnectionString, OdbcFactory.Instance); //if (parameters != null) //{ // foreach (SqlParameter parm in parameters) // { // dbCommand.Parameters.Add(parm); // } //} if (transaction != null) { affectRows = db.ExecuteNonQuery(dbCommand, transaction); } else { affectRows = db.ExecuteNonQuery(dbCommand); } return(affectRows); }
public static Status Submit(int id, string leadin, string count, string newsitems, string highlightitems) { Status stat = new Status(); GenericDatabase db = new GenericDatabase(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString, DbProviderFactories.GetFactory("MySql.Data.MySqlClient")); DbCommand cmd = db.GetStoredProcCommand("ins_media"); DateTime dte = DateTime.Now; string name = ""; name = "BOD_News_" + GetWeekNumber(dte).ToString() + "_" + id.ToString() + "_" + dte.Year.ToString(); db.AddOutParameter(cmd, "ReturnCode", DbType.Int32, 8); db.AddOutParameter(cmd, "ErrorMessage", DbType.String, 500); db.AddOutParameter(cmd, "NewID", DbType.Int32, 8); db.AddInParameter(cmd, "InID", DbType.Int32, id); db.AddInParameter(cmd, "InName", DbType.String, name); db.AddInParameter(cmd, "InLeadin", DbType.String, leadin); db.AddInParameter(cmd, "InCount", DbType.String, count); db.AddInParameter(cmd, "InNewsItems", DbType.String, newsitems); db.AddInParameter(cmd, "InHighlightItems", DbType.String, highlightitems); db.ExecuteNonQuery(cmd); stat.ReturnCode = db.GetParameterValue(cmd, "ReturnCode") != null ? (Int32)db.GetParameterValue(cmd, "ReturnCode") : 0; stat.ErrorMessage = name + ".html"; stat.NewID = db.GetParameterValue(cmd, "NewID") != null?db.GetParameterValue(cmd, "NewID").ToString() : "0"; Entry item = new Entry(); item.Name = name; item.LeadIn = leadin; item.NewItems = newsitems; item.HighlightItems = highlightitems; item.Count = count; CreateHTML(item); return(stat); }
public DropEdit(string id, string dropChance, ServerDbs sdb, GenericDatabase gdb) : base("Item edit", "cde.ico", SizeToContent.Height, ResizeMode.NoResize) { _id = id; _dropChance = dropChance; _sdb = sdb; _gdb = gdb; InitializeComponent(); _tbChance.Text = _dropChance; _tbId.Text = _id; PreviewKeyDown += new KeyEventHandler(_dropEdit_PreviewKeyDown); Loaded += delegate { _tbChance.SelectAll(); _tbChance.Focus(); }; if (sdb != null) { _buttonQuery.Click += new RoutedEventHandler(_buttonQuery_Click); } else { _buttonQuery.Visibility = Visibility.Collapsed; } }
public static Database CreateDatabase(string connectionString, string providerType) { if (string.Compare(DefaultSqlProviderName, providerType, true) == 0) { return(new SqlDatabase(connectionString)); } else if (string.Compare(DefaultOracleProviderName, providerType, true) == 0) { return(new OracleDatabase(connectionString)); } else { Type type = ActivatorEx.GetType(providerType); if (type != null) { Database result = null; if (type.IsSubclassOf(typeof(Database))) { result = ActivatorEx.CreateInstance(type, new Type[] { typeof(string) }, new object[] { connectionString }) as Database; } else { DbProviderFactory fac = ActivatorEx.CreateInstance(providerType) as DbProviderFactory; if (fac != null) { result = new GenericDatabase(connectionString, fac); } } return(result); } } return(null); }
public void SupportsNinjaNyeSearch() { var searchText = "arla hp"; var searchTerms = searchText.Split(); var resultStream = new MemoryStream(Encoding.UTF8.GetBytes( "{\"Data\": { \"id\": \"1179240\", \"source_id\": \"84\", \"business_name\": \"Letmælk\", \"source_system\": \"SQL\", \"source_table\": \"ingredients_dbo_Ingredient\", \"component_type\": \"Ingredient\", \"created_on\": \"1/13/2017 9:58:45 AM\", \"created_by\": \"JDOE\", \"updated_on\": null, \"updated_by\": null, \"is_deleted\": \"False\"} }" )); var dataApiClient = new Mock <IDataApiClient>(); dataApiClient.Setup(x => x.SearchAsync(It.IsAny <string>(), ResultFormat.Json)) .Returns(Task.FromResult((Stream)resultStream)); var queryable = new GenericDatabase <TestObject1>(dataApiClient.Object); var filter = "MDS"; var sourceSystem = filter != "all" ? filter : null; var searchResult = queryable .Where(x => sourceSystem != null ? x.SourceSystem == filter : x.SourceSystem != "MDS") .Search(x => x.Name, x => x.SourceId) .ContainingAll(searchTerms) .OrderBy(x => x.Name) .ThenByDescending(x => x.CreatedBy) .Select(x => x.Id) .ToList(); Assert.That(searchResult.Count, Is.EqualTo(1)); Assert.That(searchResult[0], Is.EqualTo("1179240")); }
/// <summary> /// Instância básica para DatabaseStructureCoreDAO. /// </summary> public DatabaseStructureCoreDAO() { assembly = Assembly.Load("MechTech.Util"); classe = assembly.GetType("MechTech.Util.Global"); propriedade = classe.GetProperty("ConnectionStringPg"); db = new GenericDatabase(propriedade.GetValue(null, null).ToString(), PgSqlProviderFactory.Instance); }
public static Database Conn() { //string ConnString = ConfigurationManager.ConnectionStrings["LocalDatabase"].ToString(); //string ConnString = decodeSTROnUrl(ConfigurationManager.ConnectionStrings["LocalDatabase"].ToString()); //ConnString = CryptoGraphy.Decrypt(ConfigurationManager.ConnectionStrings["LocalDatabase"].ToString()); Database db = new GenericDatabase(CryptoGraphy.Decrypt(ConfigurationManager.ConnectionStrings["LocalDatabase"].ToString()), DbProviderFactories.GetFactory(DecryptConnection.Provider)); return(db); }
public sealed override void Init(GenericDatabase database) { if (Table == null) { Table = new Table <TKey, ReadableTuple <TKey> >(AttributeList, UnsafeContext); } Database = database; database.AddDb(DbSource, this); }
public GDbTab GenerateTab(GenericDatabase database, TabControl control, BaseDb baseDb) { #if SDE_DEBUG CLHelper.WA = "_CPTAB loading " + baseDb.DbSource.Filename; var tab = GDbTabMaker(database, control, baseDb); CLHelper.WL = ", generating time : _CS_CDms"; return(tab); #else return(GDbTabMaker(database, control, baseDb)); #endif }
public void CanCreateGenericDatabaseFromFactory() { var factory = new DatabaseProviderFactory(new SystemConfigurationSource(false).GetSection); GenericDatabase createdObject = (GenericDatabase)factory.Create("OdbcDatabase"); Assert.IsNotNull(createdObject); Assert.AreEqual(@"some connection string;", createdObject.ConnectionStringWithoutCredentials); Assert.AreEqual(DbProviderFactories.GetFactory("System.Data.Odbc"), createdObject.DbProviderFactory); }
public void QueryableIntegrationTest() { var ids = new List <string> { "1228357", "1228358" }; var dataApiClient = new DataApiClient(new ApiConfiguration("", 443)); var queryable = new GenericDatabase <TestObject1>(dataApiClient); var searchResult = queryable.Where(x => ids.Contains(x.Id)).ToList(); Assert.That(searchResult, Is.Not.Null); CollectionAssert.AreEqual(ids, searchResult.Select(x => x.Id)); }
public DataProjectViewModel( DataProject dataProject, IDataApiClient dataApiClient, IClipboard clipboard) { this.dataApiClient = dataApiClient; this.clipboard = clipboard; Model = dataProject; var projectDatabase = new GenericDatabase <DataProject>(dataApiClient); ParameterResponsesViewModel = new ProjectParameterResponsesViewModel(dataApiClient, projectDatabase, dataProject); }
public async Task PermanentFilterIsAppliedForTypelessRepository() { string actual = null; dataApiClient.Setup(x => x.GetManyAsync("TestObject1", It.IsAny <string>(), null, null)) .Callback <string, string, string, uint?>((dataType, whereArguments, orderByArguments, limit) => actual = whereArguments) .ReturnsAsync(new List <string>()); var sut = new GenericDatabase(dataApiClient.Object, "TestObject1", "Data.source_system = 'XY'"); await sut.GetManyAsync("Data.source_id LIKE 'abc%'"); Assert.That(actual, Is.EqualTo("Data.source_system = 'XY' AND (Data.source_id LIKE 'abc%')")); }
public void CanCreateGenericDatabaseFromContainer() { IUnityContainer container = new UnityContainer(); container.AddExtension(new EnterpriseLibraryCoreExtension()); container.AddNewExtension <DataAccessBlockExtension>(); GenericDatabase createdObject = container.Resolve <GenericDatabase>("OdbcDatabase"); Assert.IsNotNull(createdObject); Assert.AreEqual(@"some connection string;", createdObject.ConnectionStringWithoutCredentials); Assert.AreEqual(DbProviderFactories.GetFactory("System.Data.Odbc"), createdObject.DbProviderFactory); }
public async Task GetManyStringWhereClauseIsUsed() { const string WhereClause = "Data.source_id LIKE 'abc%'"; string actual = null; dataApiClient.Setup(x => x.GetManyAsync <TestObject1>(It.IsAny <string>(), null, null)) .Callback <string, string, uint?>((whereArguments, orderByArguments, limit) => actual = whereArguments) .ReturnsAsync(new List <TestObject1>()); var sut = new GenericDatabase <TestObject1>(dataApiClient.Object); await sut.GetManyAsync(WhereClause); Assert.That(actual, Is.EqualTo(WhereClause)); }
public async Task GetManyFilterExpressionIsUsed() { const string Expected = "Data.source_id LIKE 'abc%'"; string actual = null; dataApiClient.Setup(x => x.GetManyAsync <TestObject1>(It.IsAny <string>(), null, null)) .Callback <string, string, uint?>((whereArguments, orderByArguments, limit) => actual = whereArguments) .ReturnsAsync(new List <TestObject1>()); var sut = new GenericDatabase <TestObject1>(dataApiClient.Object); await sut.GetManyAsync(x => x.SourceId.StartsWith("abc")); Assert.That(actual, Is.EqualTo(Expected)); }
/// <summary> /// 获取数据库链接 /// </summary> /// <returns></returns> public static Database CreateDataBase() { var dataBase = XmlHepler.xmlload("DataBase"); var dburl = XmlHepler.xmlload(dataBase); Database dbbase = null; Database db = DatabaseFactory.CreateDatabase(); DbConnectionStringBuilder dbsb = db.DbProviderFactory.CreateConnectionStringBuilder(); dbsb.ConnectionString = dburl; GenericDatabase loadDb = new GenericDatabase(dbsb.ToString(), db.DbProviderFactory); dbbase = loadDb; return(dbbase); }
public Database Conexion(String pConnectionString, String pServidor, String pBaseDatos, String pNombreUsuario, String pClave) { Database lconfig_db = DatabaseFactory.CreateDatabase(pConnectionString); DbConnectionStringBuilder lsb = lconfig_db.DbProviderFactory.CreateConnectionStringBuilder(); lsb["Data Source"] = pServidor; lsb["Initial Catalog"] = pBaseDatos; lsb["User ID"] = pNombreUsuario; lsb["Password"] = pClave; GenericDatabase newDb = new GenericDatabase(lsb.ToString(), lconfig_db.DbProviderFactory); Database ldb_Conexion = newDb; return(ldb_Conexion); }
public void CanDoExecuteDataReaderForGenericDatabaseForSqlProviderBug1836() { Database db = new GenericDatabase(@"server=(local)\SQLEXPRESS;database=Northwind;Integrated Security=true", SqlClientFactory.Instance); using (DbConnection connection = db.CreateConnection()) { connection.Open(); using (DbTransaction transaction = connection.BeginTransaction()) { using (IDataReader dataReader = db.ExecuteReader(transaction, CommandType.Text, "select * from [Order Details]")) {} transaction.Commit(); } } }
public void CanDoExecuteDataReaderForGenericDatabaseBug1836() { Database db = new GenericDatabase(@"Driver={Microsoft Access Driver (*.mdb)};Dbq=northwind.mdb;Uid=sa;Pwd=sa;", OdbcFactory.Instance); using (DbConnection connection = db.CreateConnection()) { connection.Open(); using (DbTransaction transaction = connection.BeginTransaction()) { using (IDataReader dataReader = db.ExecuteReader(transaction, CommandType.Text, "select * from [Order Details]")) {} transaction.Commit(); } } }
public void CanDoExecuteDataReaderForGenericDatabaseBug1836() { Database db = new GenericDatabase(@"Driver={Microsoft Access Driver (*.mdb)};Dbq=northwind.mdb;Uid=sa;Pwd=sa;", OdbcFactory.Instance); using (DbConnection connection = db.CreateConnection()) { connection.Open(); using (DbTransaction transaction = connection.BeginTransaction()) { using (IDataReader dataReader = db.ExecuteReader(transaction, CommandType.Text, "select * from [Order Details]")) { } transaction.Commit(); } } }
public void CanDoExecuteDataReaderForGenericDatabaseForSqlProviderBug1836() { Database db = new GenericDatabase(@"server=(localdb)\v11.0;database=Northwind;Integrated Security=true", SqlClientFactory.Instance); using (DbConnection connection = db.CreateConnection()) { connection.Open(); using (DbTransaction transaction = connection.BeginTransaction()) { using (IDataReader dataReader = db.ExecuteReader(transaction, CommandType.Text, "select * from [Order Details]")) { } transaction.Commit(); } } }
public void CanDoExecuteDataReaderForGenericDatabaseForSqlProviderBug1836() { Database db = new GenericDatabase(String.Format(@"server={0};database=Northwind;Integrated Security=true", ConfigurationManager.AppSettings["SqlServerDatabaseInstance"]), SqlClientFactory.Instance); using (DbConnection connection = db.CreateConnection()) { connection.Open(); using (DbTransaction transaction = connection.BeginTransaction()) { using (IDataReader dataReader = db.ExecuteReader(transaction, CommandType.Text, "select * from [Order Details]")) { } transaction.Commit(); } } }
public void DSDBWrapperTransSqlNoCommitTestBug1857() { Database db = new GenericDatabase(@"server=(local)\SQLEXPRESS;database=Northwind;Integrated Security=true", SqlClientFactory.Instance); using (DbConnection connection = db.CreateConnection()) { connection.Open(); using (DbTransaction transaction = connection.BeginTransaction()) { string sqlCommand = "select * from [Order Details]"; DbCommand dbCommand = db.GetSqlStringCommand(sqlCommand); DataSet dsActualResult = db.ExecuteDataSet(dbCommand, transaction); } } }
public override void Redo() { if (Database is GenericDatabase) { GenericDatabase gDb = (GenericDatabase)Database; gDb.Commands.Redo(); } else { if (Table.Commands.CanRedo) { Table.Commands.Redo(); } } }
public void DSDBWrapperTransSqlNoCommitTestBug1857() { Database db = new GenericDatabase(@"server=(localdb)\v11.0;database=Northwind;Integrated Security=true", SqlClientFactory.Instance); using (DbConnection connection = db.CreateConnection()) { connection.Open(); using (DbTransaction transaction = connection.BeginTransaction()) { string sqlCommand = "select * from [Order Details]"; DbCommand dbCommand = db.GetSqlStringCommand(sqlCommand); DataSet dsActualResult = db.ExecuteDataSet(dbCommand, transaction); } } }
public void GenericDatabaseThrowsWhenAskedToDeriveParameters() { Database db = new GenericDatabase(@"server=(local)\SQLEXPRESS;database=Northwind;Integrated Security=true", SqlClientFactory.Instance); DbCommand storedProcedure = db.GetStoredProcCommand("CustOrdersOrders"); db.DiscoverParameters(storedProcedure); }