internal Action GetAction(string actionName) { var cn = new SQLiteConnection("Data Source=" + DbName + ";Version=3;"); cn.Open(); var reader = new SQLiteCommand("select id, command, arg1, arg2 from actions where id = '" + actionName + "'", cn).ExecuteReader(); Action action = null; try { if (reader.Read()) { action = new Action(); action.Id = reader.GetString(reader.GetOrdinal("id")); action.Arg1 = reader.GetString(reader.GetOrdinal("arg1")); var arg2 = reader["arg2"]; action.Arg2 = arg2.ToString(); //action.Arg3 = reader.GetString(reader.GetOrdinal("arg3")); if (reader.GetString(reader.GetOrdinal("command")) == "pgdb-backup") { action.Command = new PostgreSQLBackupCommand(action.Arg1, action.Arg2, action.Arg3, action.Arg4); } if (reader.GetString(reader.GetOrdinal("command")) == "execute-bat") { action.Command = new ExecuteBatCommand(action.Arg1); } if (reader.GetString(reader.GetOrdinal("command")) == "sync-actions") { action.Command = new SyncActionsCommand(action.Arg1); } } } finally { cn.Close(); } return action; }
private void ApplicationControl_Load(object sender, EventArgs e) { #region read var csb = new SQLiteConnectionStringBuilder { DataSource = DataSource, Version = 3 }; using (var c = new SQLiteConnection(csb.ConnectionString)) { c.Open(); { var sql = "create table if not exists Table1 (ContentKey INTEGER PRIMARY KEY AUTOINCREMENT, ContentValue text not null, ContentBytes blob)"; using (var reader = new SQLiteCommand(sql, c).ExecuteReader()) { } } { var sql = "select ContentValue, ContentBytes from Table1"; var cmd = new SQLiteCommand(sql, c); using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { var ContentValue = reader.GetString(reader.GetOrdinal("ContentValue")); var chunkSize = 4096; // Get size of image data–pass null as the byte array parameter long bytesize = reader.GetBytes(reader.GetOrdinal("ContentBytes"), 0, null, 0, 0); // Allocate byte array to hold image data byte[] imageData = new byte[bytesize]; long bytesread = 0; int curpos = 0; while (bytesread < bytesize) { // chunkSize is an arbitrary application defined value bytesread += reader.GetBytes(reader.GetOrdinal("ContentBytes"), curpos, imageData, curpos, chunkSize); curpos += chunkSize; } dataGridView1.Rows.Add( "", ContentValue, "" + bytesize ); } } } } #endregion }