How to use SQLGetinfo_()?

Windows specific forum
bommel
New User
New User
Posts: 2
Joined: Thu Jan 11, 2007 10:45 am

How to use SQLGetinfo_()?

Post 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
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post 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
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
bommel
New User
New User
Posts: 2
Joined: Thu Jan 11, 2007 10:45 am

Post by bommel »

Thanks @Sparkie! It works :)
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

You're Welcome... (and welcome to PureBasic) :)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Post Reply