/// <summary>
        /// Initializes a new instance of the <see cref="InMemorySQLiteDatabase"/> class.
        /// </summary>
        public InMemorySQLiteDatabase()
        {
            var connectionStringBuilder = new SQLiteConnectionStringBuilder
            {
                DataSource = ":memory:",
                Version = 3,
                DefaultTimeout = 5,
            #if MONO
                JournalMode = SQLiteJournalModeEnum.Off,
            #else
                JournalMode = SQLiteJournalModeEnum.Memory,
            #endif
                UseUTF16Encoding = true
            };
            ConnectionString = connectionStringBuilder.ToString();

            connectionManager = new SQLiteConnectionManager(connectionStringBuilder.ConnectionString);
            sharedConnection = new SQLiteConnection(connectionStringBuilder.ConnectionString);
            sharedConnection.Open();
            sqlRunner = new AdHocSqlRunner(() => sharedConnection.CreateCommand(), null, () => true);
        }
Exemple #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="InMemorySQLiteDatabase"/> class.
        /// </summary>
        public InMemorySQLiteDatabase()
        {
            var connectionStringBuilder = new SQLiteConnectionStringBuilder
            {
                DataSource     = ":memory:",
                Version        = 3,
                DefaultTimeout = 5,
#if MONO
                JournalMode = SQLiteJournalModeEnum.Off,
#else
                JournalMode = SQLiteJournalModeEnum.Memory,
#endif
                UseUTF16Encoding = true
            };

            ConnectionString = connectionStringBuilder.ToString();

            connectionManager = new SQLiteConnectionManager(connectionStringBuilder.ConnectionString);
            sharedConnection  = new SQLiteConnection(connectionStringBuilder.ConnectionString);
            sharedConnection.Open();
            sqlRunner = new AdHocSqlRunner(() => sharedConnection.CreateCommand(), null, () => true);
        }
Exemple #3
0
        public static void Setup(bool useLocalFiles)
        {
            DataDirectory = new DirectoryInfo(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Gablarski"));
            if (!DataDirectory.Exists)
            {
                DataDirectory.Create();
            }

            if (useLocalFiles)
            {
                KeyFile = new FileInfo("gablarski.key");
                DbFile  = new FileInfo("gablarski.db");
            }
            else
            {
                KeyFile = new FileInfo(Path.Combine(DataDirectory.FullName, "gablarski.key"));
                DbFile  = new FileInfo(Path.Combine(DataDirectory.FullName, "gablarski.db"));
            }

                        #if !XAMARIN
            var builder = new SQLiteConnectionStringBuilder();
            builder.DataSource = DbFile.FullName;

            db = new SQLiteConnection(builder.ToString());
                        #else
            KeyFile = new FileInfo(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), KeyFile.Name));
            DbFile  = new FileInfo(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), DbFile.Name));
            if (!DbFile.Exists)
            {
                SQLiteConnection.CreateFile(DbFile.FullName);
            }

            db = new SQLiteConnection("Data Source=" + DbFile.FullName);
                        #endif
            db.Open();

            CreateDbs();
        }
Exemple #4
0
        public void Open(string absoluteFilePath)
        {
            try
            {
                ConnectionStringBuilder connstr = new ConnectionStringBuilder();
                connstr.DataSource = absoluteFilePath;
                conn = new Connection();
                conn.ConnectionString = connstr.ToString();
                conn.Open();

                cmdCommand = new Command(
                    "SELECT [Command] FROM [Command] WHERE [Name]=:name AND [Class]=:class",
                    conn);
                cmdCommand.Parameters.Add(":name", DbType.Binary);
                cmdCommand.Parameters.Add(":class", DbType.Binary);

                textCommand = new Command(
                    "SELECT [Content] FROM [Text] WHERE [Name]=:name AND [Language]=:language AND [Class]=:class",
                    conn);
                textCommand.Parameters.Add(":name", DbType.Binary);
                textCommand.Parameters.Add(":language", DbType.Binary);
                textCommand.Parameters.Add(":class", DbType.Binary);

                troubleCodeCommand = new Command(
                    "SELECT [Content], [Description] FROM [TroubleCode] WHERE [Code]=:code AND [Language]=:language AND [Class]=:class",
                    conn);
                troubleCodeCommand.Parameters.Add(":code", DbType.Binary);
                troubleCodeCommand.Parameters.Add(":language", DbType.Binary);
                troubleCodeCommand.Parameters.Add(":class", DbType.Binary);

                liveDataCommand = new Command(
                    "SELECT [ShortName], [Content], [Unit], [DefaultValue], [CommandName], [CommandClass], [Description], [Index] FROM [LiveData] WHERE [Language]=:language AND [Class]=:class",
                    conn);
                liveDataCommand.Parameters.Add(":language", DbType.Binary);
                liveDataCommand.Parameters.Add(":class", DbType.Binary);
            }
            catch (Exception ex)
            {
                Close();
                throw new DatabaseException(
                    String.Format("Cannot open vehicle database! file path = \"{0}\", error message: {1}",
                        absoluteFilePath, ex.Message));
            }
        }