<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: SQLite Bulk Insert In C#/.NET</title>
	<atom:link href="http://procbits.com/2009/09/08/sqlite-bulk-insert/feed/" rel="self" type="application/rss+xml" />
	<link>http://procbits.com/2009/09/08/sqlite-bulk-insert/</link>
	<description>source code snippets and other random musings about software</description>
	<lastBuildDate>Wed, 01 Feb 2012 09:46:07 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: gpe</title>
		<link>http://procbits.com/2009/09/08/sqlite-bulk-insert/#comment-433</link>
		<dc:creator><![CDATA[gpe]]></dc:creator>
		<pubDate>Wed, 01 Feb 2012 09:46:07 +0000</pubDate>
		<guid isPermaLink="false">http://procbits.com/?p=30#comment-433</guid>
		<description><![CDATA[Awesome results of course. Well done JP!

I made it generic. Any suggestion? http://snipt.org/ylokj7]]></description>
		<content:encoded><![CDATA[<p>Awesome results of course. Well done JP!</p>
<p>I made it generic. Any suggestion? <a href="http://snipt.org/ylokj7" rel="nofollow">http://snipt.org/ylokj7</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nguyen Dai Nghia</title>
		<link>http://procbits.com/2009/09/08/sqlite-bulk-insert/#comment-304</link>
		<dc:creator><![CDATA[Nguyen Dai Nghia]]></dc:creator>
		<pubDate>Tue, 13 Sep 2011 23:50:26 +0000</pubDate>
		<guid isPermaLink="false">http://procbits.com/?p=30#comment-304</guid>
		<description><![CDATA[Thank you very much!]]></description>
		<content:encoded><![CDATA[<p>Thank you very much!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SQLite Bulkcopy</title>
		<link>http://procbits.com/2009/09/08/sqlite-bulk-insert/#comment-116</link>
		<dc:creator><![CDATA[SQLite Bulkcopy]]></dc:creator>
		<pubDate>Fri, 11 Mar 2011 11:54:58 +0000</pubDate>
		<guid isPermaLink="false">http://procbits.com/?p=30#comment-116</guid>
		<description><![CDATA[[...] Procbits &#8211; SQLite BulkCopy [...]]]></description>
		<content:encoded><![CDATA[<p>[...] Procbits &#8211; SQLite BulkCopy [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mervyn</title>
		<link>http://procbits.com/2009/09/08/sqlite-bulk-insert/#comment-115</link>
		<dc:creator><![CDATA[Mervyn]]></dc:creator>
		<pubDate>Mon, 07 Mar 2011 21:37:52 +0000</pubDate>
		<guid isPermaLink="false">http://procbits.com/?p=30#comment-115</guid>
		<description><![CDATA[Thank you very much for this excellent code... and to Jez for the small update.]]></description>
		<content:encoded><![CDATA[<p>Thank you very much for this excellent code&#8230; and to Jez for the small update.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: (droidelicious) snapshot on 2011 janvier 18 &#124; Javouhey&#039;s Blog</title>
		<link>http://procbits.com/2009/09/08/sqlite-bulk-insert/#comment-99</link>
		<dc:creator><![CDATA[(droidelicious) snapshot on 2011 janvier 18 &#124; Javouhey&#039;s Blog]]></dc:creator>
		<pubDate>Tue, 18 Jan 2011 15:39:19 +0000</pubDate>
		<guid isPermaLink="false">http://procbits.com/?p=30#comment-99</guid>
		<description><![CDATA[[...] code for bulk inserts           This entry was posted in Uncategorized and tagged android. Bookmark the permalink.    [...]]]></description>
		<content:encoded><![CDATA[<p>[...] code for bulk inserts           This entry was posted in Uncategorized and tagged android. Bookmark the permalink.    [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: campster</title>
		<link>http://procbits.com/2009/09/08/sqlite-bulk-insert/#comment-86</link>
		<dc:creator><![CDATA[campster]]></dc:creator>
		<pubDate>Tue, 02 Nov 2010 21:14:29 +0000</pubDate>
		<guid isPermaLink="false">http://procbits.com/?p=30#comment-86</guid>
		<description><![CDATA[Jez, I had the same problem. Thanks for the code]]></description>
		<content:encoded><![CDATA[<p>Jez, I had the same problem. Thanks for the code</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jez</title>
		<link>http://procbits.com/2009/09/08/sqlite-bulk-insert/#comment-46</link>
		<dc:creator><![CDATA[Jez]]></dc:creator>
		<pubDate>Mon, 26 Jul 2010 19:34:14 +0000</pubDate>
		<guid isPermaLink="false">http://procbits.com/?p=30#comment-46</guid>
		<description><![CDATA[strange, if I insert the code, it strips the generic notations, some invalid characters for comments probably... so the code above is incorrect...

Basically the main (only?) change was in the dictionary declaration:
private Dictionary&lt;string, SQLiteParameter&gt; m_parameters = new Dictionary&lt;string, SQLiteParameter&gt;();]]></description>
		<content:encoded><![CDATA[<p>strange, if I insert the code, it strips the generic notations, some invalid characters for comments probably&#8230; so the code above is incorrect&#8230;</p>
<p>Basically the main (only?) change was in the dictionary declaration:<br />
private Dictionary&lt;string, SQLiteParameter&gt; m_parameters = new Dictionary&lt;string, SQLiteParameter&gt;();</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jez</title>
		<link>http://procbits.com/2009/09/08/sqlite-bulk-insert/#comment-45</link>
		<dc:creator><![CDATA[Jez]]></dc:creator>
		<pubDate>Mon, 26 Jul 2010 19:30:23 +0000</pubDate>
		<guid isPermaLink="false">http://procbits.com/?p=30#comment-45</guid>
		<description><![CDATA[Asanga, my description was not very precise - I had to replace Dictionary by Dictionary
&lt;code&gt;
private Dictionary m_parameters = new Dictionary();
&lt;/code&gt;

The full code for a utility class to do sqllite bulk imports:
&lt;code&gt;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SQLite;
using System.Data;

namespace DataTool
{
    public class SQLiteBulkInsert
    {
        private SQLiteConnection m_dbCon;
        private SQLiteCommand m_cmd;
        private SQLiteTransaction m_trans;

        private Dictionary m_parameters = new Dictionary();

        private uint m_counter = 0;

        private string m_beginInsertText;

        public SQLiteBulkInsert(SQLiteConnection dbConnection, string tableName)
        {
            m_dbCon = dbConnection;
            m_tableName = tableName;

            StringBuilder query = new StringBuilder(255);
            query.Append(&quot;INSERT INTO [&quot;); query.Append(tableName); query.Append(&quot;] (&quot;);
            m_beginInsertText = query.ToString();
        }

        private bool m_allowBulkInsert = true;
        public bool AllowBulkInsert { get { return m_allowBulkInsert; } set { m_allowBulkInsert = value; } }

        public string CommandText
        {
            get
            {
                if (m_parameters.Count &lt; 1)
                    throw new SQLiteException(&quot;You must add at least one parameter.&quot;);

                StringBuilder sb = new StringBuilder(255);
                sb.Append(m_beginInsertText);

                foreach (string param in m_parameters.Keys)
                {
                    sb.Append(&#039;[&#039;);
                    sb.Append(param);
                    sb.Append(&#039;]&#039;);
                    sb.Append(&quot;, &quot;);
                }
                sb.Remove(sb.Length - 2, 2);

                sb.Append(&quot;) VALUES (&quot;);

                foreach (string param in m_parameters.Keys)
                {
                    sb.Append(m_paramDelim);
                    sb.Append(param);
                    sb.Append(&quot;, &quot;);
                }
                sb.Remove(sb.Length - 2, 2);

                sb.Append(&quot;)&quot;);

                return sb.ToString();
            }
        }

        private uint m_commitMax = 10000;
        public uint CommitMax { get { return m_commitMax; } set { m_commitMax = value; } }

        private string m_tableName;
        public string TableName { get { return m_tableName; } }

        private string m_paramDelim = &quot;:&quot;;
        public string ParamDelimiter { get { return m_paramDelim; } }

        public void AddParameter(string name, DbType dbType)
        {
            SQLiteParameter param = new SQLiteParameter(m_paramDelim + name, dbType);
            m_parameters.Add(name, param);
        }

        public void Flush()
        {
            try
            {
                if (m_trans != null)
                    m_trans.Commit();
            }
            catch (Exception ex) { throw new Exception(&quot;Could not commit transaction. See InnerException for more details&quot;, ex); }
            finally
            {
                if (m_trans != null)
                    m_trans.Dispose();

                m_trans = null;
                m_counter = 0;
            }
        }

        public void Insert(object[] paramValues)
        {
            if (paramValues.Length != m_parameters.Count)
                throw new Exception(&quot;The values array count must be equal to the count of the number of parameters.&quot;);

            m_counter++;

            if (m_counter == 1)
            {
                if (m_allowBulkInsert)
                    m_trans = m_dbCon.BeginTransaction();

                m_cmd = m_dbCon.CreateCommand();
                foreach (SQLiteParameter par in m_parameters.Values)
                    m_cmd.Parameters.Add(par);

                m_cmd.CommandText = this.CommandText;
            }

            int i = 0;
            foreach (SQLiteParameter par in m_parameters.Values)
            {
                par.Value = paramValues[i];
                i++;
            }

            m_cmd.ExecuteNonQuery();

            if (m_counter == m_commitMax)
            {
                try
                {
                    if (m_trans != null)
                        m_trans.Commit();
                }
                catch (Exception) { }
                finally
                {
                    if (m_trans != null)
                    {
                        m_trans.Dispose();
                        m_trans = null;
                    }

                    m_counter = 0;
                }
            }
        }
    }
}
&lt;/code&gt;]]></description>
		<content:encoded><![CDATA[<p>Asanga, my description was not very precise &#8211; I had to replace Dictionary by Dictionary<br />
<code><br />
private Dictionary m_parameters = new Dictionary();<br />
</code></p>
<p>The full code for a utility class to do sqllite bulk imports:<br />
<code><br />
using System;<br />
using System.Collections.Generic;<br />
using System.Linq;<br />
using System.Text;<br />
using System.Data.SQLite;<br />
using System.Data;</p>
<p>namespace DataTool<br />
{<br />
    public class SQLiteBulkInsert<br />
    {<br />
        private SQLiteConnection m_dbCon;<br />
        private SQLiteCommand m_cmd;<br />
        private SQLiteTransaction m_trans;</p>
<p>        private Dictionary m_parameters = new Dictionary();</p>
<p>        private uint m_counter = 0;</p>
<p>        private string m_beginInsertText;</p>
<p>        public SQLiteBulkInsert(SQLiteConnection dbConnection, string tableName)<br />
        {<br />
            m_dbCon = dbConnection;<br />
            m_tableName = tableName;</p>
<p>            StringBuilder query = new StringBuilder(255);<br />
            query.Append("INSERT INTO ["); query.Append(tableName); query.Append("] (");<br />
            m_beginInsertText = query.ToString();<br />
        }</p>
<p>        private bool m_allowBulkInsert = true;<br />
        public bool AllowBulkInsert { get { return m_allowBulkInsert; } set { m_allowBulkInsert = value; } }</p>
<p>        public string CommandText<br />
        {<br />
            get<br />
            {<br />
                if (m_parameters.Count &lt; 1)<br />
                    throw new SQLiteException(&quot;You must add at least one parameter.&quot;);</p>
<p>                StringBuilder sb = new StringBuilder(255);<br />
                sb.Append(m_beginInsertText);</p>
<p>                foreach (string param in m_parameters.Keys)<br />
                {<br />
                    sb.Append(&#039;[&#039;);<br />
                    sb.Append(param);<br />
                    sb.Append(&#039;]&#039;);<br />
                    sb.Append(&quot;, &quot;);<br />
                }<br />
                sb.Remove(sb.Length - 2, 2);</p>
<p>                sb.Append(&quot;) VALUES (&quot;);</p>
<p>                foreach (string param in m_parameters.Keys)<br />
                {<br />
                    sb.Append(m_paramDelim);<br />
                    sb.Append(param);<br />
                    sb.Append(&quot;, &quot;);<br />
                }<br />
                sb.Remove(sb.Length - 2, 2);</p>
<p>                sb.Append(&quot;)&quot;);</p>
<p>                return sb.ToString();<br />
            }<br />
        }</p>
<p>        private uint m_commitMax = 10000;<br />
        public uint CommitMax { get { return m_commitMax; } set { m_commitMax = value; } }</p>
<p>        private string m_tableName;<br />
        public string TableName { get { return m_tableName; } }</p>
<p>        private string m_paramDelim = &quot;:&quot;;<br />
        public string ParamDelimiter { get { return m_paramDelim; } }</p>
<p>        public void AddParameter(string name, DbType dbType)<br />
        {<br />
            SQLiteParameter param = new SQLiteParameter(m_paramDelim + name, dbType);<br />
            m_parameters.Add(name, param);<br />
        }</p>
<p>        public void Flush()<br />
        {<br />
            try<br />
            {<br />
                if (m_trans != null)<br />
                    m_trans.Commit();<br />
            }<br />
            catch (Exception ex) { throw new Exception(&quot;Could not commit transaction. See InnerException for more details&quot;, ex); }<br />
            finally<br />
            {<br />
                if (m_trans != null)<br />
                    m_trans.Dispose();</p>
<p>                m_trans = null;<br />
                m_counter = 0;<br />
            }<br />
        }</p>
<p>        public void Insert(object[] paramValues)<br />
        {<br />
            if (paramValues.Length != m_parameters.Count)<br />
                throw new Exception(&quot;The values array count must be equal to the count of the number of parameters.&quot;);</p>
<p>            m_counter++;</p>
<p>            if (m_counter == 1)<br />
            {<br />
                if (m_allowBulkInsert)<br />
                    m_trans = m_dbCon.BeginTransaction();</p>
<p>                m_cmd = m_dbCon.CreateCommand();<br />
                foreach (SQLiteParameter par in m_parameters.Values)<br />
                    m_cmd.Parameters.Add(par);</p>
<p>                m_cmd.CommandText = this.CommandText;<br />
            }</p>
<p>            int i = 0;<br />
            foreach (SQLiteParameter par in m_parameters.Values)<br />
            {<br />
                par.Value = paramValues[i];<br />
                i++;<br />
            }</p>
<p>            m_cmd.ExecuteNonQuery();</p>
<p>            if (m_counter == m_commitMax)<br />
            {<br />
                try<br />
                {<br />
                    if (m_trans != null)<br />
                        m_trans.Commit();<br />
                }<br />
                catch (Exception) { }<br />
                finally<br />
                {<br />
                    if (m_trans != null)<br />
                    {<br />
                        m_trans.Dispose();<br />
                        m_trans = null;<br />
                    }</p>
<p>                    m_counter = 0;<br />
                }<br />
            }<br />
        }<br />
    }<br />
}<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Asanga</title>
		<link>http://procbits.com/2009/09/08/sqlite-bulk-insert/#comment-44</link>
		<dc:creator><![CDATA[Asanga]]></dc:creator>
		<pubDate>Mon, 26 Jul 2010 12:37:34 +0000</pubDate>
		<guid isPermaLink="false">http://procbits.com/?p=30#comment-44</guid>
		<description><![CDATA[Hi Jez,

could you send me your changes (&quot;(ie replaced Dictionary with Dictionary for m_parameters&quot;)...
I have the same problems but seem to be unable to selve them ;(

Need the bulk insert cause I have way more then 20&#039;&#039; rows and in memory the operations are much faster then on the server - but it doesn&#039;t help me if I have to wait so long to import them...
Thanks a lot!]]></description>
		<content:encoded><![CDATA[<p>Hi Jez,</p>
<p>could you send me your changes (&#8220;(ie replaced Dictionary with Dictionary for m_parameters&#8221;)&#8230;<br />
I have the same problems but seem to be unable to selve them ;(</p>
<p>Need the bulk insert cause I have way more then 20&#8221; rows and in memory the operations are much faster then on the server &#8211; but it doesn&#8217;t help me if I have to wait so long to import them&#8230;<br />
Thanks a lot!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jez</title>
		<link>http://procbits.com/2009/09/08/sqlite-bulk-insert/#comment-42</link>
		<dc:creator><![CDATA[Jez]]></dc:creator>
		<pubDate>Thu, 10 Jun 2010 17:43:08 +0000</pubDate>
		<guid isPermaLink="false">http://procbits.com/?p=30#comment-42</guid>
		<description><![CDATA[Great stuff - what more could I wish for. A class that can be used in a generic manner - even with the test class... 

Had to make a few changes (ie replaced Dictionary with Dictionary for m_parameters as the compiler was complaining about it but apart from that it works - Thanks mate!]]></description>
		<content:encoded><![CDATA[<p>Great stuff &#8211; what more could I wish for. A class that can be used in a generic manner &#8211; even with the test class&#8230; </p>
<p>Had to make a few changes (ie replaced Dictionary with Dictionary for m_parameters as the compiler was complaining about it but apart from that it works &#8211; Thanks mate!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

