dbh.execute("DROP TABLE dictionary") dbh.execute( """ CREATE TABLE if not exists `dictionary` ( `id` int auto_increment, `word` VARCHAR( 250 ) binary NOT NULL , `class` VARCHAR( 50 ) NOT NULL , `encoding` SET( 'all', 'asci', 'ucs16' ) DEFAULT 'all' NOT NULL, `type` set ( 'word','literal','regex' ) DEFAULT 'literal' NOT NULL, PRIMARY KEY (`id`) )""") count=0 for file in args[0:]: fd=open(file) print "Reading File %s" % file for line in fd: if len(line)>3: try: dbh.execute("insert into dictionary set word=\"%s\",class=\"%s\",type=%r" % (DB.escape(line.strip()),wordclass,type)) count+=1 except DB.DBError: pass if (count % 1000) == 0: sys.stdout.write("Added %s words\r" % count) sys.stdout.flush() fd.close()
dbh.execute("DROP TABLE dictionary") dbh.execute(""" CREATE TABLE if not exists `dictionary` ( `id` int auto_increment, `word` VARCHAR( 250 ) binary NOT NULL , `class` VARCHAR( 50 ) NOT NULL , `encoding` SET( 'all', 'asci', 'ucs16' ) DEFAULT 'all' NOT NULL, `type` set ( 'word','literal','regex' ) DEFAULT 'literal' NOT NULL, PRIMARY KEY (`id`) )""") count = 0 for file in args[0:]: fd = open(file) print "Reading File %s" % file for line in fd: if len(line) > 3: try: dbh.execute( "insert into dictionary set word=\"%s\",class=\"%s\",type=%r" % (DB.escape(line.strip()), wordclass, type)) count += 1 except DB.DBError: pass if (count % 1000) == 0: sys.stdout.write("Added %s words\r" % count) sys.stdout.flush() fd.close()