Пример #1
0
        public void CreateSchema()
        {
            // Create a new DB connection.
            using (var connection = (SQLiteConnection)_connectionFactory.CreateConnection())
            {
                if (connection == null)
                {
                    return;
                }

                // Open the DB connection.
                connection.ConnectionString = ConnectionString;
                connection.Open();

                // Execute SQL commands.
                using (var command = new SQLiteCommand(connection))
                {
                    command.CommandText =
                        @"CREATE TABLE [Customer] 
                    (
                        [Id] INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
                        [FirstName] NVARCHAR(40) NOT NULL,
                        [LastName] NVARCHAR(20) NOT NULL,
                        [Address] NVARCHAR(1024) NOT NULL,
                        [Email] NVARCHAR(60) NOT NULL,
                        [Phone] NVARCHAR(24) NOT NULL
                    );";
                    command.CommandType = CommandType.Text;
                    command.ExecuteNonQuery();
                }
            }
        }
Пример #2
0
        public DataTable ExecuteQuery(string sqlQuery)
        {
            var table = new DataTable();

            // Create a new DB connection.
            using (var connection = (SQLiteConnection)_connectionFactory.CreateConnection())
            {
                if (connection == null)
                {
                    return(table);
                }

                // Open the DB connection.
                connection.ConnectionString = ConnectionString;
                connection.Open();

                // Execute SQL command.
                using (var command = new SQLiteCommand(connection))
                {
                    command.CommandText = sqlQuery;
                    using (var reader = command.ExecuteReader())
                    {
                        table.Load(reader);
                    }
                }
            }

            return(table);
        }
Пример #3
0
        //create database with profiles (if not exixsts) and open window to create profile
        private void button_create_profile_Click(object sender, EventArgs e)
        {
            if (!File.Exists(db_name))
            {
                SQLiteConnection.CreateFile(db_name);
                SQLiteFactory factory = (SQLiteFactory)DbProviderFactories.GetFactory("System.Data.SQLite");

                using (SQLiteConnection connection = (SQLiteConnection)factory.CreateConnection())
                {
                    connection.ConnectionString = "Data Source = " + db_name;
                    connection.Open();

                    using (SQLiteCommand command = new SQLiteCommand(connection))
                    {
                        command.CommandText = "CREATE TABLE IF NOT EXISTS [profiles] (" +
                                              "[id] INTEGER PRIMARY KEY AUTOINCREMENT," +
                                              "[login] TEXT," +
                                              "[password] TEXT" +
                                              ")";

                        command.CommandType = CommandType.Text;
                        command.ExecuteNonQuery();
                    }
                    connection.Close();
                }
            }

            //open window to create new profile
            Form_Creare_Profile new_form = new Form_Creare_Profile();

            new_form.ShowDialog();
        }
Пример #4
0
        public static List <String> Number()
        {
            List <string> IDs = new List <string>();

            try
            {
                factory    = (SQLiteFactory)DbProviderFactories.GetFactory("System.Data.SQLite");
                connection = (SQLiteConnection)factory.CreateConnection();

                connection.ConnectionString = "Data Source = " + path_config;
                connection.Open();
                SQLiteCommand command = new SQLiteCommand(connection);

                command.CommandText = @"SELECT  * FROM Accounts";
                command.CommandType = CommandType.Text;
                command.ExecuteNonQuery();

                sql.SelectCommand = command;
                sql.Fill(dt);

                bs.DataSource = dt;
                var ID = dt.Columns["ID"];

                foreach (DataRow dr in dt.Rows)
                {
                    IDs.Add(dr[ID].ToString());
                }

                connection.Close();
            }
            catch { }
            return(IDs);
        }
Пример #5
0
        public static List <String> TimeStamps()
        //Создает лист TimeStamps, содержащий время отправки и получения сообщений в unix времени
        // Встроен конвертер unixtime в обычное время
        {
            List <string> TimeStamps = new List <string>();

            try
            {
                DataTable dt = new DataTable();
                factory    = (SQLiteFactory)DbProviderFactories.GetFactory("System.Data.SQLite");
                connection = (SQLiteConnection)factory.CreateConnection();

                connection.ConnectionString = "Data Source = " + path_config;
                connection.Open();
                SQLiteCommand command = new SQLiteCommand(connection);

                command.CommandText = @"SELECT * FROM MessageInfo ORDER BY TimeStamp";
                command.CommandType = CommandType.Text;
                command.ExecuteNonQuery();

                sql.SelectCommand = command;
                sql.Fill(dt);

                bs.DataSource = dt;
                var TimeStamp = dt.Columns["TimeStamp"];
                foreach (DataRow dr in dt.Rows)
                {
                    TimeStamps.Add(dr[TimeStamp].ToString());
                }
                connection.Close();
            }
            catch { }
            return(TimeStamps);
        }
Пример #6
0
        protected virtual void InitializeAndBuildTable()
        {
            if (File.Exists(FileName))
            {
                File.Delete(FileName);
            }

            DbProviderFactory fact = new SQLiteFactory();

            m_dbConnection = fact.CreateConnection();

            if (m_dbConnection == null)
            {
                return;
            }

            m_dbConnection.ConnectionString = "Data Source=" + FileName;

            try
            {
                m_dbConnection.Open();
            }
            catch (Exception ex)
            {
                Logger.Instance.AddEntry("SQLitePeakListExporter failed. Details: " + ex.Message, true);
                throw;
            }

            BuildTable();
        }
Пример #7
0
        public static List <String> IdMes()
        //создает лист c информацией о сообщении
        {
            List <string> IdMes = new List <string>();

            try
            {
                DataTable dt = new DataTable();
                factory    = (SQLiteFactory)DbProviderFactories.GetFactory("System.Data.SQLite");
                connection = (SQLiteConnection)factory.CreateConnection();

                connection.ConnectionString = "Data Source = " + path_config;
                connection.Open();
                SQLiteCommand command = new SQLiteCommand(connection);

                command.CommandText = @"SELECT * FROM MessageInfo ORDER BY TimeStamp";
                command.CommandType = CommandType.Text;
                command.ExecuteNonQuery();

                sql.SelectCommand = command;
                sql.Fill(dt);

                bs.DataSource = dt;
                var type = dt.Columns["EventID"];
                foreach (DataRow dr in dt.Rows)
                {
                    IdMes.Add(dr[type].ToString());
                }

                connection.Close();
            }
            catch { }
            return(IdMes);
        }
Пример #8
0
        public static long LastMessageTime()
        //создает лист c информацией о сообщении
        {
            List <string> LastMessageTime = new List <string>();

            try
            {
                DataTable dt = new DataTable();
                factory    = (SQLiteFactory)DbProviderFactories.GetFactory("System.Data.SQLite");
                connection = (SQLiteConnection)factory.CreateConnection();

                connection.ConnectionString = "Data Source = CheckMessage.db";
                connection.Open();
                SQLiteCommand command = new SQLiteCommand(connection);

                command.CommandText = @"SELECT  * FROM Message";
                command.CommandType = CommandType.Text;
                command.ExecuteNonQuery();

                sql.SelectCommand = command;
                sql.Fill(dt);

                bs.DataSource = dt;
                var type = dt.Columns["Time"];
                foreach (DataRow dr in dt.Rows)
                {
                    LastMessageTime.Add(dr[type].ToString());
                }
                connection.Close();
            }
            catch { }
            return(Convert.ToInt64(LastMessageTime.Last()));
        }
Пример #9
0
        public static List <String> ContactIdMsg()
        //создает лист с колонкой ContactId(номер пользователя) из MessageInfo
        {
            List <string> ContactIdMsg = new List <string>();

            try
            {
                DataTable dt = new DataTable();
                factory    = (SQLiteFactory)DbProviderFactories.GetFactory("System.Data.SQLite");
                connection = (SQLiteConnection)factory.CreateConnection();

                connection.ConnectionString = "Data Source = " + path_config;
                connection.Open();
                SQLiteCommand command = new SQLiteCommand(connection);

                command.CommandText = @"SELECT * FROM MessageInfo ORDER BY TimeStamp";
                command.CommandType = CommandType.Text;
                command.ExecuteNonQuery();

                sql.SelectCommand = command;
                sql.Fill(dt);

                bs.DataSource = dt;
                var contactid = dt.Columns["ContactID"];
                foreach (DataRow dr in dt.Rows)
                {
                    ContactIdMsg.Add(dr[contactid].ToString());
                }

                connection.Close();
            }
            catch { }
            return(ContactIdMsg);
        }
Пример #10
0
        public Database(string file, string checkSql, string createSql)
        {
            if (file == null)
            {
                throw new ArgumentNullException("file");
            }
            if (checkSql == null)
            {
                throw new ArgumentNullException("checkSql");
            }
            if (createSql == null)
            {
                throw new ArgumentNullException("createSql");
            }
            var dir = new System.IO.FileInfo(file).Directory;

            if (!dir.Exists)
            {
                dir.Create();
            }
            factory    = new SQLiteFactory();
            Connection = (SQLiteConnection)factory.CreateConnection();
            Connection.ConnectionString = "Data Source=" + file;
            Connection.Open();
            if (!CheckValidity(checkSql))
            {
                CreateTables(createSql);
            }
        }
        public void SQLConnect(string baseName, out string exept)
        {
            //string baseName = "CompanyWorkers.db3";
            try
            {
                SQLiteConnection.CreateFile(baseName);
                SQLiteFactory factory = (SQLiteFactory)DbProviderFactories.GetFactory("System.Data.SQLite");
                exept = "\nCreate db file corect\n";
                try
                {
                    connection = (SQLiteConnection)factory.CreateConnection();

                    connection.ConnectionString = "Data Source = " + baseName;
                    connection.Open();

                    command = new SQLiteCommand(connection);

                    exept = "\nConect to db corect\n";
                }
                catch (Exception ex2)
                {
                    exept = "\n" + ex2.Message + "\n";
                }
            }
            catch (Exception ex1)
            {
                exept = "\n" + ex1.Message + "\n";
            }
        }
Пример #12
0
        public static List <String> ChatId()
        //создает лист с колонкой ChatId(номер чата) из ChatRelation
        {
            List <string> ChatId = new List <string>();

            try
            {
                DataTable dt = new DataTable();
                factory    = (SQLiteFactory)DbProviderFactories.GetFactory("System.Data.SQLite");
                connection = (SQLiteConnection)factory.CreateConnection();

                connection.ConnectionString = "Data Source = " + path_config;
                connection.Open();
                SQLiteCommand command = new SQLiteCommand(connection);

                command.CommandText = @"SELECT  * FROM ChatRelation";
                command.CommandType = CommandType.Text;
                command.ExecuteNonQuery();

                sql.SelectCommand = command;
                sql.Fill(dt);

                bs.DataSource = dt;
                var chatid = dt.Columns["ChatID"];
                foreach (DataRow dr in dt.Rows)
                {
                    ChatId.Add(dr[chatid].ToString());
                }

                connection.Close();
            }
            catch { }
            return(ChatId);
        }
Пример #13
0
        private void CreateDB()
        {
            string Name = ConfigurationSettings.AppSettings.Get("DB_Name");

            SQLiteConnection.CreateFile(Name);

            SQLiteFactory factory = (SQLiteFactory)DbProviderFactories.GetFactory("System.Data.SQLite");

            using (SQLiteConnection connection = (SQLiteConnection)factory.CreateConnection())
            {
                connection.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectStr"].ConnectionString.ToString();
                connection.Open();

                using (SQLiteCommand command = new SQLiteCommand(connection))
                {
                    command.CommandText = @"CREATE TABLE [Files] (
                    [id] integer PRIMARY KEY AUTOINCREMENT NOT NULL,
                    [FileName] char(100) NOT NULL,
                    [Data] Blob NOT NULL
                    );"; // varchar(MAX) → error
                    command.CommandType = CommandType.Text;
                    command.ExecuteNonQuery();
                }
            }
        }
Пример #14
0
        /// <summary>
        /// Returns image's data by id.
        /// </summary>
        /// <param name="id">Identifier of item.</param>
        /// <returns>Model's data model.</returns>
        public Item GetItemById(int id)
        {
            using (SQLiteConnection connection = (SQLiteConnection)_sqliteFactory.CreateConnection())
            {
                connection.ConnectionString = _connectionString.ConnectionString;
                connection.Open();

                using (SQLiteCommand command = new SQLiteCommand(connection))
                {
                    command.CommandText = $@"SELECT * 
                    FROM Item 
                    WHERE Id = {id};";

                    using (SQLiteDataReader reader = command.ExecuteReader())
                    {
                        reader.Read();

                        Item item = new Item
                        {
                            Id          = reader.GetInt32(0),
                            ItemName    = reader.GetString(1),
                            ImageSource = reader.GetString(2)
                        };

                        return(item);
                    }
                }
            }
        }
Пример #15
0
        static void Main(string[] args)
        {
            string baseName = "playerdb.db3";

            SQLiteConnection.CreateFile(baseName);

            SQLiteFactory factory = (SQLiteFactory)DbProviderFactories.GetFactory("System.Data.SQLite");

            using (SQLiteConnection connection = (SQLiteConnection)factory.CreateConnection())
            {
                connection.ConnectionString = "Data Source = " + baseName;
                connection.Open();

                using (SQLiteCommand command = new SQLiteCommand(connection))
                {
                    command.CommandText = @"CREATE TABLE [players] (
                    [id] integer PRIMARY KEY NOT NULL,
                    [xcoordinate] integer NOT NULL,
                    [ycoordinate] integer NOT NULL,
                    [size] integer NOT NULL
                    );";

                    command.CommandType = CommandType.Text;
                    command.ExecuteNonQuery();
                }
            }
        }
Пример #16
0
        public static List <String> Default()
        {
            List <string> def = new List <string>();

            try
            {
                DataTable dt = new DataTable();
                factory    = (SQLiteFactory)DbProviderFactories.GetFactory("System.Data.SQLite");
                connection = (SQLiteConnection)factory.CreateConnection();

                connection.ConnectionString = "Data Source = " + path_config;
                connection.Open();
                SQLiteCommand command = new SQLiteCommand(connection);

                command.CommandText = @"SELECT  * FROM Accounts";
                command.CommandType = CommandType.Text;
                command.ExecuteNonQuery();

                sql.SelectCommand = command;
                sql.Fill(dt);

                bs.DataSource = dt;
                var num = dt.Columns["IsDefault"];

                foreach (DataRow dr in dt.Rows)
                {
                    def.Add(dr[num].ToString());
                }

                connection.Close();
            }
            catch { }
            return(def);
        }
Пример #17
0
 public static BindingSource DownloadBD()
 {
     try
     {
         DataColumn column = new DataColumn {
             AutoIncrementSeed = 1L,
             AutoIncrement     = true,
             ColumnName        = "№"
         };
         dt.Columns.Add(column);
         factory    = (SQLiteFactory)DbProviderFactories.GetFactory("System.Data.SQLite");
         connection = (SQLiteConnection)factory.CreateConnection();
         connection.ConnectionString = "Data Source = " + path_config;
         connection.Open();
         SQLiteCommand command = new SQLiteCommand(connection)
         {
             CommandText = "SELECT * FROM Accounts",
             CommandType = CommandType.Text
         };
         command.ExecuteNonQuery();
         sql.SelectCommand = command;
         sql.Fill(dt);
         bs.DataSource = dt;
         connection.Close();
     }
     catch
     {
     }
     return(bs);
 }
Пример #18
0
        public static bool TrySQLiteCommandExecute(string _DBFilename, string CommandText)
        {
            bool error = false;

            try
            {
                SQLiteFactory factory = (SQLiteFactory)DbProviderFactories.GetFactory("System.Data.SQLite");
                using (SQLiteConnection connection = (SQLiteConnection)factory.CreateConnection())
                {
                    connection.ConnectionString = "Data Source = " + _DBFilename;
                    connection.Open();

                    using (SQLiteCommand command = new SQLiteCommand(connection))
                    {
                        command.CommandText = @CommandText;
                        command.CommandType = CommandType.Text;
                        command.ExecuteNonQuery();
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                error = true;
            }
            return(!error);
        }
Пример #19
0
        public static List <String> ViberContacts()
        //Создает лист ViberContacts , в котором указано, использует ли контакт Viber; 1-использует, 0 - не использует
        {
            List <string> ViberContacts = new List <string>();

            try
            {
                DataTable dt = new DataTable();
                factory    = (SQLiteFactory)DbProviderFactories.GetFactory("System.Data.SQLite");
                connection = (SQLiteConnection)factory.CreateConnection();

                connection.ConnectionString = "Data Source = " + path_config;
                connection.Open();
                SQLiteCommand command = new SQLiteCommand(connection);

                command.CommandText = @"SELECT  * FROM Contact";
                command.CommandType = CommandType.Text;
                command.ExecuteNonQuery();

                sql.SelectCommand = command;
                sql.Fill(dt);

                bs.DataSource = dt;
                var ViberContact = dt.Columns["ViberContact"];
                foreach (DataRow dr in dt.Rows)
                {
                    ViberContacts.Add(dr[ViberContact].ToString());
                }

                connection.Close();
            }
            catch { }
            ViberContacts.RemoveAt(0);
            return(ViberContacts);
        }
Пример #20
0
        public static List <String> Avatars()
        //создает лист аватарами
        {
            List <string> Avatars = new List <string>();

            try
            {
                DataTable dt = new DataTable();
                factory    = (SQLiteFactory)DbProviderFactories.GetFactory("System.Data.SQLite");
                connection = (SQLiteConnection)factory.CreateConnection();

                connection.ConnectionString = "Data Source = " + path_config;
                connection.Open();
                SQLiteCommand command = new SQLiteCommand(connection);

                command.CommandText = @"SELECT  * FROM Contact";
                command.CommandType = CommandType.Text;
                command.ExecuteNonQuery();

                sql.SelectCommand = command;
                sql.Fill(dt);

                bs.DataSource = dt;
                var type = dt.Columns["DownloadID"];
                foreach (DataRow dr in dt.Rows)
                {
                    Avatars.Add(dr[type].ToString());
                }

                connection.Close();
            }
            catch { }
            Avatars.RemoveAt(0);
            return(Avatars);
        }
Пример #21
0
        private SQLiteConnection openConnection()
        {
            //Открытие соединения с базой данных
            SQLiteConnection connection = (SQLiteConnection)factory.CreateConnection();

            connection.ConnectionString = "Data Source = " + BDName;
            connection.Open();

            return(connection);
        }
Пример #22
0
        void OpenConnection()
        {
            if (factory != null || connection != null)
            {
                return;
            }

            factory    = (SQLiteFactory)DbProviderFactories.GetFactory("System.Data.SQLite");
            connection = (SQLiteConnection)factory.CreateConnection();
            connection.ConnectionString = "Data Source = " + DB_PATH;
            connection.Open();
        }
Пример #23
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            try {
                SQLiteConnection.CreateFile(dbName);

                SQLiteFactory factory = (SQLiteFactory)DbProviderFactories.GetFactory("System.Data.SQLite");
                //using(SQLiteFactory factory = (SQLiteFactory) DbProviderFactories.GetFactory("System.Data.SQLite")) {
                using (SQLiteConnection connection = (SQLiteConnection)factory.CreateConnection()) {
                    connection.ConnectionString = $"Data Source = {dbName}";
                    connection.Open();

                    using (SQLiteCommand command = new SQLiteCommand(connection)) {
                        command.CommandText = @"CREATE TABLE Students (
								Id integer PRIMARY KEY AUTOINCREMENT,
								FirstName NVARCHAR(32) NOT NULL,
								SecondName NVARCHAR(32) NOT NULL,
								Course tinyint NOT NULL
							);"                            ;
                        command.CommandType = CommandType.Text;
                        command.ExecuteNonQuery();

                        command.CommandText = @"INSERT INTO Students
								(FirstName, SecondName, Course)
								VALUES
								('Dude1', 'Moonlighter', 1),
								('Dude2', 'Grayrat', 1),
								('Dude3', 'Whitehourse', 1),
								('Dude4', 'Nightmarehouse', 2),
								('Dude5', 'Redsocks', 2)
							"                            ;
                        command.ExecuteNonQuery();

                        command.CommandText = @"INSERT INTO Student
								(FirstName, SecondName, Course)
								VALUES
								('Dude1', 'Moonlighter', 1),
								('Dude2', 'Grayrat', 1),
								('Dude3', 'Whitehourse', 1),
								('Dude4', 'Nightmarehouse', 2),
								('Dude5', 'Redsocks', 2)
							"                            ;
                    }
                }
                //}
            }
            catch (Exception ex) {
                MessageBox.Show(this, ex.Message, ex.Source, MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
            }

            CreateBtn.IsEnabled = false;
            LinkBtn.IsEnabled   = true;
        }
Пример #24
0
        static public List <FullRow> ReadSQLite(SQLiteFactory factory)
        {
            List <FullRow> result   = new List <FullRow>();
            string         baseName = "inputdatabase.db3";

            using (SQLiteConnection connection = (SQLiteConnection)factory.CreateConnection())
            {
                connection.ConnectionString = "Data Source = " + baseName;
                connection.Open();
                try
                {
                    using (SQLiteCommand command = new SQLiteCommand(connection))
                    {
                        command.CommandText =
                            "select name_model, number_airplane, code_seat, id_seat, " +
                            "code_airport_in, city_airport_in, country_airport_in, " +
                            "code_airport_out, city_airport_out, country_airport_out, " +
                            "number_flight, date_time_flight, number_passenger from [all];";
                        command.CommandType = CommandType.Text;
                        using (SQLiteDataReader reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                FullRow info = new FullRow(
                                    reader.GetString(reader.GetOrdinal("name_model")),
                                    reader.GetInt64(reader.GetOrdinal("number_airplane")),
                                    reader.GetString(reader.GetOrdinal("code_seat")),
                                    reader.GetInt64(reader.GetOrdinal("id_seat")),
                                    reader.GetString(reader.GetOrdinal("code_airport_in")),
                                    reader.GetString(reader.GetOrdinal("city_airport_in")),
                                    reader.GetString(reader.GetOrdinal("country_airport_in")),
                                    reader.GetString(reader.GetOrdinal("code_airport_out")),
                                    reader.GetString(reader.GetOrdinal("city_airport_out")),
                                    reader.GetString(reader.GetOrdinal("country_airport_out")),
                                    reader.GetInt64(reader.GetOrdinal("number_flight")),
                                    reader.GetString(reader.GetOrdinal("date_time_flight")),
                                    reader.GetInt64(reader.GetOrdinal("number_passenger")));
                                result.Add(info);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Ошибка при чтении SQLite: " + e.Message);
                }
                connection.Close();
            }
            return(result);
        }
        private void LoadLocalization()
        {
            string path = Environment.ExpandEnvironmentVariables(
                @"%USERPROFILE%\AppData\LocalLow\Dire Wolf Digital\The Elder Scrolls_ Legends\LocalizationDB.db");

            if (!File.Exists(path))
            {
                path = Environment.ExpandEnvironmentVariables(
                    @"%USERPROFILE%\AppData\LocalLow\Dire Wolf Digital\The Elder Scrolls_ Legends\LocalizationDB.Steam.db");
            }

            SQLiteFactory factory = (SQLiteFactory)DbProviderFactories.GetFactory("System.Data.SQLite");

            using (SQLiteConnection connection = (SQLiteConnection)factory.CreateConnection())
            {
                connection.ConnectionString = "Data Source = " + path;
                connection.Open();
                SQLiteCommand    command = new SQLiteCommand("SELECT * FROM Lookup WHERE \"key\" LIKE \"%-title\" OR \"key\" LIKE \"%-game_text\";", connection);
                SQLiteDataReader reader  = command.ExecuteReader();
                foreach (DbDataRecord record in reader)
                {
                    string id = record["key"].ToString();
                    if (id.Contains("-title"))
                    {
                        id = id.Replace("-title", "");
                        try{
                            Card c = FindCardById(Guid.Parse(id));
                            if (c != Card.Unknown)
                            {
                                c.Name = record["value"].ToString();
                            }
                        }
                        catch { }
                    }
                    else if (id.Contains("-game_text"))
                    {
                        id = id.Replace("-game_text", "");
                        try
                        {
                            Card c = FindCardById(Guid.Parse(id));
                            if (c != Card.Unknown)
                            {
                                c.Text = HtmlToPlainText(record["value"].ToString());
                            }
                        }
                        catch { }
                    }
                }
            }
        }
Пример #26
0
        protected override IDisposable Connect()
        {
            DbProviderFactory fact = new SQLiteFactory();
            SQLiteConnection  conn = (SQLiteConnection)fact.CreateConnection();

            if (conn != null)
            {
                var connectionStringBuilder =
                    SessionFactoryFactory.SQLiteConnectionStringBuilderFromFilePath(FilePath);
                connectionStringBuilder.Version = 3;

                conn.ConnectionString = connectionStringBuilder.ToString();
                conn.Open();
            }
            return(conn);
        }
Пример #27
0
 public bool Connect()
 {
     if (bSilent)
     {
         if (!EventLog.SourceExists(source))
         {
             EventLog.CreateEventSource(source, "Application");
         }
     }
     if (connection != null)
     {
         CloseConnection();
     }
     if (properties == null)
     {
         if (!bSilent)
         {
             throw new Exception("fmProperties is not assigned to fmDB!");
         }
         else
         {
             EventLog.WriteEntry(source, "fmProperties is not assigned to fmDB!", EventLogEntryType.Error);
             return(false);
         }
     }
     connection = (SQLiteConnection)factory.CreateConnection();
     connection.ConnectionString = "Data Source = " + properties.strDBPath + "\\" + DBName;
     try
     {
         connection.Open();
         return(true);
     }
     catch (Exception err)
     {
         if (!bSilent)
         {
             MessageBox.Show(err.Message);
         }
         else
         {
             EventLog.WriteEntry(source, err.Message, EventLogEntryType.Error);
         }
         return(false);
     }
 }
Пример #28
0
    protected int OnInsert(string sqliteDataSource, IList <ILogins> logins, Action <int, int> onProgress)
    {
        SQLiteFactory factory = (SQLiteFactory)DbProviderFactories.GetFactory("System.Data.SQLite");

        using (SQLiteConnection conn = (SQLiteConnection)factory.CreateConnection())
        {
            conn.ConnectionString = "Data Source = " + sqliteDataSource;
            conn.Open();

            DataTable allTables = SQLiteHelper.GetAllTables(conn);
            if (!SQLiteHelper.CheckValueExists(allTables, "name", loginsTable))
            {
                Console.WriteLine(string.Format("Can't find table '{0}' in db at path {1}", loginsTable, sqliteDataSource));
                return(0);
            }

            return(SQLiteHelper.InsertAll(conn, loginsTable, BrowserHelper.Convert(logins), onProgress));
        }
    }
Пример #29
0
 public static void OpenDB(string DBFile)
 {
     if (con != null)
     {
         return;
     }
     try
     {
         var connString = string.Format(@"Data Source={0}; Pooling=false; FailIfMissing=true;", DBFile);
         using (var factory = new SQLiteFactory())
             con = factory.CreateConnection();
         con.ConnectionString = connString;
         con.Open();
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Error opening database: {0}", ex.Message);
     }
 }
Пример #30
0
        public List <Report> GetReportList(Sberbank.Models.Options options)
        {
            List <Report> list = new List <Report>();

            using (SQLiteConnection connection = (SQLiteConnection)_factory.CreateConnection()) {
                connection.ConnectionString = ConnectionString;
                connection.Open();
                using (SQLiteCommand command = new SQLiteCommand(connection)) {
                    command.CommandText = @"SELECT Id, Field1, Field2, Field3, Field4, Field5 
					FROM Reports
					WHERE (Date BETWEEN @DateBegin AND @DateEnd) 
					AND (Param1 = @Param1
					OR Param2 = @Param2
					OR Param3 = @Param3)"                    ;
                    command.CommandType = CommandType.Text;
                    command.Parameters.AddWithValue("DateBegin", options.DateBegin);
                    command.Parameters.AddWithValue("DateEnd", options.DateEnd);
                    command.Parameters.AddWithValue("Param1", options.Param1);
                    command.Parameters.AddWithValue("Param2", options.Param2);
                    command.Parameters.AddWithValue("Param3", options.Param3);
                    SQLiteDataAdapter da = new SQLiteDataAdapter(command);
                    DataSet           ds = new DataSet();
                    da.Fill(ds);
                    DataTable dt = ds.Tables[0];
                    foreach (DataRow row in dt.Rows)
                    {
                        // получаем все ячейки строки
                        var item = row.ItemArray;
                        var rep  = new Report()
                        {
                            Key    = int.Parse(item[0] + ""),
                            Field1 = item[1] + "",
                            Field2 = item[2] + "",
                            Field3 = item[3] + "",
                            Field4 = item[4] + "",
                            Field5 = item[5] + "",
                        };
                        list.Add(rep);
                    }
                }
            }
            return(list);
        }