Adds the DatabaseEditorDesignTimeConnection example

[EXAMPLES]
* NEW: Database/DatabaseEditorDesignTimeConnection
This commit is contained in:
Martin Fischer 2023-09-02 20:44:26 +02:00
parent c8148252bc
commit d2fad3388d
9 changed files with 190 additions and 0 deletions

View file

@ -0,0 +1,12 @@
# Gambas Connection File 3.0
[Connection]
Type="sqlite"
Path="."
NoPassword=False
RememberPassword=False
IgnoreCharset=False
DisplayMetadata=True
RememberTemplate=True
Database="person.sqlite"
Requests=[""]

View file

@ -0,0 +1,65 @@
# Gambas Database Template File 3.0
{ Table
Name="__gb_metadata_v2"
PrimaryKey=["sTableName","iType","sKey"]
{ Field
Name="sTableName"
Type=db.String
}
{ Field
Name="iType"
Type=db.Integer
}
{ Field
Name="sKey"
Type=db.String
}
{ Field
Name="sValue"
Type=db.String
}
}
{ Table
Name="person2"
PrimaryKey=["person_id"]
{ Field
Name="person_id"
Type=db.Serial
}
{ Field
Name="sex_id"
Type=db.Integer
}
{ Field
Name="given_name"
Type=db.String
Length=80
}
{ Field
Name="sir_name"
Type=db.String
Length=80
}
{ Field
Name="birthdate"
Type=db.Date
}
}
{ Table
Name="sex"
PrimaryKey=["sex_id"]
{ Field
Name="sex_id"
Type=db.Integer
}
{ Field
Name="name"
Type=db.String
Length=80
}
{ Index
Name="idx_sex_sex_id"
Unique=True
Fields=["sex_id"]
}
}

View file

@ -0,0 +1,2 @@
[Desktop Entry]
Icon=./.icon.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View file

@ -0,0 +1,17 @@
# Gambas Project File 3.0
Title=DatabaseEditor
Startup=FMain
Version=1.0.0
Component=gb.image
Component=gb.gui
Component=gb.form
Component=gb.db
Component=gb.db.form
Component=gb.db.sqlite3
Description="Example program that demonstrates how to use data-bound controls to edit databse records.\nI use DataSource, DataBrowser, DataControl and DataCombo here.\n\nNote that this example uses a connection to the DB that is specified at design-time via the gambas IDE. As a consequence the IDE provides support when binding controls to tables and fields by offering the available tables or field names."
TabSize=4
Language=en_US
Vendor=MartinFischer
Packager=1
Tags=Database,Example
GambasVersion=3.18

View file

@ -0,0 +1,14 @@
' Gambas class file
Public Sub Form_Open()
Db.Debug = True ' log all database requests made by the runtime
' adjust column width
With personDataBrowser.View
.Columns[0].Width = 150 ' adjust column widths
.Columns[1].Width = 150
.Columns[2].Width = 200
.MoveTo(0, 0) ' activate first row so that data-bound controls get filled with data for this row
End With
End

View file

@ -0,0 +1,58 @@
# Gambas Form File 3.0
{ Form Form
MoveScaled(0,0,98,59)
Resizable = False
{ lblIntro Label
MoveScaled(-1,0,99,6)
Background = Color.LightForeground
Alignment = Align.Center
Border = Border.Plain
Text = ("Example of how to use a (design-time) database connection and data-bound controls.")
}
{ personDataSource DataSource
MoveScaled(0,6,98,53)
Connection = Connections["personConnection"]
Table = "person2"
{ personDataBrowser DataBrowser
MoveScaled(1,1,96,31)
Columns = ["given_name", "sir_name", "birthdate"]
Labels = ["Vorname", "Nachname", "Geburtstag"]
Grid = True
}
{ dataSex DataCombo
MoveScaled(19,33,32,4)
Field = "sex_id"
Table = "sex"
Display = "name"
}
{ dataGivenName DataControl
MoveScaled(19,38,32,4)
Field = "given_name"
}
{ dataSirName DataControl
MoveScaled(19,43,32,4)
Field = "sir_name"
}
{ dataBirthdate DataControl
MoveScaled(19,48,32,4)
Field = "birthdate"
}
{ Label1 Label
MoveScaled(1,38,16,3)
Text = ("Vorname")
}
{ Label2 Label
MoveScaled(1,43,16,3)
Text = ("Nachname")
}
{ Label3 Label
MoveScaled(1,48,16,3)
Text = ("Geburtstag")
}
{ Label5 Label
MoveScaled(1,33,17,3)
Text = ("Geschlecht")
}
}
}

View file

@ -0,0 +1,22 @@
## README
This example uses a sqlite3 DB.
One speciality with respect to gambas is that you have to be careful how to
define the schema. gambas will read this schema definition later and extract
some information from it.
Expecially the autoincrement feature often used for primary key columns
is affected by this. You can specify a PK with autoincrement in a lot of ways
that are all valid table definitions. The problem is that gambas only understands
some of then.
Here is the one that works: specify AUTOINCREMENT together with the column definition like so:
...
person_id INTEGER PRIMARY KEY AUTOINCREMENT,
...
When AUTOINCREMENT is not part of the column definition, gambas will not recognize
the fact that there is no need to provide a person_id value for insertions.
As a consequence you would have to bind the person_id to a data-bound control
to manually let the user provide this id for each new record (which does not make much sense).