Get Database Name
- DarkRookie
- User
- Posts: 20
- Joined: Wed Nov 24, 2010 5:47 pm
Get Database Name
Is there a way to get a database's name after you open it.
My search in the help file, forums, and purearea came up with nothing.
I do have a workaround in place but it just seems bleh to me.
I am using ODBC with an Access file if that throws a wrench into anything.
Also using the Demo Version. Which will throw a wrench into things.
Thanks in advance
My search in the help file, forums, and purearea came up with nothing.
I do have a workaround in place but it just seems bleh to me.
I am using ODBC with an Access file if that throws a wrench into anything.
Also using the Demo Version. Which will throw a wrench into things.
Thanks in advance
Last edited by DarkRookie on Fri Jan 02, 2015 6:53 pm, edited 1 time in total.
It is better to have a dumb question than a wrong answer!
Re: Get Database Name
Hi,
if you are connectet to the DB, you can get the name with a sql query like this:
if you are connectet to the DB, you can get the name with a sql query like this:
Code: Select all
select name from sys.sysdatabases where dbid=db_id()
my live space
- DarkRookie
- User
- Posts: 20
- Joined: Wed Nov 24, 2010 5:47 pm
Re: Get Database Name
No dice
Get the following error:
Get the following error:
Code: Select all
[Microsoft][ODBC Microsoft Access Driver] Could not find file 'PATH\sys.mdb'.
It is better to have a dumb question than a wrong answer!
Re: Get Database Name
I did that long time back
Hope it will help you
Or just wait for the database guru (Kiffi or ABBKlaus)
Hope it will help you
Or just wait for the database guru (Kiffi or ABBKlaus)
Code: Select all
Macro SQL_HANDLE_ENV(Database)
PeekL(PeekL(IsDatabase(Database))-4)
EndMacro
Macro SQL_HANDLE_STMT(Database)
PeekL(PeekL(IsDatabase(Database)+4)+4)
EndMacro
Macro SQL_HANDLE_DBC(Database)
PeekL(PeekL(IsDatabase(Database)+4))
EndMacro
Procedure.b Add_User_Dsn(Driver$,Attributes$)
MakeKeywordValuePairs(Attributes$)
Result=SQLConfigDataSource_(0,#ODBC_ADD_DSN,Driver$,*LPAttribMem)
FreeMemory(*LPAttribMem)
ProcedureReturn Result
EndProcedure
Procedure.b Delete_User_Dsn(Driver$,DSN$)
DSN$="DSN="+DSN$
MakeKeywordValuePairs(DSN$)
Result=SQLConfigDataSource_(0,#ODBC_REMOVE_DSN,@Driver$,*LPAttribMem)
FreeMemory(*LPAttribMem)
ProcedureReturn Result
EndProcedure
Procedure.b Add_System_Dsn(Driver$,Attributes$)
MakeKeywordValuePairs(Attributes$)
Result=SQLConfigDataSource_(0,#ODBC_ADD_SYS_DSN,Driver$,*LPAttribMem)
FreeMemory(*LPAttribMem)
ProcedureReturn Result
EndProcedure
Procedure.b Delete_System_Dsn(Driver$,DSN$)
DSN$="DSN="+DSN$
MakeKeywordValuePairs(DSN$)
Result=SQLConfigDataSource_(0,#ODBC_REMOVE_SYS_DSN,@Driver$,*LPAttribMem)
FreeMemory(*LPAttribMem)
ProcedureReturn Result
EndProcedure
Procedure.l GetDatabaseTables(Database)
SQLCancel_(SQL_HANDLE_STMT(Database))
res.w=SQLTables_(SQL_HANDLE_STMT(Database),0,0,0,0,0,0,0,0)
If res = 0 Or res = 1 ; #SQL_SUCCESS / #SQL_SUCCESS_WITH_INFO
ProcedureReturn 1
EndIf
EndProcedure
Procedure.l GetDatabaseDBNames(Database)
SQLCancel_(SQL_HANDLE_STMT(Database))
res.w=SQLTables_(SQL_HANDLE_STMT(Database),"%",-3,"",-3,"",-3,"",-3)
If res = 0 Or res = 1 ; #SQL_SUCCESS / #SQL_SUCCESS_WITH_INFO
ProcedureReturn 1
EndIf
EndProcedure
Egypt my love
- DarkRookie
- User
- Posts: 20
- Joined: Wed Nov 24, 2010 5:47 pm
Re: Get Database Name
Didn't work for me
It cannot find
Which I am pretty sure is because I am using the Demo and not the full
It cannot find
Code: Select all
MakeKeywordValuePairs(Attributes$)
It is better to have a dumb question than a wrong answer!
Re: Get Database Name
Yes you need the full version for API functions to work
Code: Select all
Procedure.l MakeKeywordValuePairs(Attributes$)
Shared *LPAttribMem
; ConfigDSN Function from M$
; http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/odbcconfigdsn.asp
; Each pair is terminated with a null byte, and the entire list is terminated with a null byte.
; (That is, two null bytes mark the End of the list.)
While Right(Attributes$,2)<>";;"
Attributes$+";"
Wend
; Allocate enough memory in both Ascii and Unicode mode + space for the terminating zero character
*LPAttribMem=AllocateMemory(Len(Attributes$)*SizeOf(character) + SizeOf(character))
; Copy string to memory
PokeS(*LPAttribMem,Attributes$,Len(Attributes$))
; Replace each ';' with zero character
For L=1 To Len(Attributes$)
; CompilerIf #PB_Compiler_Unicode
; If PeekW(*LPAttribMem + (l-1) * SizeOf(character))=Asc(";")
; PokeW(*LPAttribMem + (l-1) * SizeOf(character),0)
; EndIf
; CompilerElse
If PeekB(*LPAttribMem + l -1)=Asc(";")
PokeB(*LPAttribMem + l -1,0)
EndIf
; CompilerEndIf
Next
ProcedureReturn *LPAttribMem
EndProcedure
Egypt my love
Re: Get Database Name
the only way i know is to examine the registry.

Here is a module to read the registry from ts-soft:
http://www.purebasic.fr/english/viewtop ... 72#p422572 (works only with the full version).
// Edit:
Greetings ... Peter

Here is a module to read the registry from ts-soft:
http://www.purebasic.fr/english/viewtop ... 72#p422572 (works only with the full version).
// Edit:
Code: Select all
Debug Registry::ReadValue(#HKEY_CURRENT_USER, "Software\ODBC\ODBC.INI\AccessTest", "DBQ")
Re: Get Database Name
Sorry for this intervention, but this is strange (for me).
after you open it, Is there a way to get a database's name ?
To open a database, you must provide the name of this database?
The same question in reverse.DarkRookie wrote:Is there a way to get a database's name after you open it.

To open a database, you must provide the name of this database?
➽ Windows 11 64-bit - PB 6.21 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti
Sorry for my bad english and the Dunning–Kruger effect
Re: Get Database Name
@falsam
no, that's not true for ODBC.
You open the ODBC connection with the name of the connection.
You don't know the name of the database.
Look at the pictures of Kiffi:
You open 'AccessTest', but the database which is behind is Test.mdb
Bernd
no, that's not true for ODBC.
You open the ODBC connection with the name of the connection.
You don't know the name of the database.
Look at the pictures of Kiffi:
You open 'AccessTest', but the database which is behind is Test.mdb
Bernd
Re: Get Database Name
ok. Thank infratec 

➽ Windows 11 64-bit - PB 6.21 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti
Sorry for my bad english and the Dunning–Kruger effect
Re: Get Database Name
Using the code from RASHAD for a while now (a 64bit version with int size 8 not 4).
With PB5.31 this code works beautifully.
With PB5.40 beta 3 this code gives me the #SQL_INVALID_HANDLE error (-2).
Would be nice if someone could test it.
With PB5.31 this code works beautifully.
With PB5.40 beta 3 this code gives me the #SQL_INVALID_HANDLE error (-2).
Would be nice if someone could test it.
I am to provide the public with beneficial shocks.
Alfred Hitshock