Comment 0 for bug 1202298

Revision history for this message
aemil estvold (mrnitrate) wrote : 2nd connection/cursor to different database with same table names on same server, uses wrong default databse to select from same table name

Platform: Centos 6.3, Mysql server 5.5.25, Oursql 0.9.2, python 2.6

Code:
db=mdb.connect(host=host,user='feederapp',db=db, autoreconnect=True,autoping=True)
old_db=mdb.connect(host=host,user='feederapp',db=old_db, autoreconnect=True,autoping=True)

with db.cursor(mdb.DictCursor) as dbc:
 with db.cursor(mdb.DictCursor) as old_dbc:
  #get id, filenames from creatives table
  dbc.execute('SELECT id,filename from creatives')
  #this does not execute on old_db's database 'mailing' instead it incorrectly uses db's database 'kidon_mailing'
               old_dbc.execute('SELECT id,filename from creatives')

Output:
dbc.execute('SELECT id,filename from creatives') correctly returns:
'2', 'a7be4ffdcca8e550d642fd7b260ad02d.jpg'
'3', '80946164dbc8da0d537c9ac38cea1233.jpg'

While old_dbc.execute('SELECT id,filename from creatives') incorrectly returns:
'2', 'a7be4ffdcca8e550d642fd7b260ad02d.jpg'
'3', '80946164dbc8da0d537c9ac38cea1233.jpg'
Instead of:
'1094', 'eef47e724fb74e900116ca0fd5350c3d.jpg'
'1095','69219255d4d46d23ee5bac5aca659d3f.gif''

Mysql schema's:

Database 'mailing'
CREATE TABLE `creatives` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `offer_id` int(11) NOT NULL,
  `description` varchar(255) DEFAULT NULL,
  `filename` varchar(255) NOT NULL,
  `url` varchar(255) NOT NULL,
  `thumb_filename` varchar(255) NOT NULL,
  `thumb_url` varchar(255) NOT NULL,
  `created_at` datetime NOT NULL,
  PRIMARY KEY (`id`),
  KEY `offer_id` (`offer_id`),
  CONSTRAINT `creatives_ibfk_1` FOREIGN KEY (`offer_id`) REFERENCES `offers` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=2281 DEFAULT CHARSET=utf8$$

Table content:
'1094', '318', NULL, 'eef47e724fb74e900116ca0fd5350c3d.jpg', '/images/eef47e724fb74e900116ca0fd5350c3d.jpg', 'thumb-eef47e724fb74e900116ca0fd5350c3d.jpg', '/images/thumb-eef47e724fb74e900116ca0fd5350c3d.jpg', '2012-08-06 14:49:08'
'1095', '319', NULL, '69219255d4d46d23ee5bac5aca659d3f.gif', '/images/69219255d4d46d23ee5bac5aca659d3f.gif', 'thumb-69219255d4d46d23ee5bac5aca659d3f.gif', '/images/thumb-69219255d4d46d23ee5bac5aca659d3f.gif', '2012-08-06 14:51:34'

Database 'kidon_mailing':
CREATE TABLE `creatives` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `offer_id` int(11) NOT NULL,
  `description` varchar(255) DEFAULT NULL,
  `filename` varchar(255) NOT NULL,
  `url` varchar(255) NOT NULL,
  `thumb_filename` varchar(255) NOT NULL,
  `thumb_url` varchar(255) NOT NULL,
  `created_at` datetime NOT NULL,
  PRIMARY KEY (`id`),
  KEY `offer_id` (`offer_id`),
  CONSTRAINT `creatives_ibfk_1` FOREIGN KEY (`offer_id`) REFERENCES `offers` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=2281 DEFAULT CHARSET=utf8$$

Table Content:
'2', '1', NULL, 'a7be4ffdcca8e550d642fd7b260ad02d.jpg', '/static/images/a7be4ffdcca8e550d642fd7b260ad02d.jpg', 'thumb-a7be4ffdcca8e550d642fd7b260ad02d.jpg', '/static/images/thumb-a7be4ffdcca8e550d642fd7b260ad02d.jpg', '2013-07-14 17:14:56'
'3', '1', NULL, '80946164dbc8da0d537c9ac38cea1233.jpg', '/static/images/80946164dbc8da0d537c9ac38cea1233.jpg', 'thumb-80946164dbc8da0d537c9ac38cea1233.jpg', '/static/images/thumb-80946164dbc8da0d537c9ac38cea1233.jpg', '2013-07-14 17:15:09'