多行插入ANDROID
执行以下操作
INSERT INTO 'tablename'
SELECT 'data1' AS 'column1', 'data2' AS 'column2'
UNION SELECT 'data3', 'data4'
UNION SELECT 'data5', 'data6'
UNION SELECT 'data7', 'data8'
我在
查询实际上执行没有问题,但没有插入数据...我最后做了简单的测试...
这是插入日志:
05-18 10:53:49.531: DEBUG/dalvikvm(27793): GC_CONCURRENT freed 1001K, 52% free 3602K/7367K, external 2526K/3051K, paused 1ms+2ms
05-18 10:53:49.785: DEBUG/dalvikvm(27793): GC_CONCURRENT freed 1117K, 51% free 3610K/7367K, external 2526K/3051K, paused 8ms+2ms
05-18 10:53:49.835: DEBUG/dalvikvm(27793): GC_CONCURRENT freed 1083K, 52% free 3599K/7367K, external 2526K/3051K, paused 2ms+2ms
05-18 10:53:49.890: DEBUG/dalvikvm(27793): GC_CONCURRENT freed 1043K, 51% free 3634K/7367K, external 2526K/3051K, paused 2ms+2ms
05-18 10:53:49.917: DEBUG/dalvikvm(27793): GC_FOR_MALLOC freed 1079K, 52% free 3578K/7367K, external 2526K/3051K, paused 18ms
05-18 10:53:49.964: DEBUG/dalvikvm(27793): GC_CONCURRENT freed 987K, 51% free 3657K/7367K, external 2526K/3051K, paused 2ms+1ms
05-18 10:53:49.988: DEBUG/dalvikvm(27793): GC_FOR_MALLOC freed 955K, 52% free 3606K/7367K, external 2526K/3051K, paused 17ms
05-18 10:53:50.011: DEBUG/dalvikvm(27793): GC_FOR_MALLOC freed 1037K, 52% free 3584K/7367K, external 2526K/3051K, paused 18ms
05-18 10:53:50.035: DEBUG/dalvikvm(27793): GC_FOR_MALLOC freed 953K, 51% free 3627K/7367K, external 2526K/3051K, paused 18ms
05-18 10:53:50.058: DEBUG/dalvikvm(27793): GC_FOR_MALLOC freed 925K, 51% free 3631K/7367K, external 2526K/3051K, paused 18ms
05-18 10:53:50.089: DEBUG/dalvikvm(27793): GC_FOR_MALLOC freed 945K, 52% free 3589K/7367K, external 2526K/3051K, paused 18ms
05-18 10:53:50.113: DEBUG/dalvikvm(27793): GC_FOR_MALLOC freed 883K, 51% free 3638K/7367K, external 2526K/3051K, paused 18ms
05-18 10:53:50.132: DEBUG/dalvikvm(27793): GC_FOR_MALLOC freed 857K, 51% free 3625K/7367K, external 2526K/3051K, paused 17ms
05-18 10:53:50.156: DEBUG/dalvikvm(27793): GC_FOR_MALLOC freed 924K, 52% free 3593K/7367K, external 2526K/3051K, paused 18ms
05-18 10:53:50.183: DEBUG/dalvikvm(27793): GC_FOR_MALLOC freed 925K, 52% free 3594K/7367K, external 2526K/3051K, paused 19ms
05-18 10:53:50.203: DEBUG/dalvikvm(27793): GC_FOR_MALLOC freed 959K, 52% free 3596K/7367K, external 2526K/3051K, paused 18ms
05-18 10:53:50.226: DEBUG/dalvikvm(27793): GC_FOR_MALLOC freed 859K, 52% free 3597K/7367K, external 2526K/3051K, paused 18ms
05-18 10:53:50.226: DEBUG/TV Spored++(27793): INSERT INTO current SELECT '1' AS _id_current, '4645416' AS id_current, '3SAT' AS channel_name, '3SAT' AS channel, '2' AS id_channel, '27' AS id_language, 'Lanz kuha' AS title, '2011-05-18 10:15:00' AS start, '75' AS length, '11' AS catergory, '65' AS genre, '0' AS sortOrder UNION SELECT '2', '4628869', 'A Kanal', 'AKANAL', '3', '2', 'Pa me ustreli!', '2011-05-18 10:40:00', '30', '5', '94', '1' UNION SELECT '3', '4648393', 'ABMoteurs', 'ABMOTEURS', '4', '12', 'Fenomen Ferrari', '2011-05-18 10:30:00', '30', '8', '7', '2' UNION SELECT '4', '4644514', 'ARD', 'ARD', '8', '27', 'Za božjo voljo', '2011-05-18 10:25:00', '50', '5', '9', '3' UNION SELECT '5', '4647462', 'ARTE', 'ARTE', '9', '27', 'Junaki znanosti', '2011-05-18 10:10:00', '50', '8', '7', '4' UNION SELECT '6', '4624746', 'AXN Adria', 'AXN', '164', '2', 'Starsky in Hutch', '2011-05-18 10:40:00', '60', '5', '71', '5' UNION SELECT '7', '4632973', 'Animal Planet', 'ANIMAL', '6', '2', 'Živalsko okrožje', '2011-05-18 10:00:00', '55', '8', '103', '6' UNION SELECT '8', '4646744', 'BBC Entertainment', 'BBCPRIME', '10', '2', 'Michael Palin v Novi Evropi', '2011-05-18 10:25:00', '50', '8', '103', '7' UNION SELECT '9', '4645887', 'BBC World', 'BBCWORLD', '11', '2', 'Težke besede', '2011-05-18 10:30:00', '30', '7', '39', '8' UNION SELECT '10', '4640146', 'Baby First', 'BABYFIRST', '134', '2', 'Različno', '2011-05-18 10:30:00', '60', '6', '0', '9' UNION SELECT '11', '4638896', 'Boomerang', 'BOOMERANG', '12', '2', 'Jetsonovi', '2011-05-18 10:35:00', '25', '6', '46', '10' UNION SELECT '12', '4634922', 'C Music TV', 'CMUSICTV', '124', '2', 'Videomix', '2011-05-18 10:00:00', '240', '11', '15', '11' UNION SELECT '13', '4573091', 'CCTV Kitajski', 'CCTVCHINA', '149', '2', 'Potovanja', '2011-05-18 10:30:00', '30', '8', '103', '12' UNION SELECT '14', '4659684', 'CNBC Europe', 'CNBCEUR', '150', '2', 'Mednarodno trgovanje', '2011-05-18 10:00:00', '120', '7', '20', '13' UNION SELECT '15', '4640257', 'CNN International', 'CNN', '16', '2', 'Poslovni svet danes', '2011-05-18 10:00:00', '60', '7', '20', '14' UNION SELECT '16', '4638021', 'Cartoon Network - TCM', 'CARTOON', '14', '2', 'Robotek', '2011-05-18 10:30:00', '30', '6', '46', '15' UNION SELECT '17', '4646081', 'Channel One Russia', 'RUSSIA1', '165', '34', 'Zdravo živeti!', '2011-05-18 09:50:00', '70', '9', '103', '16' UNION SELECT '18', '4644397', 'Cinemax', 'CINEMAX1', '111', '2', 'Mamma Mia!', '2011-05-18 09:40:00', '110', '1', '97', '17' UNION SELECT '19', '4643819', 'Cinemax 2', 'CINEMAX2', '113', '2', 'Kalifornijska delitev', '2011-05-18 10:00:00', '105', '1', '24', '18' UNION SELECT '20', '4615025', 'Croatian Music Channel', 'CMC', '17', '14', 'Nova plošča', '2011-05-18 10:00:00', '60', '11', '15', '19' UNION SELECT '21', '4604102', 'DM Sat', 'DMSAT', '151', '38', 'Glasbeni program in pogovor preko SMS-ov', '2011-05-18 07:05:00', '235', '11', '15', '20' UNION SELECT '22', '4645977', 'Da Vinci Learning', 'DAVINCILEAR', '121', '2', 'Nekoč so bili izumitelji: Einstein', '2011-05-18 10:30:00', '30', '6', '22', '21' UNION SELECT '23', '4649979', 'Daring! TV', 'XXXXTREME', '159', '2', 'Fantom vstop prepovedan', '2011-05-18 08:53:00', '127', '14', '91', '22' UNION SELECT '24', '4626679', 'Discovery Channel Europe', 'DISCOVERY', '19', '2', 'Neverjetno preživetje', '2011-05-18 10:00:00', '55', '8', '103', '23' UNION SELECT '25', '4613894', 'Discovery HD', 'DISCOVERYHD', '131', '3', 'GT dirkalnik: Magny Cours', '2011-05-18 10:35:00', '50', '8', '52', '24' UNION SELECT '26', '4633183', 'Discovery Investigation', 'DISCINV', '120', '2', 'Dosjeji FBI', '2011-05-18 10:10:00', '50', '8', '103', '25' UNION SELECT '27', '4610298', 'Discovery Science', 'DISCSCI', '21', '2', 'LDRS - Največji nevarni raketoplani', '2011-05-18 10:50:00', '50', '8', '103', '26'
这里可能出了什么问题?
感谢您的回答!
I do the following
INSERT INTO 'tablename'
SELECT 'data1' AS 'column1', 'data2' AS 'column2'
UNION SELECT 'data3', 'data4'
UNION SELECT 'data5', 'data6'
UNION SELECT 'data7', 'data8'
From on LINK!
Query actually executes with no problem, but no data is inserted... I do the simple test at the end...
This is the insertion LOG:
05-18 10:53:49.531: DEBUG/dalvikvm(27793): GC_CONCURRENT freed 1001K, 52% free 3602K/7367K, external 2526K/3051K, paused 1ms+2ms
05-18 10:53:49.785: DEBUG/dalvikvm(27793): GC_CONCURRENT freed 1117K, 51% free 3610K/7367K, external 2526K/3051K, paused 8ms+2ms
05-18 10:53:49.835: DEBUG/dalvikvm(27793): GC_CONCURRENT freed 1083K, 52% free 3599K/7367K, external 2526K/3051K, paused 2ms+2ms
05-18 10:53:49.890: DEBUG/dalvikvm(27793): GC_CONCURRENT freed 1043K, 51% free 3634K/7367K, external 2526K/3051K, paused 2ms+2ms
05-18 10:53:49.917: DEBUG/dalvikvm(27793): GC_FOR_MALLOC freed 1079K, 52% free 3578K/7367K, external 2526K/3051K, paused 18ms
05-18 10:53:49.964: DEBUG/dalvikvm(27793): GC_CONCURRENT freed 987K, 51% free 3657K/7367K, external 2526K/3051K, paused 2ms+1ms
05-18 10:53:49.988: DEBUG/dalvikvm(27793): GC_FOR_MALLOC freed 955K, 52% free 3606K/7367K, external 2526K/3051K, paused 17ms
05-18 10:53:50.011: DEBUG/dalvikvm(27793): GC_FOR_MALLOC freed 1037K, 52% free 3584K/7367K, external 2526K/3051K, paused 18ms
05-18 10:53:50.035: DEBUG/dalvikvm(27793): GC_FOR_MALLOC freed 953K, 51% free 3627K/7367K, external 2526K/3051K, paused 18ms
05-18 10:53:50.058: DEBUG/dalvikvm(27793): GC_FOR_MALLOC freed 925K, 51% free 3631K/7367K, external 2526K/3051K, paused 18ms
05-18 10:53:50.089: DEBUG/dalvikvm(27793): GC_FOR_MALLOC freed 945K, 52% free 3589K/7367K, external 2526K/3051K, paused 18ms
05-18 10:53:50.113: DEBUG/dalvikvm(27793): GC_FOR_MALLOC freed 883K, 51% free 3638K/7367K, external 2526K/3051K, paused 18ms
05-18 10:53:50.132: DEBUG/dalvikvm(27793): GC_FOR_MALLOC freed 857K, 51% free 3625K/7367K, external 2526K/3051K, paused 17ms
05-18 10:53:50.156: DEBUG/dalvikvm(27793): GC_FOR_MALLOC freed 924K, 52% free 3593K/7367K, external 2526K/3051K, paused 18ms
05-18 10:53:50.183: DEBUG/dalvikvm(27793): GC_FOR_MALLOC freed 925K, 52% free 3594K/7367K, external 2526K/3051K, paused 19ms
05-18 10:53:50.203: DEBUG/dalvikvm(27793): GC_FOR_MALLOC freed 959K, 52% free 3596K/7367K, external 2526K/3051K, paused 18ms
05-18 10:53:50.226: DEBUG/dalvikvm(27793): GC_FOR_MALLOC freed 859K, 52% free 3597K/7367K, external 2526K/3051K, paused 18ms
05-18 10:53:50.226: DEBUG/TV Spored++(27793): INSERT INTO current SELECT '1' AS _id_current, '4645416' AS id_current, '3SAT' AS channel_name, '3SAT' AS channel, '2' AS id_channel, '27' AS id_language, 'Lanz kuha' AS title, '2011-05-18 10:15:00' AS start, '75' AS length, '11' AS catergory, '65' AS genre, '0' AS sortOrder UNION SELECT '2', '4628869', 'A Kanal', 'AKANAL', '3', '2', 'Pa me ustreli!', '2011-05-18 10:40:00', '30', '5', '94', '1' UNION SELECT '3', '4648393', 'ABMoteurs', 'ABMOTEURS', '4', '12', 'Fenomen Ferrari', '2011-05-18 10:30:00', '30', '8', '7', '2' UNION SELECT '4', '4644514', 'ARD', 'ARD', '8', '27', 'Za božjo voljo', '2011-05-18 10:25:00', '50', '5', '9', '3' UNION SELECT '5', '4647462', 'ARTE', 'ARTE', '9', '27', 'Junaki znanosti', '2011-05-18 10:10:00', '50', '8', '7', '4' UNION SELECT '6', '4624746', 'AXN Adria', 'AXN', '164', '2', 'Starsky in Hutch', '2011-05-18 10:40:00', '60', '5', '71', '5' UNION SELECT '7', '4632973', 'Animal Planet', 'ANIMAL', '6', '2', 'Živalsko okrožje', '2011-05-18 10:00:00', '55', '8', '103', '6' UNION SELECT '8', '4646744', 'BBC Entertainment', 'BBCPRIME', '10', '2', 'Michael Palin v Novi Evropi', '2011-05-18 10:25:00', '50', '8', '103', '7' UNION SELECT '9', '4645887', 'BBC World', 'BBCWORLD', '11', '2', 'Težke besede', '2011-05-18 10:30:00', '30', '7', '39', '8' UNION SELECT '10', '4640146', 'Baby First', 'BABYFIRST', '134', '2', 'Različno', '2011-05-18 10:30:00', '60', '6', '0', '9' UNION SELECT '11', '4638896', 'Boomerang', 'BOOMERANG', '12', '2', 'Jetsonovi', '2011-05-18 10:35:00', '25', '6', '46', '10' UNION SELECT '12', '4634922', 'C Music TV', 'CMUSICTV', '124', '2', 'Videomix', '2011-05-18 10:00:00', '240', '11', '15', '11' UNION SELECT '13', '4573091', 'CCTV Kitajski', 'CCTVCHINA', '149', '2', 'Potovanja', '2011-05-18 10:30:00', '30', '8', '103', '12' UNION SELECT '14', '4659684', 'CNBC Europe', 'CNBCEUR', '150', '2', 'Mednarodno trgovanje', '2011-05-18 10:00:00', '120', '7', '20', '13' UNION SELECT '15', '4640257', 'CNN International', 'CNN', '16', '2', 'Poslovni svet danes', '2011-05-18 10:00:00', '60', '7', '20', '14' UNION SELECT '16', '4638021', 'Cartoon Network - TCM', 'CARTOON', '14', '2', 'Robotek', '2011-05-18 10:30:00', '30', '6', '46', '15' UNION SELECT '17', '4646081', 'Channel One Russia', 'RUSSIA1', '165', '34', 'Zdravo živeti!', '2011-05-18 09:50:00', '70', '9', '103', '16' UNION SELECT '18', '4644397', 'Cinemax', 'CINEMAX1', '111', '2', 'Mamma Mia!', '2011-05-18 09:40:00', '110', '1', '97', '17' UNION SELECT '19', '4643819', 'Cinemax 2', 'CINEMAX2', '113', '2', 'Kalifornijska delitev', '2011-05-18 10:00:00', '105', '1', '24', '18' UNION SELECT '20', '4615025', 'Croatian Music Channel', 'CMC', '17', '14', 'Nova plošča', '2011-05-18 10:00:00', '60', '11', '15', '19' UNION SELECT '21', '4604102', 'DM Sat', 'DMSAT', '151', '38', 'Glasbeni program in pogovor preko SMS-ov', '2011-05-18 07:05:00', '235', '11', '15', '20' UNION SELECT '22', '4645977', 'Da Vinci Learning', 'DAVINCILEAR', '121', '2', 'Nekoč so bili izumitelji: Einstein', '2011-05-18 10:30:00', '30', '6', '22', '21' UNION SELECT '23', '4649979', 'Daring! TV', 'XXXXTREME', '159', '2', 'Fantom vstop prepovedan', '2011-05-18 08:53:00', '127', '14', '91', '22' UNION SELECT '24', '4626679', 'Discovery Channel Europe', 'DISCOVERY', '19', '2', 'Neverjetno preživetje', '2011-05-18 10:00:00', '55', '8', '103', '23' UNION SELECT '25', '4613894', 'Discovery HD', 'DISCOVERYHD', '131', '3', 'GT dirkalnik: Magny Cours', '2011-05-18 10:35:00', '50', '8', '52', '24' UNION SELECT '26', '4633183', 'Discovery Investigation', 'DISCINV', '120', '2', 'Dosjeji FBI', '2011-05-18 10:10:00', '50', '8', '103', '25' UNION SELECT '27', '4610298', 'Discovery Science', 'DISCSCI', '21', '2', 'LDRS - Največji nevarni raketoplani', '2011-05-18 10:50:00', '50', '8', '103', '26'
What could be wrong here?
Thanks for your answers!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在您的日志中,
GC_FOR_MALLOC
表示您的垃圾收集器必须频繁执行,可能是由于查询的大小所致。如果必须多次连接字符串,请避免使用“+”运算符,因为它会为每次连接创建一个新字符串。因此,垃圾收集器必须做很多工作来收集这些垃圾字符串
,而您可以使用stringBuilder
。字符串生成器将新字符串附加到先前的字符串中,并且不会每次都创建新字符串。至于查询的语法,查询的结构是完美的。
我建议您使用
execSQL
而不是rawQuery(string,null)
。因为 execSQL 用于不返回任何内容的查询。In your LOG
GC_FOR_MALLOC
indicates that your Garbage collector has to execute frequently probably due to the large size of your query. If you have to concatenate a string many times avoid using '+' operator as it creates a new String for every concatenation. So garbage collector has to work a lot to collect these garbagestrings
instead you can usestringBuilder
. String builder appends the new string into previous and do not creates new string every time.As for as the syntax of query is considered, the query is perfectly structured.
I will suggest you using
execSQL
instead ofrawQuery(string,null)
. AsexecSQL
is used to queries which do not mean to return anything.尝试启动一个事务,以便所有这些插入可以分组在一起。 AFAIK SQLite 将每个插入视为一个事务,除非您显式开始和结束事务。使用开始和提交。
Try starting a transaction, so all of these inserts can be grouped together. AFAIK SQLite treats each insert to have a single transaction unless you explicitly start and end a transaction. Use Begin and Commit.