[Gambas-user] prb:Connection.Exec() bypass sql code

ron ronstk at ...239...
Sat Apr 29 23:34:14 CEST 2006


I'm feeling realy stupid.
===========
PRINT sTBLinProc
  hRecordData = hConn.Create(sTBLinProc)
i = hRecordData.Fields.Count
i = hRecordData.Count
i = hRecordData.Max

  txtCount.Text = getRecordCount()
===========
hRecordData is variable of Result
sTBLinProc = table name and correct
the first i is correct field count
the second i is gives '1' and is wrong, the test table has 7 records
the last i returns '0' and should be 6 ?

The GetRecordCount() I made get it from the same table and is correct.

The help says only 
  'This class represents the result of a SQL request.'
  'Returns the number of records inside the result.'

Than it is logic to me that 'hRecordData = hConn.Create(sTBLinProc)'
should act as the SQL request and get the whole table as 
"SELECT * FROM table" and if there is a note in gb.db 
page not to use .Exec for correct working.

using:
===========
  FOR EACH sName IN asFields '<-- these are the fieldnames in table
    PRINT sName & " = " & hRecordData[sName] '<-- no data
  NEXT
hRecordData.MoveFirst
  FOR EACH sName IN asFields
    PRINT sName & " = " & hRecordData[sName] '<-- no data
  NEXT
===========
But it tells me there is 1 record and nothing in it ?


Again from help

  gb.db - Database access component

the information note at the end

  This works only if:
  ...
  You use the Find, Create and Edit methods.
  ...
  You don't use the Exec method, that lets you 
  send SQL request directly to the backend, so 
  that you can access its specific features.

I use the Create to open/use the table.

PUBLIC SUB hurt()
DIM hConn AS Connection
  DIM hResult AS result
  DIM done AS Integer
  
  done = 0
  hConn = NEW Connection
  hConn.Type = "mysql"  
  hConn.host = "127.0.0.1"
  hConn.Name = "selectdemo"
  hConn.user = "gambas"
  hConn.Password = "gambas"
  hConn.open()

  hResult = hConn.Create("makes")
  FOR EACH hResult
    PRINT hResult!makeID; " "; hResult!makeName; " and "; hResult.Count - done; " To go"
    INC Done
  NEXT 
  
END

I get only ' and 1 To go'?

Question is what I'm doing wrong?

I do have some idea but want this info to prevent adding 
incorrect information and wild guesses to the wikihelp.

TIA,

Ron




More information about the User mailing list