mysql - Cannot properly execute a sql script with sqlite3 Python module -


i'm trying execute sql scripts contained in .sql file sqlite3 python module, in order migrate database drupal site wordpress one.

so open , read .sql thing little script:

def executesqlscriptsfromfile(filename):     fd = open(filename, 'r')     sqlfile = fd.read()     fd.close()      sqlcommands = sqlfile.split(';')      command in sqlcommands:         print " === begin \n" + command + "\nend === \n"         try:             c.execute(command)         except operationalerror, msg:             print "command skipped: ", msg  

and when execute code sql commands write, works fine: create table, select, delete...

but when try sql script downloaded website database work on:

create table if not exists `node` (   `nid` int(10) unsigned not null auto_increment,   `vid` int(10) unsigned not null default '0',   `type` varchar(32) not null default '',    `language` varchar(12) not null default '',    `title` varchar(255) not null default '',    `uid` int(11) not null default '0',   `status` int(11) not null default '1',   `created` int(11) not null default '0',   `changed` int(11) not null default '0',   `comment` int(11) not null default '0',   `promote` int(11) not null default '0',   `moderate` int(11) not null default '0',   `sticky` int(11) not null default '0',   `tnid` int(10) unsigned not null default '0',   `translate` int(11) not null default '0',   primary key (`nid`),   unique key `vid` (`vid`),   key `node_changed` (`changed`),   key `node_created` (`created`),   key `node_moderate` (`moderate`),   key `node_promote_status` (`promote`,`status`),   key `node_status_type` (`status`,`type`,`nid`),   key `node_title_type` (`title`,`type`(4)),   key `node_type` (`type`(4)),   key `uid` (`uid`),   key `tnid` (`tnid`),   key `translate` (`translate`) ) engine=myisam  default charset=utf8 auto_increment=663 ; 

i got exception:

command skipped:  near "unsigned": syntax error 

as can see, not fluent in sql :p

does know may problem ?

sqlite3 not support "unsigned" , not support auto_increment. there other directive sqlite3 not support ... think got file targeting postgres or mysql... fix remove directives not supported sqlite3, or use same database engine file targets

as aside can do

 c.executescript(open("my_sqcript.sql").read()) 

here schema work sqlite3

create table if not exists `node` (   `nid` int(10) not null,   `vid` int(10) not null default '0',   `type` varchar(32) not null default '',    `language` varchar(12) not null default '',    `title` varchar(255) not null default '',    `uid` int(11) not null default '0',   `status` int(11) not null default '1',   `created` int(11) not null default '0',   `changed` int(11) not null default '0',   `comment` int(11) not null default '0',   `promote` int(11) not null default '0',   `moderate` int(11) not null default '0',   `sticky` int(11) not null default '0',   `tnid` int(10)  not null default '0',   `translate` int(11) not null default '0',   primary key (`nid`),   unique(`vid`)  )   ; 

here table defined sqlalchemy

class node(base):    __tablename__ = 'node'    nid     = column(integer,primary_key=true)    vid     = column(integer,default=0)    type    = column(string,default="")    language= column(string,default="")    title   = column(string,default="")    uid     = column(integer,default=0)    status  = column(integer,default=1)    created = column(integer,default=0)    changed = column(integer,default=0)    comment = column(integer,default=0)    promote = column(integer,default=0)    moderate= column(integer,default=0)     sticky  = column(integer,default=0)    tnid    = column(integer,default=0)    translate= column(integer,default=0) 

Comments