[chronojump] Added sqlite method columnExists can be caseSensitive
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] Added sqlite method columnExists can be caseSensitive
- Date: Thu, 24 Feb 2022 10:39:22 +0000 (UTC)
commit f32385c7395e340fb8ad6761d40c43c39ff5602a
Author: Xavier de Blas <xaviblas gmail com>
Date: Thu Feb 24 11:38:06 2022 +0100
Added sqlite method columnExists can be caseSensitive
src/sqlite/main.cs | 38 +++++++++++++++++++++++++++++++-------
1 file changed, 31 insertions(+), 7 deletions(-)
---
diff --git a/src/sqlite/main.cs b/src/sqlite/main.cs
index e789f3b0b..1f125bb6e 100644
--- a/src/sqlite/main.cs
+++ b/src/sqlite/main.cs
@@ -3573,7 +3573,7 @@ class Sqlite
creationRate ++;
}
- protected static bool tableExists(bool dbconOpened, string tableName)
+ protected static bool tableExists (bool dbconOpened, string tableName)
{
openIfNeeded(dbconOpened);
@@ -3594,12 +3594,36 @@ class Sqlite
return exists;
}
- /*
- TODO: create a columnExists method with sqlite command:
- SELECT * FROM sqlite_master WHERE type = 'table' AND name = 'forceSensor' AND sql LIKE
'%maxForceRaw%';
- can be implemented on the future, previous to any ALTER TABLE ADD COLUMN,
- but at the moment we are using try{}catch{} blocks and it is working great
- */
+
+ protected static bool columnExists (bool dbconOpened, string tableName, string columnName, bool
caseSensitive)
+ {
+ openIfNeeded(dbconOpened);
+
+ if(caseSensitive)
+ executeSQL("PRAGMA case_sensitive_like=ON;");
+
+ dbcmd.CommandText = "SELECT * FROM sqlite_master WHERE type = \"table\" AND name = \"" +
+ tableName + "\" AND sql LIKE \"%" + columnName + "%\"";
+
+ LogB.SQL(dbcmd.CommandText.ToString());
+
+ SqliteDataReader reader;
+ reader = dbcmd.ExecuteReader();
+
+ bool exists = false;
+ if (reader.Read())
+ exists = true;
+ //LogB.SQL(string.Format("name exists = {0}", exists.ToString()));
+
+ reader.Close();
+
+ if(caseSensitive)
+ executeSQL("PRAGMA case_sensitive_like=OFF;");
+
+ closeIfNeeded(dbconOpened);
+
+ return exists;
+ }
public static bool Exists(bool dbconOpened, string tableName, string findName)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]