From 466a570451a556eab4f649a12f64ee458c4f0901 Mon Sep 17 00:00:00 2001 From: gambas Date: Wed, 6 Feb 2019 23:24:08 +0100 Subject: [PATCH] Connection.GetTemplate() and Connection.ApplyTemplate() now take tables without primary key into account correctly. [GB.DB] * BUG: Connection.GetTemplate() and Connection.ApplyTemplate() now take tables without primary key into account correctly. --- main/lib/db/CTable.c | 5 ++++- main/lib/db/gb.db/.component | 2 +- main/lib/db/gb.db/.project | 2 +- main/lib/db/gb.db/.src/Connection.class | 9 +++++++-- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/main/lib/db/CTable.c b/main/lib/db/CTable.c index 03b0bdc24..880ca6e78 100644 --- a/main/lib/db/CTable.c +++ b/main/lib/db/CTable.c @@ -179,7 +179,10 @@ BEGIN_PROPERTY(CTABLE_primary_key) field = *((char **)GB.Array.Get(primary, i)); if (!CFIELD_exist(THIS, field)) { - GB.Error("Unknown field: &1", field); + if (!field) + GB.Error("Void field name"); + else + GB.Error("Unknown field: &1", field); return; } } diff --git a/main/lib/db/gb.db/.component b/main/lib/db/gb.db/.component index a9a67ca4f..565303235 100644 --- a/main/lib/db/gb.db/.component +++ b/main/lib/db/gb.db/.component @@ -1,3 +1,3 @@ [Component] Key=gb.db -Version=3.12.0 +Version=3.12.90 diff --git a/main/lib/db/gb.db/.project b/main/lib/db/gb.db/.project index 737ba00d6..b2f9888f9 100644 --- a/main/lib/db/gb.db/.project +++ b/main/lib/db/gb.db/.project @@ -1,7 +1,7 @@ # Gambas Project File 3.0 Title=gb.db Startup=Main -Version=3.12.0 +Version=3.12.90 VersionFile=1 Component=gb.db TabSize=2 diff --git a/main/lib/db/gb.db/.src/Connection.class b/main/lib/db/gb.db/.src/Connection.class index 7cff07e16..c722b840f 100644 --- a/main/lib/db/gb.db/.src/Connection.class +++ b/main/lib/db/gb.db/.src/Connection.class @@ -24,6 +24,7 @@ Public Sub ApplyTemplate(Template As String) Dim iLength As Integer Dim sErr As String Dim sColl As String + Dim aKey As String[] hFile = Open String Template @@ -120,7 +121,9 @@ CREATE_TABLE: Next 'Print "primary key: "; cTable["PrimaryKey"].Join(",") - hTable.PrimaryKey = cTable["PrimaryKey"] + aKey = cTable["PrimaryKey"] + If aKey.Count = 1 And If aKey[0] = "" Then aKey.Clear + If aKey.Count Then hTable.PrimaryKey = cTable["PrimaryKey"] hTable.Update For Each cIndex In cTable["Indexes"] @@ -141,6 +144,7 @@ Public Sub GetTemplate() As String Dim hField As Field Dim hIndex As Index Dim sTemplate As String + Dim aKey As String[] hFile = Open String For Write @@ -160,7 +164,8 @@ Public Sub GetTemplate() As String Print #hFile, "{ Table" Print #hFile, " Name="; Quote(hTable.Name) If hTable.Type Then Print #hFile, " Type="; Quote(hTable.Type) - Print #hFile, " PrimaryKey=[\""; hTable.PrimaryKey.Join("\",\""); "\"]" + aKey = hTable.PrimaryKey + If aKey.Count Then Print #hFile, " PrimaryKey=[\""; aKey.Join("\",\""); "\"]" For Each hField In hTable.Fields