예제 #1
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));
        }
    }
예제 #2
0
    protected IList <ILogins> OnGet(string sqliteDataSource)
    {
        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(null);
            }

            DataTable table = SQLiteHelper.SelectAll(conn, loginsTable);
            return(BrowserHelper.Parse(table, loginsType));
        }
    }