Exemplo n.º 1
0
 /// <summary>
 /// Create an instance of the database client for a Sqlite database file.
 /// </summary>
 /// <param name="filename">Sqlite database.</param>
 public DatabaseClient(string filename)
 {
     if (String.IsNullOrEmpty(filename))
     {
         throw new ArgumentNullException(nameof(filename));
     }
     _Settings = new DatabaseSettings(filename);
     _Header   = "[DatabaseWrapper." + _Settings.Type.ToString() + "] ";
     _Sqlite   = new Sqlite.DatabaseClient(filename);
 }
Exemplo n.º 2
0
        /// <summary>
        /// Create an instance of the database client for a Sqlite database file.
        /// </summary>
        /// <param name="filename"></param>
        public DatabaseClient(string filename)
        {
            if (String.IsNullOrEmpty(filename))
            {
                throw new ArgumentNullException(nameof(filename));
            }

            _DbType         = DbTypes.Sqlite;
            _SqliteFilename = filename;
            _Header         = "[DatabaseWrapper." + _DbType.ToString() + "] ";

            _Sqlite = new Sqlite.DatabaseClient(filename);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Create an instance of the database client.
        /// </summary>
        /// <param name="settings">Database settings.</param>
        public DatabaseClient(DatabaseSettings settings)
        {
            _Settings = settings ?? throw new ArgumentNullException(nameof(settings));

            if (_Settings.Type == DbTypes.Sqlite && String.IsNullOrEmpty(_Settings.Filename))
            {
                throw new ArgumentException("Filename must be populated in database settings of type 'Sqlite'.");
            }

            if (_Settings.Type != DbTypes.SqlServer && !String.IsNullOrEmpty(_Settings.Instance))
            {
                throw new ArgumentException("Instance can only be used in database settings of type 'SqlServer'.");
            }

            _Header = "[DatabaseWrapper." + _Settings.Type.ToString() + "] ";

            switch (_Settings.Type)
            {
            case DbTypes.Sqlite:
                _Sqlite = new Sqlite.DatabaseClient(_Settings);
                break;

            case DbTypes.Mysql:
                _Mysql = new Mysql.DatabaseClient(_Settings);
                break;

            case DbTypes.Postgresql:
                _Postgresql = new Postgresql.DatabaseClient(_Settings);
                break;

            case DbTypes.SqlServer:
                _SqlServer = new SqlServer.DatabaseClient(_Settings);
                break;

            default:
                throw new ArgumentException("Unknown database type '" + _Settings.Type.ToString() + "'.");
            }
        }