Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Program
- {
- static void Main(string[] args)
- {
- CreateDatabase("test.db", @"d:\temp\linda.jpg");
- }
- }
- // dumps this:
- // SQLite version: 3.7.17
- // System.Data.SQLite version: System.Data.SQLite, Version=1.0.86.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139
- // Size of file: 1057881
- // Size of db: 1041408
- static void CreateDatabase(string dbPath, string imagePath)
- {
- if (File.Exists(dbPath))
- {
- File.Delete(dbPath);
- }
- using (System.Data.SQLite.SQLiteConnection conn = new System.Data.SQLite.SQLiteConnection("data source=" + dbPath))
- {
- conn.Open();
- var cmd = conn.CreateCommand();
- cmd.CommandText = "SELECT sqlite_version()";
- Console.WriteLine("SQLite version: " + cmd.ExecuteScalar());
- Console.WriteLine("System.Data.SQLite version: " + conn.GetType().Assembly.FullName);
- cmd = conn.CreateCommand();
- cmd.CommandText = "CREATE TABLE IF NOT EXISTS Test(record_id INTEGER PRIMARY KEY ASC, pic)";
- cmd.ExecuteNonQuery();
- Console.WriteLine("Size of file: " + new FileInfo(imagePath).Length);
- var photo = new Bitmap(imagePath);
- var pic = ImageToByte(photo, ImageFormat.Jpeg);
- cmd = conn.CreateCommand();
- cmd.CommandText = "INSERT INTO Test (record_id, pic) VALUES ('1', @0);";
- System.Data.SQLite.SQLiteParameter param = new System.Data.SQLite.SQLiteParameter("@0", DbType.Binary);
- param.Value = pic;
- cmd.Parameters.Add(param);
- cmd.ExecuteNonQuery();
- }
- Console.WriteLine("Size of db: " + new FileInfo(dbPath).Length);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement