<?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 for Procbits</title>
	<atom:link href="http://procbits.com/comments/feed/" rel="self" type="application/rss+xml" />
	<link>http://procbits.com</link>
	<description>source code snippets and other random musings about software</description>
	<lastBuildDate>Mon, 26 Jul 2010 19:34:14 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>Comment on SQLite Bulk Insert In C#/.NET by Jez</title>
		<link>http://procbits.com/2009/09/08/sqlite-bulk-insert/#comment-46</link>
		<dc:creator>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>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>Comment on SQLite Bulk Insert In C#/.NET by Jez</title>
		<link>http://procbits.com/2009/09/08/sqlite-bulk-insert/#comment-45</link>
		<dc:creator>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>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>Comment on SQLite Bulk Insert In C#/.NET by Asanga</title>
		<link>http://procbits.com/2009/09/08/sqlite-bulk-insert/#comment-44</link>
		<dc:creator>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>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>Comment on SQLite Bulk Insert In C#/.NET by Jez</title>
		<link>http://procbits.com/2009/09/08/sqlite-bulk-insert/#comment-42</link>
		<dc:creator>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>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>
	<item>
		<title>Comment on SQLite Bulk Insert In C#/.NET by JP</title>
		<link>http://procbits.com/2009/09/08/sqlite-bulk-insert/#comment-40</link>
		<dc:creator>JP</dc:creator>
		<pubDate>Wed, 10 Mar 2010 07:46:02 +0000</pubDate>
		<guid isPermaLink="false">http://procbits.com/?p=30#comment-40</guid>
		<description>Hi Leon,

I don&#039;t, but it should be fairly easy to modify and for updates.

-JP</description>
		<content:encoded><![CDATA[<p>Hi Leon,</p>
<p>I don&#8217;t, but it should be fairly easy to modify and for updates.</p>
<p>-JP</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on SQLite Bulk Insert In C#/.NET by Leon</title>
		<link>http://procbits.com/2009/09/08/sqlite-bulk-insert/#comment-39</link>
		<dc:creator>Leon</dc:creator>
		<pubDate>Sat, 06 Mar 2010 11:34:09 +0000</pubDate>
		<guid isPermaLink="false">http://procbits.com/?p=30#comment-39</guid>
		<description>Hi JP,

Great job. This is exactly what I need. Now my inserts got wings. 200000 inserts under 3 seconds, amazing. I was wondering. Do You also have such magic code for doing updates?

ThanQ...</description>
		<content:encoded><![CDATA[<p>Hi JP,</p>
<p>Great job. This is exactly what I need. Now my inserts got wings. 200000 inserts under 3 seconds, amazing. I was wondering. Do You also have such magic code for doing updates?</p>
<p>ThanQ&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Deploying a Rails application on Ubuntu 8.04 LTS with Phusion Passenger and SQL Server 2005 by JP</title>
		<link>http://procbits.com/2009/03/10/deploying-a-rails-application-on-ubuntu-804-lts-with-phusion-passenger-and-sql-server-2005/#comment-14</link>
		<dc:creator>JP</dc:creator>
		<pubDate>Mon, 15 Jun 2009 06:49:34 +0000</pubDate>
		<guid isPermaLink="false">http://procbits.com/?p=5#comment-14</guid>
		<description>Jason, thanks for sharing your comments.
-JP</description>
		<content:encoded><![CDATA[<p>Jason, thanks for sharing your comments.<br />
-JP</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Deploying a Rails application on Ubuntu 8.04 LTS with Phusion Passenger and SQL Server 2005 by Jason M</title>
		<link>http://procbits.com/2009/03/10/deploying-a-rails-application-on-ubuntu-804-lts-with-phusion-passenger-and-sql-server-2005/#comment-13</link>
		<dc:creator>Jason M</dc:creator>
		<pubDate>Sat, 13 Jun 2009 03:44:07 +0000</pubDate>
		<guid isPermaLink="false">http://procbits.com/?p=5#comment-13</guid>
		<description>Fantastic write up! I was getting stuck before I saw this write-up. If I had not found this post, I think I may have gone insane. Everything simply works, no more dinking around with mssql 2005 nonsense for me! THANKS MUCH!</description>
		<content:encoded><![CDATA[<p>Fantastic write up! I was getting stuck before I saw this write-up. If I had not found this post, I think I may have gone insane. Everything simply works, no more dinking around with mssql 2005 nonsense for me! THANKS MUCH!</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Deploying a Rails application on Ubuntu 8.04 LTS with Phusion Passenger and SQL Server 2005 by JP</title>
		<link>http://procbits.com/2009/03/10/deploying-a-rails-application-on-ubuntu-804-lts-with-phusion-passenger-and-sql-server-2005/#comment-12</link>
		<dc:creator>JP</dc:creator>
		<pubDate>Thu, 28 May 2009 03:58:12 +0000</pubDate>
		<guid isPermaLink="false">http://procbits.com/?p=5#comment-12</guid>
		<description>Scott,

Glad it was useful to you.

Take care.

-JP</description>
		<content:encoded><![CDATA[<p>Scott,</p>
<p>Glad it was useful to you.</p>
<p>Take care.</p>
<p>-JP</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Deploying a Rails application on Ubuntu 8.04 LTS with Phusion Passenger and SQL Server 2005 by Scott Wolff</title>
		<link>http://procbits.com/2009/03/10/deploying-a-rails-application-on-ubuntu-804-lts-with-phusion-passenger-and-sql-server-2005/#comment-11</link>
		<dc:creator>Scott Wolff</dc:creator>
		<pubDate>Wed, 27 May 2009 18:38:03 +0000</pubDate>
		<guid isPermaLink="false">http://procbits.com/?p=5#comment-11</guid>
		<description>Thanks for the very complete write-up.  All the information in one place -- very helpful!</description>
		<content:encoded><![CDATA[<p>Thanks for the very complete write-up.  All the information in one place &#8212; very helpful!</p>
]]></content:encoded>
	</item>
</channel>
</rss>
