# Help on SQLITE3-ruby (1.2.3) Windows problem

**URL:** <https://rubytalk.org/t/help-on-sqlite3-ruby-1-2-3-windows-problem/51340>\
**Category:** ruby-talk\
**Created:** [24 January 2009 05:08 UTC](https://rubytalk.org/t/help-on-sqlite3-ruby-1-2-3-windows-problem/51340 "2009-01-24T05:08:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![John2](https://avatars.discourse-cdn.com/v4/letter/j/f0a364/32.png) [@John2](https://rubytalk.org/u/John2)\
**Post date:** [24 January 2009 05:08 UTC](https://rubytalk.org/t/help-on-sqlite3-ruby-1-2-3-windows-problem/51340/1 "2009-01-24T05:08:09Z")

</div>

Your Help please:

I have installed sqlite3 in directory : c:\tools\sqlite3\  
and performed gem install : gem install sqlite3-ruby-1.2.3-  
mswin32.gem

test2.rb program:

> **···**
>
> #--------------------------------------------------------------  
> require 'rubygems'  
> require 'sqlite3/database'  
> &nbsp;&nbsp;require 'sqlite3'
> 
> &nbsp;&nbsp;File.delete "test.db" rescue nil
> 
> &nbsp;&nbsp;&nbsp;db = SQLite3::Database.new( "test.db" )  
> sql = \<\<SQL  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;create table the\_table (  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a varchar2(30),  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b varchar2(30)  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;);
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;insert into the\_table values ( 'one', 'two' );  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;insert into the\_table values ( 'three', 'four' );  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;insert into the\_table values ( 'five', 'six' );  
> SQL
> 
> &nbsp;&nbsp;&nbsp;db.execute\_batch( sql )
> 
> db.execute( "select \* from the\_table" ) do |row|  
> &nbsp;&nbsp;&nbsp;&nbsp;p row  
> &nbsp;&nbsp;end  
> #-----------------------------------------------------------
> 
> \*\* upon executing the program: ruby test2.rb
> 
> &nbsp;&nbsp;&nbsp;it can not file sqlite3.dll
> 
> But when I move aa copy of sqlite3.dll into the same directory as  
> test2.rb  
> then everything runs OK.
> 
> Question: How do I condition sqlite3-ruby to load the sqlite3.dll  
> from the directory c:\tools\sqlite3?
> 
> Thanks for your assistance,  
> John

---

<div class="post-metadata">

**Author:** ![Bosko\_Ivanisevic](https://avatars.discourse-cdn.com/v4/letter/b/43a26b/32.png) [@Bosko\_Ivanisevic](https://rubytalk.org/u/Bosko_Ivanisevic)\
**Post date:** [24 January 2009 09:08 UTC](https://rubytalk.org/t/help-on-sqlite3-ruby-1-2-3-windows-problem/51340/2 "2009-01-24T09:08:05Z")

</div>

Put c:\tools\sqlite3 in the PATH environment variable.

> **···**
>
> On Jan 24, 6:08 am, jhs...@gmail.com wrote:
> 
> > Your Help please:
> > 
> > I have installed sqlite3 in directory : c:\tools\sqlite3\  
> > and performed gem install : gem install sqlite3-ruby-1.2.3-  
> > mswin32.gem
> > 
> > test2.rb program:  
> > #--------------------------------------------------------------  
> > require 'rubygems'  
> > require 'sqlite3/database'  
> > require 'sqlite3'
> > 
> > File.delete "test.db" rescue nil
> > 
> > db = SQLite3::Database.new( "test.db" )  
> > sql = \<\<SQL  
> > create table the\_table (  
> > a varchar2(30),  
> > b varchar2(30)  
> > );
> > 
> > ```
> > insert into the\_table values \( &#39;one&#39;, &#39;two&#39; \);
> > insert into the\_table values \( &#39;three&#39;, &#39;four&#39; \);
> > insert into the\_table values \( &#39;five&#39;, &#39;six&#39; \);
> > 
> > ```
> > 
> > SQL
> > 
> > db.execute\_batch( sql )
> > 
> > db.execute( "select \* from the\_table" ) do |row|  
> > p row  
> > end  
> > #-----------------------------------------------------------
> > 
> > \*\* upon executing the program: ruby test2.rb
> > 
> > it can not file sqlite3.dll
> > 
> > But when I move aa copy of sqlite3.dll into the same directory as  
> > test2.rb  
> > then everything runs OK.
> > 
> > Question: How do I condition sqlite3-ruby to load the sqlite3.dll  
> > from the directory c:\tools\sqlite3?
> > 
> > Thanks for your assistance,  
> > John

---

<div class="post-metadata">

**Author:** ![Luis\_Lavena1](https://avatars.discourse-cdn.com/v4/letter/l/f08c70/32.png) [@Luis\_Lavena1](https://rubytalk.org/u/Luis_Lavena1)\
**Post date:** [24 January 2009 16:03 UTC](https://rubytalk.org/t/help-on-sqlite3-ruby-1-2-3-windows-problem/51340/3 "2009-01-24T16:03:08Z")

</div>

For Windows to load shared libraries (.dll) needs to find those in any  
of the directories of PATH, including the directory where the  
executable (ruby.exe) is located.

Now, this is similar to LD\_LIBRARY\_PATH on \*nix, but playing with it  
is considered harmful [1]

sqlite3-ruby is built on Windows against the binary version of SQLite,  
which requires the dll to be found in the PATH.

One alternative is add c:\tools\sqlite3 to the PATH:

SET PATH=%PATH%;C:\tools\sqlite3

The other alternative is put sqlite3.dll binary in the Ruby folder.

[1] [Should I set LD\_LIBRARY\_PATH?](http://linuxmafia.com/faq/Admin/ld-lib-path.html)

HTH,

> **···**
>
> On Jan 24, 3:08 am, jhs...@gmail.com wrote:
> 
> > Your Help please:
> > 
> > I have installed sqlite3 in directory : c:\tools\sqlite3\  
> > and performed gem install : gem install sqlite3-ruby-1.2.3-  
> > mswin32.gem
> > 
> > test2.rb program:  
> > #--------------------------------------------------------------  
> > require 'rubygems'  
> > require 'sqlite3/database'  
> > require 'sqlite3'
> > 
> > File.delete "test.db" rescue nil
> > 
> > db = SQLite3::Database.new( "test.db" )  
> > sql = \<\<SQL  
> > create table the\_table (  
> > a varchar2(30),  
> > b varchar2(30)  
> > );
> > 
> > ```
> > insert into the\_table values \( &#39;one&#39;, &#39;two&#39; \);
> > insert into the\_table values \( &#39;three&#39;, &#39;four&#39; \);
> > insert into the\_table values \( &#39;five&#39;, &#39;six&#39; \);
> > 
> > ```
> > 
> > SQL
> > 
> > db.execute\_batch( sql )
> > 
> > db.execute( "select \* from the\_table" ) do |row|  
> > p row  
> > end  
> > #-----------------------------------------------------------
> > 
> > \*\* upon executing the program: ruby test2.rb
> > 
> > it can not file sqlite3.dll
> > 
> > But when I move aa copy of sqlite3.dll into the same directory as  
> > test2.rb  
> > then everything runs OK.
> > 
> > Question: How do I condition sqlite3-ruby to load the sqlite3.dll  
> > from the directory c:\tools\sqlite3?
> > 
> > Thanks for your assistance,  
> > John
> 
> --  
> Luis Lavena

---

<div class="post-metadata">

**Author:** ![Jeremy\_Hinegardner](https://avatars.discourse-cdn.com/v4/letter/j/65b543/32.png) [@Jeremy\_Hinegardner](https://rubytalk.org/u/Jeremy_Hinegardner)\
**Post date:** [24 January 2009 18:43 UTC](https://rubytalk.org/t/help-on-sqlite3-ruby-1-2-3-windows-problem/51340/4 "2009-01-24T18:43:30Z")

</div>

Another option is to use Amalgalite which embeds SQLite in the ruby extension,  
no need to download the sqlite3.dll separately. If you are using sqlite  
directly then that is a good option. if you need to use ActiveRecord or Sequel  
or something like that, the drivers for ORM's do not exist, yet.

enjoy,

-jeremy

> **···**
>
> On Sun, Jan 25, 2009 at 01:03:08AM +0900, Luis Lavena wrote:
> 
> > On Jan 24, 3:08?am, jhs...@gmail.com wrote:  
> > \> Your Help please:  
> > \>  
> > \> I have installed sqlite3 in directory : ?c:\tools\sqlite3\  
> > \> and performed gem install : ?gem install sqlite3-ruby-1.2.3-  
> > \> mswin32.gem  
> > \>  
> > \> test2.rb ?program:  
> > \> #--------------------------------------------------------------  
> > \> require 'rubygems'  
> > \> require 'sqlite3/database'  
> > \> ? require 'sqlite3'  
> > \>  
> > \> ? File.delete "test.db" rescue nil  
> > \>  
> > \> ? ?db = SQLite3::Database.new( "test.db" )  
> > \> ?sql = \<\<SQL  
> > \> ? ? ?create table the\_table (  
> > \> ? ? ? ?a varchar2(30),  
> > \> ? ? ? ?b varchar2(30)  
> > \> ? ? ?);  
> > \>  
> > \> ? ? ?insert into the\_table values ( 'one', 'two' );  
> > \> ? ? ?insert into the\_table values ( 'three', 'four' );  
> > \> ? ? ?insert into the\_table values ( 'five', 'six' );  
> > \> SQL  
> > \>  
> > \> ? ?db.execute\_batch( sql )  
> > \>  
> > \> db.execute( "select \* from the\_table" ) do |row|  
> > \> ? ? p row  
> > \> ? end  
> > \> #-----------------------------------------------------------  
> > \>  
> > \> \*\* upon executing the program: ?ruby test2.rb  
> > \>  
> > \> ? ?it can not file sqlite3.dll  
> > \>  
> > \> But when I move aa copy of sqlite3.dll into the same directory as  
> > \> test2.rb  
> > \> then everything runs OK.  
> > \>  
> > \> Question: ?How do I condition sqlite3-ruby to load the sqlite3.dll  
> > \> from the directory c:\tools\sqlite3?  
> > \>  
> > \> Thanks for your assistance,  
> > \> John
> > 
> > For Windows to load shared libraries (.dll) needs to find those in any  
> > of the directories of PATH, including the directory where the  
> > executable (ruby.exe) is located.
> > 
> > Now, this is similar to LD\_LIBRARY\_PATH on \*nix, but playing with it  
> > is considered harmful [1]
> > 
> > sqlite3-ruby is built on Windows against the binary version of SQLite,  
> > which requires the dll to be found in the PATH.
> > 
> > One alternative is add c:\tools\sqlite3 to the PATH:
> > 
> > SET PATH=%PATH%;C:\tools\sqlite3
> > 
> > The other alternative is put sqlite3.dll binary in the Ruby folder.
> 
> # --
> 
> Jeremy Hinegardner jeremy@hinegardner.org
