Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor change to get full varchar field. #4

Open
jtowell opened this issue Jun 24, 2011 · 1 comment
Open

Minor change to get full varchar field. #4

jtowell opened this issue Jun 24, 2011 · 1 comment

Comments

@jtowell
Copy link

jtowell commented Jun 24, 2011

Need to call SQLGetData multiple times to get long field, limit per Get is set by ODBC driver. I'm using a Windows 2003 PostgreSQL ODBC driver.

Example patch.

--- /weigj-go-odbc-514210d/odbc.go
+++ /weigj-go-odbc-514210d-2/odbc.go
@@ -453,12 +453,22 @@
case C.SQL_WCHAR, C.SQL_WVARCHAR, C.SQL_WLONGVARCHAR:
value := make([]uint16, int(field_len)+8)
ret = C.SQLGetData(C.SQLHSTMT(stmt.handle), C.SQLUSMALLINT(field_index+1), C.SQL_C_WCHAR, C.SQLPOINTER(unsafe.Pointer(&value[0])), C.SQLINTEGER(int(field_len)+4), &fl)

  •   s := UTF16ToString(value)
    
  •   s := ""
    
  •   for Success(ret) {
    
  •       if len(UTF16ToString(value))<=0 { break }
    
  •       s += UTF16ToString(value)
    
  •       ret = C.SQLGetData(C.SQLHSTMT(stmt.handle), C.SQLUSMALLINT(field_index+1), C.SQL_C_WCHAR, C.SQLPOINTER(unsafe.Pointer(&value[0])), C.SQLINTEGER(int(field_len)+4), &fl)
    
  •   }
    v = s
    
    default:
    value := make([]byte, int(fl)+2)
    ret = C.SQLGetData(C.SQLHSTMT(stmt.handle), C.SQLUSMALLINT(field_index+1), C.SQL_C_CHAR, C.SQLPOINTER(unsafe.Pointer(&value[0])), C.SQLINTEGER(int(field_len)+4), &fl)
  •   s := string(value[0:])
    
  •   s := ""
    
  •   for Success(ret) {
    
  •       if len(string(value[0:]))<=0 { break }
    
  •       s += string(value[0:])
    
  •       ret = C.SQLGetData(C.SQLHSTMT(stmt.handle), C.SQLUSMALLINT(field_index+1), C.SQL_C_CHAR, C.SQLPOINTER(unsafe.Pointer(&value[0])), C.SQLINTEGER(int(field_len)+4), &fl)
    
  •   }
    v = s
    debugPrint("default type", value, fl, s)
    
    }
@AllanCochrane
Copy link

Hi, I have applied these changes to a local copy of odbc.go but am getting a 'FormatError 100' and empty result set. Any ideas? :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants