def _BindParams(self, param_types, pram_io_list = []):
        # Clear the old Parameters
        if not self.connection:
            self.close()
        #self._free_results(NO_FREE_STATEMENT)
        
        # Get the number of query parameters judged by database.
        NumParams = c_short()
        ret = ODBC_API.SQLNumParams(self.stmt_h, ADDR(NumParams))
        if ret != SQL_SUCCESS:
            check_success(self, ret)
        
        if len(param_types) != NumParams.value:
            # In case number of parameters provided do not same as number required
            error_desc = "The SQL contains %d parameter markers, but %d parameters were supplied" \
                        %(NumParams.value,len(param_types))
            raise ProgrammingError('HY000',error_desc)
        
        
        # Every parameter needs to be binded to a buffer
        ParamBufferList = []
        # Temporary holder since we can only call SQLDescribeParam before
        # calling SQLBindParam.
        temp_holder = []
        for col_num in range(NumParams.value):
            dec_num = 0            
            buf_size = 512
                
            if param_types[col_num][0] == 'u':
                sql_c_type = SQL_C_WCHAR
                sql_type = SQL_WVARCHAR 
                buf_size = 255                 
                ParameterBuffer = create_buffer_u(buf_size)                
                    
            elif param_types[col_num][0] == 's':
                sql_c_type = SQL_C_CHAR
                sql_type = SQL_VARCHAR
                buf_size = 255                 
                ParameterBuffer = create_buffer(buf_size)


            elif param_types[col_num][0] == 'U':
                sql_c_type = SQL_C_WCHAR
                sql_type = SQL_WLONGVARCHAR
                buf_size = param_types[col_num][1]#len(self._inputsizers)>col_num and self._inputsizers[col_num] or 20500
                ParameterBuffer = create_buffer_u(buf_size)

            elif param_types[col_num][0] == 'S':
                sql_c_type = SQL_C_CHAR
                sql_type = SQL_LONGVARCHAR
                buf_size = param_types[col_num][1]#len(self._inputsizers)>col_num and self._inputsizers[col_num] or 20500
                ParameterBuffer = create_buffer(buf_size)
            
            # bool subclasses int, thus has to go first
            elif param_types[col_num][0] == 'b':
                sql_c_type = SQL_C_CHAR
                sql_type = SQL_BIT
                buf_size = SQL_data_type_dict[sql_type][4]
                ParameterBuffer = create_buffer(buf_size)
                
            elif param_types[col_num][0] == 'i':
                sql_c_type = SQL_C_CHAR            
                sql_type = SQL_INTEGER    
                buf_size = SQL_data_type_dict[sql_type][4]             
                ParameterBuffer = create_buffer(buf_size)           
                
            elif param_types[col_num][0] == 'l':
                sql_c_type = SQL_C_CHAR           
                sql_type = SQL_BIGINT         
                buf_size = SQL_data_type_dict[sql_type][4]         
                ParameterBuffer = create_buffer(buf_size)
            

            elif param_types[col_num][0] == 'D': #Decimal
                sql_c_type = SQL_C_CHAR
                sql_type = SQL_NUMERIC
                digit_num, dec_num = param_types[col_num][1]
                if dec_num > 0:
                    # has decimal
                    buf_size = digit_num 
                    dec_num = dec_num
                else:
                    # no decimal
                    buf_size = digit_num - dec_num 
                    dec_num = 0

                ParameterBuffer = create_buffer(buf_size + 4)# add extra length for sign and dot

                
            elif param_types[col_num][0] == 'f':
                sql_c_type = SQL_C_CHAR
                sql_type = SQL_DOUBLE                
                buf_size = SQL_data_type_dict[sql_type][4]
                ParameterBuffer = create_buffer(buf_size)
                
                
            # datetime subclasses date, thus has to go first
            elif param_types[col_num][0] == 'dt':
                sql_c_type = SQL_C_CHAR
                sql_type = SQL_TYPE_TIMESTAMP
                buf_size = self.connection.type_size_dic[SQL_TYPE_TIMESTAMP][0]                
                ParameterBuffer = create_buffer(buf_size)
                dec_num = self.connection.type_size_dic[SQL_TYPE_TIMESTAMP][1]
                
                
            elif param_types[col_num][0] == 'd':
                sql_c_type = SQL_C_CHAR
                if SQL_TYPE_DATE in self.connection.type_size_dic:
                    #if DEBUG:print('conx.type_size_dic.has_key(SQL_TYPE_DATE)')
                    sql_type = SQL_TYPE_DATE
                    buf_size = self.connection.type_size_dic[SQL_TYPE_DATE][0]
                    
                    ParameterBuffer = create_buffer(buf_size)
                    dec_num = self.connection.type_size_dic[SQL_TYPE_DATE][1]
                    
                else:
                    # SQL Sever <2008 doesn't have a DATE type.
                    sql_type = SQL_TYPE_TIMESTAMP 
                    buf_size = 10                    
                    ParameterBuffer = create_buffer(buf_size)
                    
    
            elif param_types[col_num][0] == 't':
                sql_c_type = SQL_C_CHAR
                if SQL_TYPE_TIME in self.connection.type_size_dic:
                    sql_type = SQL_TYPE_TIME
                    buf_size = self.connection.type_size_dic[SQL_TYPE_TIME][0]                    
                    ParameterBuffer = create_buffer(buf_size)
                    dec_num = self.connection.type_size_dic[SQL_TYPE_TIME][1]                   
                elif SQL_SS_TIME2 in self.connection.type_size_dic:
                    # TIME type added in SQL Server 2008
                    sql_type = SQL_SS_TIME2
                    buf_size = self.connection.type_size_dic[SQL_SS_TIME2][0]
                    ParameterBuffer = create_buffer(buf_size)
                    dec_num = self.connection.type_size_dic[SQL_SS_TIME2][1]
                else:
                    # SQL Sever <2008 doesn't have a TIME type.
                    sql_type = SQL_TYPE_TIMESTAMP
                    buf_size = self.connection.type_size_dic[SQL_TYPE_TIMESTAMP][0]                    
                    ParameterBuffer = create_buffer(buf_size)
                    dec_num = 3
                    
            elif param_types[col_num][0] == 'BN':
                sql_c_type = SQL_C_BINARY
                sql_type = SQL_VARBINARY 
                buf_size = 1                 
                ParameterBuffer = create_buffer(buf_size)                
            
            elif param_types[col_num][0] == 'N':
                if len(self._PARAM_SQL_TYPE_LIST) > 0:
                    sql_c_type = SQL_C_DEFAULT
                    sql_type = self._PARAM_SQL_TYPE_LIST[col_num][0]
                    buf_size = 1
                    ParameterBuffer = create_buffer(buf_size)
                else:
                    sql_c_type = SQL_C_CHAR
                    sql_type = SQL_CHAR
                    buf_size = 1                 
                    ParameterBuffer = create_buffer(buf_size) 
            elif param_types[col_num][0] == 'bi':
                sql_c_type = SQL_C_BINARY
                sql_type = SQL_LONGVARBINARY 
                buf_size = param_types[col_num][1]#len(self._inputsizers)>col_num and self._inputsizers[col_num] or 20500                
                ParameterBuffer = create_buffer(buf_size)
            
                
            else:
                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)
                
            temp_holder.append((sql_c_type, sql_type, buf_size, dec_num, ParameterBuffer))

        for col_num, (sql_c_type, sql_type, buf_size, dec_num, ParameterBuffer) in enumerate(temp_holder):
            BufferLen = c_ssize_t(buf_size)
            LenOrIndBuf = c_ssize_t()
                
            
            InputOutputType = SQL_PARAM_INPUT
            if len(pram_io_list) > col_num:
                InputOutputType = pram_io_list[col_num]

            ret = SQLBindParameter(self.stmt_h, col_num + 1, InputOutputType, sql_c_type, sql_type, buf_size,\
                    dec_num, ADDR(ParameterBuffer), BufferLen,ADDR(LenOrIndBuf))
            if ret != SQL_SUCCESS:    
                check_success(self, ret)
            # Append the value buffer and the length buffer to the array
            ParamBufferList.append((ParameterBuffer,LenOrIndBuf,sql_type))
                
        self._last_param_types = param_types
        self._ParamBufferList = ParamBufferList
Create parameter buffers based on param types, and bind them to the statement
dataset/ETHPy150Open harryliu/edwin/edwinServer/site_packages/pypyodbc.py/Cursor._BindParams