[Tutor] Ado data type conversions

WEISS, MARK (NB) mw5858 at sbc.com
Mon Oct 18 21:17:00 CEST 2004


Good morning everyone!  I am trying to dynamically create an UPDATE sql
statement based on an ADO recordset queried from a staging database.  Is
there an easy way to handle the adDate and NULL data types?  I think I
should be able to cast them to the specific type (as with strings and
int's), but I'm having a hard time finding the solution.  I would
appreciate any suggestions or hints.  Thank you!  
Mark

My function uses this loop to parse through a recordset, and return a
list of values:
(Python 2.3.3 running on Windows 2000)

	for i in updateflds:
                    try:
                        if str(rs.Fields(i).type) == '202':
                            # we have an ADO adVarWChar type (= 202)
                            value = str(rs.Fields(i).value).strip()
                        elif str(rs.Fields(i).type) == '3':
                            # we have an ADO adInteger type (= 3)
                            value = eval(str(rs.Fields(i).value))
                        elif str(rs.Fields(i).type) == '7':
                            # we have an ADO adDate type (= 7)
                            # value should be cast to an adDate type or
just object(?)
		    value = rs.Fields(i).value
                        else:
                            # we have an unhandled ADO type (= i)
                            value = 'UNHANDLED_TYPE_' + i + "_" +
str(rs.Fields(i).type) 
                            # print i + " - " + str(rs.Fields(i).type) +
" - " + str(rs.Fields(i).value)
    
                        if value is None:
		    # value should be cast to an object that adds NULL
to the list... can't be 'NULL' 
                            value = value

                        updatevalues.append(value)    
                        
                    except Exception:                      
                        updatevalues.append('err_UNHANDLED_TYPE_' + i +
"_" + str(rs.Fields(i).type))                    
                        pass

The result of the loop above is used like this:

	qString = "UPDATE " + tname + " SET "+ str(tuple(updateflds)) +
" = " + str(tuple(updatevalues))
	whereString = " WHERE KEY = '" + str(rs_key) + "'"
	writeToFile(ATTRIBUTE_MOD_SQL, qString + whereString)



More information about the Tutor mailing list