summaryrefslogtreecommitdiff
path: root/Aktywator/Sql.cs
diff options
context:
space:
mode:
authorMichal Zimniewicz <mzimniew@man.poznan.pl>2015-01-28 10:49:16 +0100
committerMichal Zimniewicz <mzimniew@man.poznan.pl>2015-01-28 10:58:38 +0100
commit29d9771333f9f996208b0e3dbce95dd80cddf8e9 (patch)
tree7160accad1184eabc2dbfadf4175aeeb6abf82dc /Aktywator/Sql.cs
parenta331533373a95820a89aa93fead351ceb9a30046 (diff)
initial commit with unreleased version 1.0.4
Diffstat (limited to 'Aktywator/Sql.cs')
-rw-r--r--Aktywator/Sql.cs76
1 files changed, 76 insertions, 0 deletions
diff --git a/Aktywator/Sql.cs b/Aktywator/Sql.cs
new file mode 100644
index 0000000..c35b0dd
--- /dev/null
+++ b/Aktywator/Sql.cs
@@ -0,0 +1,76 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+using System.Data.OleDb;
+using data = System.Data.OleDb.OleDbDataReader;
+
+namespace Aktywator
+{
+ class Sql
+ {
+ private OleDbConnection connection;
+
+ public Sql(string filename)
+ {
+ string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" + filename + ";";
+ connection = new OleDbConnection(connStr);
+ connection.Open();
+ }
+
+ public void close()
+ {
+ connection.Close();
+ }
+
+ public bool isOpen()
+ {
+ if (connection == null) return false;
+ else return connection.State == System.Data.ConnectionState.Open;
+ }
+
+ public int query(string q)
+ {
+ OleDbCommand cmd = new OleDbCommand(q, connection);
+ return cmd.ExecuteNonQuery();
+ }
+ public string selectOne(string q)
+ {
+ OleDbCommand cmd = new OleDbCommand(q, connection);
+ object o = cmd.ExecuteScalar();
+ if (o == null) return "";
+ else return o.ToString();
+ }
+ public data select(string q)
+ {
+ OleDbCommand cmd = new OleDbCommand(q, connection);
+ return cmd.ExecuteReader();
+ }
+
+ public bool checkTableExists(string tableName)
+ {
+ try
+ {
+ selectOne("select count(*) from " + tableName);
+ }
+ catch (OleDbException)
+ {
+ return false;
+ }
+ return true;
+ }
+
+ public bool checkFieldExists(string tableName, string fieldName)
+ {
+ try
+ {
+ selectOne("select " + fieldName + " from " + tableName);
+ }
+ catch (OleDbException)
+ {
+ return false;
+ }
+ return true;
+ }
+ }
+}