[Gambas-user] show record with mysql (withDB.08)

Charlie karl.reinl at ...9...
Fri May 16 22:21:54 CEST 2003


Saman Sjukur schrieb:

>Hi Charlie,
>I run WithDB.08, it's about show records with mysql.
>It's work just fine, but the program exit when I press any button except
>CANCEL after the message "Result is not available" appears when the pointer
>reach the last record.
>
The message is Ok, that also happend if you go down behind the first 
record, but there it don't crash, but it do work 'strange' and like it 
is often not regulary. But this is new in gambas-0.56 , I don't have 
reported to Benoît yet, because I don't take the time for do to.
Now it's done.

But always that also can be a question of philosophy.
 Some DB-engines do it, in other you have to do it by code.

Try it with  if rResult.Available then rResult.MoveNext.
If you do that on MovePrevious the messagebox don't raise, that told me 
that in the Software both cases are not equal.
In all cases it is better to do it.
In my case it's a bug in my project.

>Also the title in the message window is not "WithDB.08" but "WithDB.05"
>
This is , because tho write all this parts , I copied always one to the 
next. And in the .project file you will find Project=WithDB_05

>What should I do to fix the problem ?
>And where I can find documentation about all the syntax in database
>programming with gambas ?
>  
>
I attachet you an older  email on that subject from Benoît.

>Best regard's
>Saman Sjukur
>  
>

-------------- next part --------------
Betreff:
[Gambas-devel] Database component syntax
Von:
Beno??? Minisini <gambas at ...1...>
Datum:
Sun, 16 Feb 2003 11:42:18 +0100
An:
gambas-devel at lists.sourceforge.net, gambas-user at lists.sourceforge.net

Here is a quick explanation of how to use the database component.

**** Opening a database:

DIM hDB AS NEW Database

hDB.Type = "postgresql"
hDB.Name = "mydabatabase"
'Optional parameters
'hDB.User = "benoit"
'hDB.Password = ""
'hDB.Port = 0
'hDB.Host = "AAA.BBB.CCC.DDD"

hDB.Open

**** Closing a database:

HDB.Close

**** Executing a query and getting the result

DIM iId AS Integer
DIM sName AS String
DIM rResult AS Result
DIM sField AS String

iID = 1
sName = "Gambas"

rResult = hDB.Exec("SELECT * INTO MyTable WHERE id = &1 AND name = &2", iId, sName)

' The iId and sName are substituted into the query, with automatic quoting
' => The executed query is "SELECT * INTO MyTable WHERE id = 1 AND 
'    name = 'Gambas'"

' Printing a result

WHILE rResult.Available

  FOR EACH sField IN rResult.Fields
    PRINT sField; " = "; rResult[sField]
  NEXT
  PRINT

  rResult.MoveNext
WEND


**** Creating a record in a table

rResult = hDB.Create("MyTable")
rResult!id = 2
rResult!Name = "Python"
rResult.Update ' => Generates an INSERT query


**** Editing records in a table

rResult = hDB.Edit("MyTable", "Name = &1", "Perl")
' => send the query "SELECT * INTO MyTable WHERE Name = 'Perl'"

WHILE rResult.Available

  rResult!Name = "PHP"
  rResult.Update ' => Generates an UPDATE query

  rResult.MoveNext
WEND

BE CAREFUL ! You cannot edit records this way if the component cannot find a primary index in your table (in postgresql, a primary index on the table "MyTable" is an index named "MyTable_pkey"). If you have no primary index on your table, you must use Exec() with your own UPDATE query.


**** Transactions

hDB.Begin
...
hDB.Commit
...
hDB.Rollback


BE CAREFUL ! The interface of the database component is not terminated, so it is subject to any change ! This is an EXPERIMENTAL component.



More information about the User mailing list