开发者

SystemError: The connection has been disabled

This is a really nebulous error that I can't seem to get a lot of context for so p开发者_如何学运维lease ask any questions that might help clarify. I'll try to give you as much context as I can.

I'm currently creating a whole bunch of insert statements for mysql using a comma separated list of parantheses delineated values (i.e. insert into table (a, b, c) values (1,2,3),(4,5,6),(7,8,9);) I'm creating a thousand of these tuples, joining them with a ',' and inserting them in one statement.

the problem is I'm getting the error in the question.

I've even resorted to connecting to the DB every time I have a new insert statement. I can provide the code if you'dl ike, but it's all masked behind a with statement.

I see no reason for the connection to the DB to be dropped....

edit: why not. here's the code. inside a for loop:

with SQLConnection(DATASOURCES[SCHEDULEDB]) as db:
    db.execute_sql( command + ' ' + ','.join(block) + ';' )

couple of def's:

def execute_sql(self, query):
    if query.startswith('select'):
        return self.execute_read(query)
    else:
        return self.execute_other(query)

def execute_other(self,query):
    adapter = OdbcCommand(query,self.connection)
    adapter.ExecuteNonQuery()
    return True


I'm not sure why you are getting the error you are getting. Perhaps it has to do with creating very long SQL statements? Whatever the case, you should always use parametrized SQL statements; avoid composing SQL (with arguments) manually:

sql = 'INSERT INTO table (a,b,c) VALUES (%s,%s,%s)'
args = [(1,2,3),(4,5,6),(7,8,9)]
cursor.executemany( sql, args )


It turns out that some of the values I was trying to insert into the DB are larger than the VarChar size I allocated for it. The exceptions aren't very enlightening. I ended up checking to make sure each value I insert is smaller than the size allocated for it and raising an exception if it's not.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜