ODBC connections and DatabaseColumnType()

Just starting out? Need help? Post your questions and find answers here.
User avatar
captain_skank
Enthusiast
Enthusiast
Posts: 639
Joined: Fri Oct 06, 2006 3:57 pm
Location: England

ODBC connections and DatabaseColumnType()

Post by captain_skank »

Morning all,

Not sure if this is a bug or known behaviour :

On the latest beta DatabaseColumnType() returns 0 when using ODBC as a connection type.

I will test it using older versions but wondered if anyone else has seen this before.

Cheers
Marco2007
Enthusiast
Enthusiast
Posts: 648
Joined: Tue Jun 12, 2007 10:30 am
Location: not there...

Re: ODBC connections and DatabaseColumnType()

Post by Marco2007 »

I just tried ODBC with MySQL and SQL Server -> okay here with PB 6.10 b6 x64. 🤔
PureBasic for Windows
User avatar
captain_skank
Enthusiast
Enthusiast
Posts: 639
Joined: Fri Oct 06, 2006 3:57 pm
Location: England

Re: ODBC connections and DatabaseColumnType()

Post by captain_skank »

Code: Select all

; Execute a SQL query
If DatabaseQuery(0, PVAR_sql)
  
  column_count.i = DatabaseColumns(0)
  
  ; get the column names and update the CSV
  For loop_count = 0 To column_count
    
    Debug DatabaseColumnName(0, loop_count)
    
    Select DatabaseColumnType(0, loop_count) ;
      Case #PB_Database_Long                 ; Numeric format (a Long (.l) in PureBasic)
        Debug "Column " + Str(loop_count) + "#PB_Database_Long"
      Case #PB_Database_Float   ; Numeric float format (a Float (.f) in PureBasic)
        Debug "Column " + Str(loop_count) + "#PB_Database_Float"
      Case #PB_Database_Double  ; Numeric double format (a Double (.d) in PureBasic)
        Debug "Column " + Str(loop_count) + "#PB_Database_Double"
      Case #PB_Database_Quad    ; Numeric quad format (a Quad (.q) in PureBasic)
        Debug "Column " + Str(loop_count) + "#PB_Database_Quad"
      Case #PB_Database_Blob    ; Blob format
        Debug "Column " + Str(loop_count) + "#PB_Database_Blob"
      Case #PB_Database_String  ; String format (a String (.s) in PureBasic)
        Debug "Column " + Str(loop_count) + "#PB_Database_String"
      Default
        Debug "Column " + Str(loop_count) + "No DB column type found"
    EndSelect 
    
  Next
  
  ; get the database records and update the CSV
  While NextDatabaseRow(0)
    
    field_data.s = ""
    
    For loop_count = 0 To column_count
      
      Select DatabaseColumnType(0, loop_count) ;
        Case #PB_Database_Long                 ; Numeric format (a Long (.l) in PureBasic)
          field_data + GetDatabaseString(0, loop_count)
        Case #PB_Database_Float   ; Numeric float format (a Float (.f) in PureBasic)
          field_data + GetDatabaseString(0, loop_count)
        Case #PB_Database_Double  ; Numeric double format (a Double (.d) in PureBasic)
          field_data + GetDatabaseString(0, loop_count)
        Case #PB_Database_Quad    ; Numeric quad format (a Quad (.q) in PureBasic)
          field_data + GetDatabaseString(0, loop_count)
        Case #PB_Database_Blob    ; Blob format
          field_data + GetDatabaseString(0, loop_count)
        Case #PB_Database_String  ; String format (a String (.s) in PureBasic)
          field_data + Chr(34) + GetDatabaseString(0, loop_count) + Chr(34)
      EndSelect    
      
    Next
    
  Wend
  
  FinishDatabaseQuery(0)
   
Else
  Debug "database error"
EndIf  
This is a snippet of my db code and using DatabaseColumnType() before and after the db retrieval loop - and neither return anything but 0.

But the databasecolumncount() and DatabaseColumnName() commands work fine.

cheers
Marco2007
Enthusiast
Enthusiast
Posts: 648
Joined: Tue Jun 12, 2007 10:30 am
Location: not there...

Re: ODBC connections and DatabaseColumnType()

Post by Marco2007 »

Do you mean the last column?

I think, you need to do this:

Code: Select all

For loop_count = 0 To column_count-1
PureBasic for Windows
User avatar
captain_skank
Enthusiast
Enthusiast
Posts: 639
Joined: Fri Oct 06, 2006 3:57 pm
Location: England

Re: ODBC connections and DatabaseColumnType()

Post by captain_skank »

oops - ignore that. :oops:

But no doesn't work for any of them.

I'm doing some more experimentation at the moment and i think it's the version of the ODBC driver - if I upgrade to the newest it works fine, but in this particular use case i have to use an older 32bit version which this doesn't work with.

Cheers
Post Reply