[Gambas-user] How do I get the database name from Connection.Databases
ron
ronstk at ...239...
Sun Apr 16 21:18:12 CEST 2006
I want to get the names of the databases on a connection
dim hConn as connection
set user,pass etc and hConn.open
now I should be able to get from hConn.Dataases the names
but how ?
The local help says only: PROPERTY Databases AS Object
The website says:
-----------
Connection.Databases (gb.db)
PROPERTY Databases AS .ConnectionDatabases
-----------
the link: .ConnectionDatabases says:
.ConnectionDatabases (gb.db)
This is a collection of all databases managed by the database server.
You may not see every database if the user you used to connect to the
server do not have sufficient rights.
This class inherits .SubCollection in gb - Gambas Internal native classes.
In the link to 'gb - Gambas Internal native classes'
there is no sign of SubCollection ?
This class is enumerable with the FOR EACH keyword.
Properties: Count & length
Method: Add, Exist & Remove
note: bit stupid to generate keys for Exist() of 1...n char of a-zA-Z0-9
-----------
for .SubCollection (gb) I get
This virtual class is the parent class of every collection of sub-objects.
Properties: Count & length
Method: Exist
This class is enumerable with the FOR EACH keyword.
-----------
Both tell me the FOR EACH but how to do that excact?
FOR EACH Variable IN Expression
Expression must be a reference to an enumerable object: for example,
a collection, or an array.
The Expression is .ConnectionDatabases or .SubCollection
The Variable must be what kind of datatype if any
FOR EACH Expression
This syntax must be used when Expression is a enumerable object that
is not a real container: for example, the result of a database query.
FOR EACH hconn.Databases
print hconn.Databases[key] ' the key is the thing I want
NEXT
FOR Variable = Expression TO Expression [ STEP Expression ]
FOR x = 0 TO hconn.Databases.length - 1
print "database name=" & ????? hconn.Databases[x]
NEXT
In hconn.Databases[x] x must be the key as string
If it is the name then it does not work, I don't know the names
and just want them.
If x can be a integer wich property tell me the name for that key as index?
Currently I do
PRIVATE SUB FillListBox(sql AS String, obj AS ListBox)
DIM res AS Result
res = hconn.Exec(sql)
WITH obj
.Clear
WHILE res.Available
.Add(res[0])
res.MoveNext
WEND
END WITH
END
PUBLIC SUB ListBoxDBUpdate()
DIM sql AS String
sql = "show databases"
FillListBox(sql, ListboxDB)
END
As work arround the res = hconn.Exec(sql).
However I should not use the .Exec as told in the help.
if hConn.Databases returns a String[] and the list property
of the listbox ask for a String[] the next line solved everything
ListBox1.list = hConn.Databases
For ListBox.List
PROPERTY List AS String
Returns or sets the ListBox contents with a string.
Each element in the string must be delimited by a newline character.
ListBox1.list = hConn.Databases.Join("\n")
ListBox1.list
So my request is what does Connection.Databases give me in real live.
In fact the Connection.Tables is the same problem.
----
mfg Ron
More information about the User
mailing list