Guest User

Untitled

a guest
Dec 9th, 2017
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Vala 1.29 KB | None | 0 0
  1. using Sqlite;
  2.  
  3. class PkgDB : GLib.Object {
  4.  private Database db;
  5.  private Statement stmt;
  6.  
  7.  public PkgDB( string filename ) {
  8.   Database.open_v2( filename, out this.db, OPEN_READWRITE );
  9.  }
  10.  
  11.  public void change_pkg( string name, string version, string column, string newentry ) {
  12.   this.db.prepare_v2(@"update tbl set $column = '$newentry' where name = '$name' and version = '$version'",
  13.                      -1, out this.stmt, null);
  14.   this.stmt.step();
  15.  }
  16.  
  17.  public void add_pkg( string installed, string name, string version, string description, string dependencies ) {
  18.   this.db.prepare_v2(@"insert into tbl VALUES('$installed', '$name', '$version', '$description', '$dependencies')",
  19.                      -1, out this.stmt, null);
  20.   this.stmt.step();
  21.  }
  22.  
  23.  public void remove_pkg( string name, string version ) {
  24.   this.db.prepare_v2(@"delete from tbl where name = '$name' and version = '$version'", -1, out this.stmt, null);
  25.   this.stmt.step();
  26.  }
  27.  
  28.  public void print_pkg( string name, string version ) {
  29.   this.db.prepare_v2(@"select * from tbl where name = '$name' and version = '$version'", -1, out this.stmt, null);
  30.   this.stmt.step();
  31.   for (int place = 0; place < 5; place ++ ) {
  32.    string tstring = this.stmt.column_text(place);
  33.    stdout.printf("%s\n", tstring);
  34.   }
  35.  }
  36. }
Add Comment
Please, Sign In to add comment