2011-08-25 60 views
0


我试图在SQLite3数据库内执行SQL文件(从MySQL数据库转储文件)。 我面临的问题是转储文件有一个不能被SQLite3处理的多重插入。 下面是一个例子:
从MySQL数据库转换SQLite3 [插入问题]

INSERT INTO resultset_values (id, o_id, points, descrip, created, createdby, up, upby) 
VALUES 
(1,1,1,'string1','2011-03-29 11:21:00','user1',NULL,NULL), 
(2,1,2,'string2','2011-03-29 11:21:00','user1',NULL,NULL); 

能正常工作在MySQL,但我不能让它在sqlite3的工作。 有人有任何想法如何在SQLite3中插入倍数? 我的数据库很大,上面的例子只是为了说明问题。

+0

为什么你想要将一个“很大”的数据库从MySQL移动到Sqlite? – NullUserException

+0

是的,这是有原因的。 这不是那么大,但无论如何...我正在开发移动平台,到目前为止,SQLite3是他们使用的数据库:) – JLuiz

+0

那么,只是想确保。 Sqlite并非真正用于处理大量数据和/或并发用户的应用程序。 – NullUserException

回答

0

这已经在这里找到答案:Is it possible to insert multiple rows at a time in an SQLite database?

显然,this syntax is not supported in SQLite

你必须把

INSERT INTO resultset_values (id, o_id, points, descrip, created, createdby, up, upby) 
VALUES 
(1,1,1,'string1','2011-03-29 11:21:00','user1',NULL,NULL), 
(2,1,2,'string2','2011-03-29 11:21:00','user1',NULL,NULL); 

到:

INSERT INTO resultset_values (id, o_id, points, descrip, created, createdby, up, upby) 
VALUES 
(1,1,1,'string1','2011-03-29 11:21:00','user1',NULL,NULL); 
INSERT INTO resultset_values (id, o_id, points, descrip, created, createdby, up, upby) 
VALUES 
(2,1,2,'string2','2011-03-29 11:21:00','user1',NULL,NULL); 

你应该能够做到这一点与自己喜欢的正则表达式能够文本编辑器。

更新

你也可以尝试将其转换成这种格式:

INSERT INTO resultset_values 
     SELECT 1,1,1,'string1','2011-03-29 11:21:00','user1',NULL,NULL 
UNION SELECT 2,1,2,'string2','2011-03-29 11:21:00','user1',NULL,NULL 
UNION ... 

但就个人而言,我认为你必须与我提出的第一个选项较少的工作。

+0

谢谢你,我要去做。 – JLuiz