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.
This commit is contained in:
gambas 2019-02-06 23:24:08 +01:00
parent c0eab6b4c4
commit 466a570451
4 changed files with 13 additions and 5 deletions

View File

@ -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;
}
}

View File

@ -1,3 +1,3 @@
[Component]
Key=gb.db
Version=3.12.0
Version=3.12.90

View File

@ -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

View File

@ -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