G
gert
I am trying to do this in a single transaction, the 3 separate
statements work fine, but i am screwed if they are not executed
together.
########### db.execute('BEGIN') #############
db.execute('UPDATE users SET uid=? WHERE uid=?',(v['uid'],s.UID))
db.execute('UPDATE sessions SET uid=? WHERE sid=?',(v['uid'],s.SID))
# only do this if there is no primary key conflict in the above
if db.ERROR == None: db.execute('UPDATE groups SET uid=? WHERE uid=?',
(v['uid'],s.UID))
########### db.execute('END') #####################
My tables are as follows
CREATE TABLE users (
uid VARCHAR(64) PRIMARY KEY,
name VARCHAR(64) DEFAULT '',
adress VARCHAR(64) DEFAULT '',
city VARCHAR(64) DEFAULT '',
country VARCHAR(64) DEFAULT '',
phone VARCHAR(64) DEFAULT '',
picture BLOB
);
CREATE TABLE groups (
gid VARCHAR(64),
uid VARCHAR(64),
PRIMARY KEY(gid,uid),
FOREIGN KEY(uid) REFERENCES users(uid) ON UPDATE CASCADE ON DELETE
CASCADE
);
CREATE TABLE sessions (
uid VARCHAR(64) UNIQUE,
pwd VARCHAR(64) DEFAULT '',
sid VARCHAR(64) PRIMARY KEY,
exp DATETIME,
FOREIGN KEY(uid) REFERENCES users(uid) ON UPDATE CASCADE ON DELETE
CASCADE
);
What is the python or sql way of doing this kind of things ?
statements work fine, but i am screwed if they are not executed
together.
########### db.execute('BEGIN') #############
db.execute('UPDATE users SET uid=? WHERE uid=?',(v['uid'],s.UID))
db.execute('UPDATE sessions SET uid=? WHERE sid=?',(v['uid'],s.SID))
# only do this if there is no primary key conflict in the above
if db.ERROR == None: db.execute('UPDATE groups SET uid=? WHERE uid=?',
(v['uid'],s.UID))
########### db.execute('END') #####################
My tables are as follows
CREATE TABLE users (
uid VARCHAR(64) PRIMARY KEY,
name VARCHAR(64) DEFAULT '',
adress VARCHAR(64) DEFAULT '',
city VARCHAR(64) DEFAULT '',
country VARCHAR(64) DEFAULT '',
phone VARCHAR(64) DEFAULT '',
picture BLOB
);
CREATE TABLE groups (
gid VARCHAR(64),
uid VARCHAR(64),
PRIMARY KEY(gid,uid),
FOREIGN KEY(uid) REFERENCES users(uid) ON UPDATE CASCADE ON DELETE
CASCADE
);
CREATE TABLE sessions (
uid VARCHAR(64) UNIQUE,
pwd VARCHAR(64) DEFAULT '',
sid VARCHAR(64) PRIMARY KEY,
exp DATETIME,
FOREIGN KEY(uid) REFERENCES users(uid) ON UPDATE CASCADE ON DELETE
CASCADE
);
What is the python or sql way of doing this kind of things ?