· 8 years ago · May 02, 2018, 12:32 PM
1using UnityEngine;
2using System.Collections;
3
4using System.Collections.Generic;
5using System.Data;
6using Mono.Data.Sqlite;
7
8using System.IO;
9
10private string conn;
11private IDbConnection dbconn;
12private IDbCommand dbcmd = null;
13private IDataReader reader;
14
15
16private string CADASTRARFASE = "UPDATE Fases SET Fase";
17private string selectTodosFases = "SELECT * FROM Fases";
18private string inserirFase = "INSERT INTO Fases (Fase1) VALUES ('false');";
19// Use this for initialization
20void Start ()
21{
22 conecta ();
23 dbcmd.CommandText = selectTodosFases;
24 IDataReader reader = dbcmd.ExecuteReader();
25 if (!reader.Read()) {
26 reader.Close ();
27 reader = null;
28 dbcmd.CommandText = inserirFase;
29 IDataReader reader2 = dbcmd.ExecuteReader();
30 }
31
32 desconecta ();
33}
34
35
36public int checaIsTrue() {
37 conecta ();
38 dbcmd.CommandText = selectTodosFases;
39 IDataReader reader = dbcmd.ExecuteReader();
40 if (!reader.Read()) {
41 return 1;
42 desconecta ();
43 } else {
44 desconecta ();
45 return 0;
46 }
47
48
49}
50
51// Update is called once per frame
52void Update ()
53{
54
55}
56
57
58
59public void cadastraFase(string i) {
60 conecta ();
61 string cad = CADASTRARFASE + i + "='true';";
62 dbcmd.CommandText = cad;
63 reader = dbcmd.ExecuteReader();
64
65 desconecta ();
66}
67
68private void desconecta() {
69
70 dbcmd.Dispose();
71 dbcmd = null;
72 dbconn.Close();
73 dbconn = null;
74}
75
76
77private void conecta() {
78 conn = "URI=file:" + Application.dataPath + "/projetomuseu.s3db"; //Path to database.
79
80 dbconn = (IDbConnection) new SqliteConnection(conn);
81 dbconn.Open(); //Open connection to the database.
82
83 dbcmd = dbconn.CreateCommand();
84 string sqlQuery = "CREATE TABLE IF NOT EXISTS [Fases] (n[Fase1] BOOLEAN DEFAULT 'false' NULL,n[Fase2] BOOLEAN DEFAULT 'false' NULL,n[Fase3] BOOLEAN DEFAULT 'false' NULL,n[Fase4] BOOLEAN DEFAULT 'false' NULL,n[Fase5] BOOLEAN DEFAULT 'false' NULL,n[Fase6] BOOLEAN DEFAULT 'false' NULL,n[Fase7] BOOLEAN DEFAULT 'false' NULL,n[Fase8] BOOLEAN DEFAULT 'false' NULL,n[Fase9] BOOLEAN DEFAULT 'false' NULLn)";
85 dbcmd.CommandText = sqlQuery;
86 reader = dbcmd.ExecuteReader();
87
88
89 reader.Close();
90 reader = null;
91
92 sqlQuery = "CREATE TABLE IF NOT EXISTS [Colecionaveis] (n[Co1] BOOLEAN DEFAULT 'false' NULL,n[Co2] BOOLEAN DEFAULT 'false' NULL,n[Co3] BOOLEAN DEFAULT 'false' NULL,n[Co4] BOOLEAN DEFAULT 'false' NULL,n[Co5] BOOLEAN DEFAULT 'false' NULL,n[Co6] BOOLEAN DEFAULT 'false' NULL,n[Co7] BOOLEAN DEFAULT 'false' NULL,n[Co8] BOOLEAN DEFAULT 'false' NULL,n[Co9] BOOLEAN DEFAULT 'false' NULL,n[Co10] BOOLEAN DEFAULT 'false' NULL,n[Co11] BOOLEAN DEFAULT 'false' NULL,n[Co12] BOOLEAN DEFAULT 'false' NULL,n[Co13] BOOLEAN DEFAULT 'false' NULL,n[Co14] BOOLEAN DEFAULT 'false' NULL,n[Co15] BOOLEAN DEFAULT 'false' NULL,n[Co16] BOOLEAN DEFAULT 'false' NULL,n[Co17] BOOLEAN DEFAULT 'false' NULL,n[Co18] BOOLEAN DEFAULT 'false' NULLn)";
93 dbcmd.CommandText = sqlQuery;
94 reader = dbcmd.ExecuteReader();
95
96 reader.Close();
97 reader = null;
98
99
100
101 sqlQuery = "CREATE TABLE IF NOT EXISTS [Biografias] (n[Bio1] BOOLEAN DEFAULT '''false''' NULL,n[Bio2] BOOLEAN DEFAULT '''false''' NULL,n[Bio3] BOOLEAN DEFAULT '''false''' NULL,n[Bio4] BOOLEAN DEFAULT '''false''' NULL,n[Bio5] BOOLEAN DEFAULT '''false''' NULL,n[Bio6] BOOLEAN DEFAULT '''false''' NULL,n[Bio7] BOOLEAN DEFAULT '''false''' NULL,n[Bio8] BOOLEAN DEFAULT '''false''' NULL,n[Bio9] BOOLEAN DEFAULT '''false''' NULL,n[Bio10] BOOLEAN DEFAULT '''false''' NULL,n[Bio11] BOOLEAN DEFAULT '''false''' NULL,n[Bio12] BOOLEAN DEFAULT '''false''' NULL,n[Bio13] BOOLEAN DEFAULT '''false''' NULL,n[Bio14] BOOLEAN DEFAULT '''false''' NULL,n[Bio15] BOOLEAN DEFAULT '''false''' NULL,n[Bio16] BOOLEAN DEFAULT '''false''' NULL,n[Bio17] BOOLEAN DEFAULT '''false''' NULL,n[Bio18] BOOLEAN DEFAULT '''false''' NULLn)";
102 dbcmd.CommandText = sqlQuery;
103 reader = dbcmd.ExecuteReader();
104 reader.Close();
105 reader = null;
106
107}