Example #1
0
        public void Open(string connStr, string providerName = null, string dbType = null)
        {
            if (providerName == null || providerName.Length == 0)
            {
                providerName = "System.Data.Odbc";
            }

            if (dbType == null)
            {
                if (providerName == "System.Data.SqlClient")
                {
                    dbType = "mssql";
                }
                else if (providerName == "System.Data.Odbc")
                {
                    var m = Regex.Match(connStr, @"DRIVER=(.*?);", RegexOptions.IgnoreCase);
                    if (m.Success)
                    {
                        string driver = m.Groups[1].Value;
                        if (driver.IndexOf("SQL Server", StringComparison.CurrentCultureIgnoreCase) >= 0)
                        {
                            dbType = "mssql";
                        }
                    }
                }
                if (dbType == null)
                {
                    dbType = "mysql";
                }
            }
            this.DbType = dbType;

            Provider = DbProviderFactories.GetFactory(providerName);

            if (dbType == "mssql")
            {
                m_dbStrategy = new MsSQLStrategy();
            }
            else
            {
                m_dbStrategy = new MySQLStrategy();
            }
            m_dbStrategy.init(this);

            m_conn = Provider.CreateConnection();
            this.ConnectionString = connStr;
            this.Open();
        }
Example #2
0
 public DbManager(IDbStrategy database, DbConnection connection, GenTablesOptions options)
 {
     this.Database    = database;
     this._connection = connection;
     this._options    = options;
 }
Example #3
0
 public DbContext SetStrategy(IDbStrategy dbStrategy)
 {
     _dbStrategy = dbStrategy;
     return(this);
 }