EDA & SQLite: Support for retrieving a Table's primary key
authorJerome St-Louis <jerome@ecere.com>
Thu, 2 Aug 2012 14:31:46 +0000 (10:31 -0400)
committerJerome St-Louis <jerome@ecere.com>
Thu, 2 Aug 2012 14:31:46 +0000 (10:31 -0400)
eda/drivers/sqlite/EDASQLite.ec
eda/drivers/sqlite/locale/EDASQLite.pot
eda/libeda/src/EDA.ec

index 1695626..76027be 100644 (file)
@@ -393,6 +393,7 @@ class SQLiteDatabase : Database
                }
                else
                {
+                  Table refTable = null;
                   sqlite3_stmt * statement;
                   
                   sprintf(command, "SELECT Name, Type, Length FROM eda_table_fields WHERE Table_Name='%s';", name);
@@ -433,8 +434,13 @@ class SQLiteDatabase : Database
                      }
 
                      {
+                        Table * fTable = (Table *)eClass_GetProperty(type, "table");
                         SQLiteField field { tbl = table, name = CopyString(fieldName), type = type, length = length, num = table.fields.count, sqliteType = sqliteType };
                         incref field;
+                        if(fTable) refTable = *fTable;
+                        if(!table.primaryKey && refTable && !strcmp(refTable.name, table.name))
+                           table.primaryKey = field;
+
                         table.fields.Add(field);
                      }
                   }
@@ -1052,6 +1058,11 @@ class SQLiteTable : Table
       return fields.first;
    }
 
+   Field GetPrimaryKey()
+   {
+      return primaryKey;
+   }
+
    uint GetFieldsCount()
    {
       return fields.count;
index 41100f1..99ad7d0 100644 (file)
@@ -10,11 +10,11 @@ msgstr ""
 "Content-Transfer-Encoding: 8bit\n"
 "X-Poedit-Basepath: ../\n"
 
-#: ./EDASQLite.ec:457
+#: ./EDASQLite.ec:463
 msgid "BEGIN FAILED!"
 msgstr "BEGIN FAILED!"
 
-#: ./EDASQLite.ec:468
+#: ./EDASQLite.ec:474
 msgid "COMMIT FAILED!"
 msgstr "COMMIT FAILED!"
 
@@ -22,11 +22,11 @@ msgstr "COMMIT FAILED!"
 msgid "EDASQLite: Can't open database (%s): %s\n"
 msgstr "EDASQLite: Can't open database (%s): %s\n"
 
-#: ./EDASQLite.ec:954
+#: ./EDASQLite.ec:960
 msgid "WARNING: ALTER TABLE DOESN'T WORK WITH PRIMARY KEY FOR "
 msgstr "WARNING: ALTER TABLE DOESN'T WORK WITH PRIMARY KEY FOR "
 
-#: ./EDASQLite.ec:915
+#: ./EDASQLite.ec:921
 msgid "WARNING: Table not yet created for class "
 msgstr "WARNING: Table not yet created for class "
 
index d1efdaa..fc36877 100644 (file)
@@ -251,6 +251,7 @@ public class Table
 public:
    virtual String GetName();
    virtual Field GetFirstField();
+   virtual Field GetPrimaryKey();
    virtual uint GetFieldsCount();
    virtual uint GetRowsCount();
    virtual DriverRow CreateRow();
@@ -274,6 +275,7 @@ public:
 public:
    property String name { get { return GetName(); } }
    property Field firstField { get { return GetFirstField(); } }
+   property Field primaryKey { get { return GetPrimaryKey(); } }
    property uint fieldsCount { get { return GetFieldsCount(); } }
    property uint rowsCount { get { return GetRowsCount(); } }