Page 1 of 1

How to use SQLGetinfo_()?

Posted: Thu Jan 11, 2007 10:53 am
by bommel
Hi,

can anybody explain how to use this API function SQLGetinfo, please?

Code: Select all

SQLRETURN   SQLGetInfo       (
               SQLHDBC           ConnectionHandle,   /* hdbc */
               SQLUSMALLINT      InfoType,           /* fInfoType */
               SQLPOINTER        InfoValuePtr,       /* rgbInfoValue */
               SQLSMALLINT       BufferLength,       /* cbInfoValueMax */
               SQLSMALLINT       *StringLengthPtr);  /* pcbInfoValue */
I want to know the Name of the database that ist in use. Or is there another way to get it if the database is opened with OpenDatabaseRequester() in PB?

InfoValue has to be 16 as far as I know to get the DBName.
I'm an absolut newbie with this Api stuff. So a code example would be nice.

Thanks for your help,
bommel

Posted: Sun Jan 28, 2007 5:26 am
by Sparkie
Not fully tested but it seems to work here on PB 4.02 on WinXP SP2...

Code: Select all

#SQL_DATABASE_NAME = 16
Procedure GetDBinfo()
  InitDatabase()
  odb = OpenDatabaseRequester(0)
  If odb
    dbName.s = Space(#MAX_PATH)
    dbNameLength = 0
    ;...Thanks to ABBKlaus for getting the db handle
    ;...http://www.purebasic.fr/english/viewtopic.php?p=171735#171735
    dbHandle = PeekL(odb) 
    If SQLGetInfo_(dbHandle, #SQL_DATABASE_NAME, @dbName, Len(dbName), @dbNameLength) = 0
      MessageRequester("Path of selected Database is:", dbName, #MB_OK)
    Else
      MessageRequester("Error", "Problem calling SQLGetInfo", #MB_OK)
    EndIf
    CloseDatabase(0)
  Else
    MessageRequester("Info", "No Database opened", #MB_OK)
  EndIf
  
EndProcedure
  
If OpenWindow(0, 0, 0, 300, 300, "Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
  ButtonGadget(1, 10, 10, 100, 25, "Select Database")
  Repeat
    Event = WaitWindowEvent()
    If Event = #PB_Event_Gadget And EventGadget() = 1
      GetDBinfo()
    EndIf
  Until Event = #PB_Event_CloseWindow
EndIf
End

Posted: Sun Jan 28, 2007 3:47 pm
by bommel
Thanks @Sparkie! It works :)

Posted: Sun Jan 28, 2007 3:56 pm
by Sparkie
You're Welcome... (and welcome to PureBasic) :)