Sok Ann Yap avatar Sok Ann Yap committed 5497a42

Move checking of special types toward the top.

Passing them as argument to `issubclass` will raise exception:

TypeError: issubclass() arg 1 must be a class

Thanks to jiangwen365 for catching this.

Comments (3)

  1. jiangwen365 repo owner

    Hi Sok, Can you please help to do a small testing on your linux box, and try changing the way loading libodbc.so on linux from:

    else:
        # Set the library location on linux 
        lib_paths = ("/usr/lib/libodbc.so","/usr/lib/i386-linux-gnu/libodbc.so","/usr/lib/x86_64-linux-gnu/libodbc.so")
        lib_paths = [path for path in lib_paths if os.path.exists(path)]
        if len(lib_paths) == 0 :
            raise OdbcNoLibrary, 'ODBC Library is not found'
        library = lib_paths[0]
        try:
            ODBC_API = ctypes.cdll.LoadLibrary(library)
        except:
            raise OdbcLibraryError, 'Error while loading %s' % library
    

    to

    else:
        # Set the library location on linux 
        #lib_paths = ("/usr/lib/libodbc.so","/usr/lib/i386-linux-gnu/libodbc.so","/usr/lib/x86_64-linux-gnu/libodbc.so")
        #lib_paths = [path for path in lib_paths if os.path.exists(path)]
        #if len(lib_paths) == 0 :
        #    raise OdbcNoLibrary, 'ODBC Library is not found'
        #library = lib_paths[0]
        try:
            ODBC_API = ctypes.cdll.LoadLibrary("libodbc.so")
        except:
            raise OdbcLibraryError, 'Error while loading %s' % library
    

    It works on my Ubuntu 12.04 box, but not sure if it works or not on your Linux box?

    I googled for quite a while and I think this is the right way to load libodbc.so on Linux. Ctypes will find it from system wide libraries, instead of the script itself finding the library in some fixed locations libodbc.so usually appears.

Files changed (1)

pypyodbc/pypyodbc.py

                 buf_size = 1
                 ParameterBuffer = create_buffer(buf_size)
 
+            elif param_types[col_num] == 'u':
+                sql_c_type = SQL_C_WCHAR
+                sql_type = SQL_WLONGVARCHAR
+                buf_size = len(self._inputsizers)>col_num and self._inputsizers[col_num] or 20500
+                ParameterBuffer = create_buffer_u(buf_size)
+
+            elif param_types[col_num] == 's':
+                sql_c_type = SQL_C_CHAR
+                sql_type = SQL_LONGVARCHAR
+                buf_size = len(self._inputsizers)>col_num and self._inputsizers[col_num] or 20500
+                ParameterBuffer = create_buffer(buf_size)
+
+            elif type(param_types[col_num]) == tuple: #Decimal
+                sql_c_type = SQL_C_CHAR
+                sql_type = SQL_NUMERIC
+                buf_size = param_types[col_num][0]
+
+                ParameterBuffer = create_buffer(buf_size+4)
+                col_size = param_types[col_num][1]
+                if DEBUG: print param_types[col_num][0],param_types[col_num][1]
+
             # bool subclasses int, thus has to go first
             elif issubclass(param_types[col_num], bool):
                 sql_c_type = SQL_C_CHAR
                 ParameterBuffer = create_buffer(buf_size)
                 
                 
-            elif type(param_types[col_num]) == tuple: #Decimal
-                sql_c_type = SQL_C_CHAR
-                sql_type = SQL_NUMERIC
-                buf_size = param_types[col_num][0]
-                
-                ParameterBuffer = create_buffer(buf_size+4)
-                col_size = param_types[col_num][1]
-                if DEBUG: print param_types[col_num][0],param_types[col_num][1]
-                
             # datetime subclasses date, thus has to go first
             elif issubclass(param_types[col_num], datetime.datetime):
                 sql_c_type = SQL_C_CHAR
                 buf_size = 255                 
                 ParameterBuffer = create_buffer(buf_size)
 
-            elif param_types[col_num] == 'u':
-                sql_c_type = SQL_C_WCHAR
-                sql_type = SQL_WLONGVARCHAR 
-                buf_size = len(self._inputsizers)>col_num and self._inputsizers[col_num] or 20500                
-                ParameterBuffer = create_buffer_u(buf_size)                
-                    
-            elif param_types[col_num] == 's':
-                sql_c_type = SQL_C_CHAR
-                sql_type = SQL_LONGVARCHAR
-                buf_size = len(self._inputsizers)>col_num and self._inputsizers[col_num] or 20500                
-                ParameterBuffer = create_buffer(buf_size)
-                
-    
             elif issubclass(param_types[col_num], (bytearray, buffer)):
                 sql_c_type = SQL_C_BINARY
                 sql_type = SQL_LONGVARBINARY 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.