SQLite3, combining multiple INSERT statements?

I'm sure there must be an easy answer to this but everything I've googled seems to over complicate things and now I'm not so sure.

So here's what I'd have to do to insert records into my table now

INSERT INTO CAT_BUD_TAB (_id, CAT_ITEM, IN_OUT) VALUES (null, 'Student Loan', 'out'); INSERT INTO CAT_BUD_TAB (_id, CAT_ITEM, IN_OUT) VALUES (null, 'Food', 'in');

I figure there must be a shorter way, say something like..

INSERT INTO CAT_BUD_TAB (_id, CAT_ITEM, IN_OUT) VALUES (null, 'Student Loan', 'out'),(null, 'Food', 'in');

I'm using SQLite as I'm developing for android, but I'm pretty sure it's SQLite3 which means INSERTS like above should be possible right? How do I do it?

-------------Problems Reply------------

simple way is store the value1 and value2 in array and use a for loop like

for(int i = 0;i< value1.length,i++)
INSERT INTO CAT_BUD_TAB (_id, CAT_ITEM, IN_OUT) VALUES (null, 'value1[i]', 'value2[i]');

Try use statement as folowing :

INSERT INTO table(field1,field2) SELECT "value1","value2" UNION SELECT "value1","value2" ...

Here is the official reference:


However, it seems to be possible:

insert into myTable (col1,col2)
select aValue as col1,anotherValue as col2
union select moreValue,evenMoreValue

Also, consider using things like:

begin transaction;
insert into ...;
insert into ...;

I don´t know to combining multiple Inserts. I think this is not possible!

Use transactions and prepared statements, if you want to insert a long list in a very short time.

For what do you need it?

The docs on the SQL syntax understood by SQLite seem to indicate that only one set of VALUES can be used with each INSERT statement.


Category:android Views:0 Time:2010-12-08

Related post

  • Hibernate Batch Insert. Would it ever use one insert instead of multiple inserts? 2011-05-29

    I've been looking around trying to determine some Hibernate behavior that I'm unsure about. In a scenario where Hibernate batching is properly set up, will it only ever use multiple insert statements when a batch is sent? Is it not possible to use a

  • Combining SQL Insert and Delete 2009-05-05

    Ok here is the question I have three tables events - id - name questions - id - event_id - name answers - id - question_id - description While generating the add form, i can simply search for all the questions belonging to particular event, and show

  • How to combine multiple Excel files into single Excel workbook with multiple sheets? 2009-06-30

    I need to develop a service (either WCF or Java) that can take multiple single-sheet Excel files and combine them into a single Excel workbook with multiple sheets. The Excel files are actually exported from crystal reports as individual files. Follo

  • SQL server 2008 trigger not working correct with multiple inserts 2010-05-03

    I've got the following trigger; CREATE TRIGGER trFLightAndDestination ON checkin_flight AFTER INSERT,UPDATE AS BEGIN IF NOT EXISTS ( SELECT 1 FROM Flight v INNER JOIN Inserted AS i ON i.flightnumber = v.flightnumber INNER JOIN checkin_destination AS

  • Combine multiple SQL fields into 1 output row 2010-08-16

    Having a SQL table like UserID |Attribute | Value 1 |Username | Marius 1 |Password | Fubar I want to create an output like: 1 | Marius | Fubar Maybe I'm just too tired to see it, doesn't sound too complicated, but I just can't seem to figure it out.

  • Combining multiple PDFs using PDFSharp 2011-02-14

    I am trying to combine multiple PDFs into a single PDF. The PDFs come from SSRS, from some LocalReports that I processed. I am using PDFSharp, because it is already used through out the project. However, the outputDocument.addPage(page) methods throw

  • Combine Multiple Queries into One 2011-03-31

    i have a stored procedure having above 3000 lines of code as below. its a validate business rules proc. There are similar queries for different columns from different tables. i dont know how do i combine these queries together so i can shrink this pr

  • Combining Multiple Commits Into One Prior To Push 2011-04-19

    This question pertains not only to how to accomplish this task, but to whether doing so is good or bad practice with Git. Consider that locally I do most work on the master branch, but I have created a topical branch I will call "topical_xFeature". I

  • combine multiple html fragment files with enlive, clojure 2011-09-19

    I have multiple html files, which is to be combined into a single html file. Those multiple files are like header, footer, etc, which are common to multiple files. I'm using enlive's html-resource method. but, that method inserting missing html tags

  • How do I combine multiple worksheets into one long consolidated list without copy paste? 2013-08-05

    How would you combine multiple worksheets with matching columns into a single long list? I do not want to copy and paste each worksheet because there are 100+ worksheets. Any Ideas? Thanks for your help in advance. --------------Solutions------------

  • Combine multiple worksheets in Excel 2010 2014-10-15

    I'm trying to combine data from multiple worksheets into a single worksheet. Many of the columns are the same; however, there are columns in each that only appear in that sheet. Example: All worksheets include Customer Name/Contact Name/Pilot Program

  • Is there any way to create multiple insert statements in a ms-access query? 2008-09-15

    I am using MS Access 2003. I want to run a lot of insert SQL statements in what is called 'Query' in MS Access. Is there any easy(or indeed any way) to do it? --------------Solutions------------- yes and no. You can't do: insert into foo (c1, c2, c3)

  • Can you combine multiple images into a single one using JavaScript? 2008-10-01

    I am wondering if there is a way to combine multiple images into a single image using only JavaScript. Is this something that Canvas will be able to do. The effect can be done with positing, but can you combine them into a single image for download?

  • How do I combine multiple BIRT reports 2008-10-23

    We currently have a whole suite of report designs that cover various parts of our app, and these reports are generated on demand by our users. I want to be able to bundle up several of these reports into a single report to return to the user. I initi

  • SQL: Combine multiple dynamic resultsets in one stored procedure 2008-12-29

    We're having a small issue and could use some help - we have the need to combine multiple resultsets from one stored procedure into one resultset (the limitation of our Java reporting framework). We've looked at Union, etc. but the problem is that th

  • Combining multiple config files in Visual Studio 2009-01-21

    I have a solution in Visual Studio 2008 which contains multiple C# projects. Each project has it's own config file (App.config and Settings.settings). This makes sense architecturally as each module is autonomous and is used in a number of different

  • Oracle: Combine multiple results in a subquery into a single comma-separated value 2009-01-29

    This question already has an answer here: How can I combine multiple rows into a comma-delimited list in Oracle? [duplicate] 11 answers I'm trying to convert a single-columned subquery into a command-separated VARCHAR-typed list of values. This is id

  • Retrieving auto-incremented column value from table where multiple insert/selects in single stored procedure 2009-05-29

    I have a stored procedure with multiple insert/select statements. Let's say I'm using the first insert to populate a "Manager" table. On insert, a ManagerId (incremented automatically) is added, but not referenced in the insert statement. I then wish

  • How do I collect and combine multiple arrays for calculation? 2009-06-26

    I am collecting the values for a specific column from a named_scope as follows: a = survey_job.survey_responses.collect(&:base_pay) This gives me a numeric array for example (1,2,3,4,5). I can then pass this array into various functions I have cr

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.068 (s). 11 q(s)