[Gambas-user] Looking up data from a second table
Christof Thalhofer
chrisml at deganius.de
Tue Feb 20 08:10:02 CET 2018
Am 20.02.2018 um 07:22 schrieb T Lee Davidson:
> And if one does not need to easily use the connection from multiple forms, the connection can simply be defined and opened in
> the main form's Open event:
>
> Public Sub Form_Open()
>
> Dim hConn As Connection
> hConn = New Connection("sqlite3://" & User.Home &/ "db.sqlite")
> Try hConn.Open()
> If Error Then
> Debug "Cannot open database."
> Return
> Endif
>
> DataSource1.Connection = hConn
> DataSource1.Table = "select this from that;"
>
> End
Yes, thank you! But in this construction one must be aware that if a
programmer creates another form in the same project and does the same
there, there are two different independent connections and so on.
Because they are independent, a database like Postgresql sees them like
different users on the network doing some database stuff. In one program
this easily can lead to situations of database deadlocks.
https://en.wikipedia.org/wiki/Deadlock
If the program is larger the use of just one single connection per
database is much more secure.
As I do DB programming all the time and quite often ran in such
situations (created code that randomly created DB deadlocks) I've
learned that using just one single connection and piping all db stuff
through it sequentially is the safest way to talk to a database.
>> For the problem of the OP: I was not able to display the data in a
>> DataView. I do not understand how the DataView corresponds with the
>> DataSource, beecause I do not work with gb.db.form.
>
> The DataView should be a child of DataSource so that it 'inherits' the connection.
Ohh...key, cool! Now I got it.
Alles Gute
Christof Thalhofer
--
Dies ist keine Signatur
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20180220/e9a2d05c/attachment.sig>
More information about the User
mailing list