Advertisement
Guest User

DJUKA

a guest
Jan 22nd, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.SQLite;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Web;
  7.  
  8. namespace WebFormsProjekt.Persistence
  9. {
  10. public abstract class SqlLiteBaseRepository
  11. {
  12. private string _dbPath = HttpContext.Current.Server.MapPath("\\db.sqlite");
  13.  
  14. private void InitializeDatabase()
  15. {
  16. SQLiteConnection.CreateFile(_dbPath);
  17.  
  18.  
  19. using (var connection = new SQLiteConnection("Data Source =" + _dbPath))
  20. {
  21. connection.Open();
  22.  
  23. var cmd = new SQLiteCommand("CREATE TABLE users (" +
  24. "id integer primary key autoincrement, " +
  25. "username text, " +
  26. "firstName text," +
  27. "lastName text," +
  28. "email text," +
  29. "password text," +
  30. "authority integer" +
  31. ");",
  32. connection);
  33.  
  34.  
  35. cmd.ExecuteNonQuery();
  36.  
  37. cmd.CommandText = "INSERT INTO users(username, firstName, lastName, email, password, authority) values " +
  38. "('Djuro105', 'Tomislav', 'Jansky', 'tjansky@vub.hr', '1234', 2)";
  39. cmd.ExecuteNonQuery();
  40. cmd.CommandText = "INSERT INTO users(username, firstName, lastName, email, password, authority) values " +
  41. "('Pero12', 'Janko', 'Grgic', 'grga@vub.hr', 'test', 1)";
  42. cmd.ExecuteNonQuery();
  43.  
  44.  
  45.  
  46.  
  47. var cmd1 = new SQLiteCommand("CREATE TABLE groups (" +
  48. "id integer primary key autoincrement, " +
  49. "id_prof integer, " +
  50. "name text," +
  51. "course integer," +
  52. "year integer," +
  53. "subject text" +
  54. ");",
  55. connection);
  56.  
  57. cmd1.ExecuteNonQuery();
  58.  
  59. cmd1.CommandText = "INSERT INTO groups(id_prof, name, course, year, subject) values " +
  60. "(1, 'Grupa1-OIP', 0, 1, 'Oip')";
  61. cmd1.ExecuteNonQuery();
  62. cmd1.CommandText = "INSERT INTO groups(id_prof, name, course, year, subject) values " +
  63. "(1, 'Grupa2-OIP', 0, 1, 'Oip')";
  64. cmd1.ExecuteNonQuery();
  65. }
  66. }
  67.  
  68. public SqlLiteBaseRepository()
  69. {
  70. if (!File.Exists(_dbPath))
  71. {
  72. InitializeDatabase();
  73. }
  74. }
  75.  
  76. public SQLiteConnection GetDbConnection()
  77. {
  78. return new SQLiteConnection("Data Source =" + _dbPath);
  79. }
  80.  
  81. }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement