[cx-oracle-users] Re: setinputsizes (Was: Inserting on table where is CLOB column)
Brought to you by:
atuining
From: Jani T. <re...@lu...> - 2005-05-18 15:59:24
|
Anthony Tuininga kirjoitti: > On 5/18/05, Jani Tiainen <re...@lu...> wrote: > >>Jani Tiainen kirjoitti: >> >> >>>In application code insert clause is in form: >>> >>>sql = "INSERT INTO FOOBAR (ID, VALUE, CLOB_VALUE) VALUES (%s, %s, %s)" >>>params = (1, 'foobar', 'verylongfoobar') >>> >>>This is converted to format: >>> >>>sql = "INSERT INTO FOOBAR (ID, VALUE, CLOB_VALUE) VALUES (:val1, :val2, >>>:val3)" >>>params = {'val1' : 1, 'val2' : 'foobar', 'val3' : 'verylongfoobar'} >>> >>>Now this works as long as string I'm trying to insert doesn't exceed >>>4000 chars. If that happens it tries insert LONG to CLOB column. >>> >>>I've tried following piece of code: >>> >>># Adjust inputsizes.. >>>inputsizes = {} >>>for k, v in params.items(): >>> if type(v) is str and len(v) > 4000: >>> inputsizes[k] = cx_Oracle.CLOB >>> else: >>> inputsizes[k] = None >>> >>>cursor.setinputsizes(inputsizes) >>> >>>And I always endup having "cx_Oracle.NotSupportedError: >>>Variable_TypeByPythonType(): unhandled data type" error. Even I remove >>>else-branch final result is still same. >>> >>>Even I used cx_Oracle.STRING instead of None result was same. >>> >> >>Only occassion when abowe works is when named parameters are passed. >> >>Even following doesn't seem to work: >> >>cursor.setinputvalues([None, cx_Oracle.CLOB]) >>cursor.execute("INSERT INTO FOOBAR(ID, CLOB_VAR) VALUES (:1, :2)", >> [{'1' : 1002}, {'2' : 'longfoobartext'}]) > > > This should be > > cursor.execute(insert_statement, [1002, 'longfoobartext']) > > In other words, you should not pass a dictionary for positional > arguments but a sequence instead. I saw that on some example and it seemed to work tough.. :) Well finally I got it workin (felt a little stupid after all.. :) But thak you very much for help and patience. Final question: Is there plans to support c-format (%s) parameters in execute query? -- Jani Tiainen |