[ANN] SQLite/Ruby 2.0.1 BETA

J

Jamis Buck

Another beta release for SQLite/Ruby is available, hard on the heels of
the last release.

project: http://rubyforge.org/projects/sqlite-ruby
usage FAQ: http://sqlite-ruby.rubyforge.org/faq.html
api: http://sqlite-ruby.rubyforge.org

This release should be simpler for people to build for Windows. I've
removed the pesky "experimental" APIs and replaced the "sqlite_bind"
interface with one written purely in Ruby. (See the FAQ for information
on using bind variables and placeholders in your SQL statements.)

I would encourage those of you that are interested in this library to
look over the FAQ (link above), since it talks about the new ways of
querying information via this library. Also, feel free to suggest more
content for it.

A pre-built Windows binary is probably forthcoming...just need to touch
bases with Justin...

- Jamis

--
Jamis Buck
(e-mail address removed)
http://www.jamisbuck.org/jamis

"I use octal until I get to 8, and then I switch to decimal."
 
V

Vincent Isambart

Hi,

Great job for SQLite/Ruby. It is really great to be able to prepare
statements. I have played a little with it today and I have a few
remarks:
- when you have a statement that does inserts, you must call next on
the result set to really execute the statement: stmt.execute { |result|
result.next } # the statement is not executed if next is not called
It would be great to have it in the FAQ, as it took me some time to
understand why my inserts where not working.
- a little mistake in the doc SQLite::Statement doc:
stmt.bind_variables( 15, "hello" ) should be stmt.bind_params( 15,
"hello" )
(it was not updated for 2.0.1)

Continue you great work ^o^

Vincent Isambart
 
J

Jamis Buck

Vincent said:
Hi,

Great job for SQLite/Ruby. It is really great to be able to prepare
statements. I have played a little with it today and I have a few remarks:
- when you have a statement that does inserts, you must call next on the
result set to really execute the statement: stmt.execute { |result|
result.next } # the statement is not executed if next is not called
It would be great to have it in the FAQ, as it took me some time to
understand why my inserts where not working.
- a little mistake in the doc SQLite::Statement doc:
stmt.bind_variables( 15, "hello" ) should be stmt.bind_params( 15,
"hello" )
(it was not updated for 2.0.1)

Continue you great work ^o^

Vincent Isambart

Thanks, Vincent! Great feedback--I'll get your suggestions incorporated
into the documentation.

Also, would a Statement#execute_immediate method help? It would not take
a block and would always return +nil+, but then you wouldn't have to do
an explicit "next" on the result set.

- Jamis

--
Jamis Buck
(e-mail address removed)
http://www.jamisbuck.org/jamis

"I use octal until I get to 8, and then I switch to decimal."
 
V

Vincent Isambart

Also, would a Statement#execute_immediate method help? It would not
take a block and would always return +nil+, but then you wouldn't have
to do an explicit "next" on the result set.
It would be great ^o^
I love decreasing the length of my code ;o)
 
J

Justin Rudd

- when you have a statement that does inserts, you must call next on the
result set to really execute the statement: stmt.execute { |result|
result.next } # the statement is not executed if next is not called
It would be great to have it in the FAQ, as it took me some time to
understand why my inserts where not working.

I did the following...

require 'sqlite'

db = SQLite::Database.new( 'test.db' )
db.execute( "create table test ( pkid INTEGER, name VARCHAR(15) )")

db.execute( "insert into test (pkid, name) values (1, 'justin')")

db.execute( "select * from test" ).each { |row|
p row
}

db.execute( "drop table test" )
db.close()

And the inserts worked without having to call result.next. Am I
missing something?
 
J

Justin Rudd

HA! Never fails. 2 minutes after I hit send I realize you are
talking about Statement not Database. Doh! Ignore the man behind the
curtain...
 
C

Carl Youngblood

What about searching to see if there is no SELECT in the SQL and
executing it immediately if not? Too kludgy?
 
J

Jamis Buck

Carl said:
What about searching to see if there is no SELECT in the SQL and
executing it immediately if not? Too kludgy?

hmmm, yah, I think so. Consider this statement:

insert into a_table ( a, b, c )
select x, y, z from b_table where...

It has a select in it...but returns no rows. You could then say, only
those that start with select... but then you have to worry about
comments... and there are SQLite commands that work like a select, but
don't use the select keyword ("pragma table_info...", etc.).

In other words, there no simple answer for determining automatically
whether a query should use "execute immediate" or just "execute". :(

Anyway, the developer will typically know whether the query they are
executing returns rows that they are interested in or not. If not, use
execute_immediate. If they want the rows, use execute (and friends).

- Jamis


--
Jamis Buck
(e-mail address removed)
http://www.jamisbuck.org/jamis

"I use octal until I get to 8, and then I switch to decimal."
 
C

Carl Youngblood

You're right of course. Thanks for pointing that out. I obviously
hadn't explored the idea very far.

On the other hand, I'm wondering why you would want to wait until next
is called before executing a statement. If you've called execute, you
obviously intend to run it. Why not always execute the statement and
only do stuff inside next that applies to result sets? It seems like
there should be a programatic way to get around this without making it
necessary for the developer to call two different functions. Of
course I'm approaching this more abstractly, not having looked at the
actual code but simply wondering why something has to be a certain
way.
 
J

Jamis Buck

Carl said:
You're right of course. Thanks for pointing that out. I obviously
hadn't explored the idea very far.

On the other hand, I'm wondering why you would want to wait until next
is called before executing a statement. If you've called execute, you
obviously intend to run it. Why not always execute the statement and
only do stuff inside next that applies to result sets? It seems like
there should be a programatic way to get around this without making it
necessary for the developer to call two different functions. Of
course I'm approaching this more abstractly, not having looked at the
actual code but simply wondering why something has to be a certain
way.

A good question. Right now, it is the way it is because that's the way
the underlying SQLite library works.

1) You "compile" your SQL statement into a "virtual machine".
(Corresponds roughly to the Ruby binding's "Statement#execute" method.)

2) You "step" through your VM one record at a time, with each step
returning the row that was fetched. (ResultSet#next)

3) You "finalize" the VM when you are done. (ResultSet#close)

Note that this issue only arises when using result sets directly, from
statements with side effects (typically DDL statements). Most queries
can be performed without that level of granularity. In fact, with the
new "execute_immediate" interface I added, you should never need to
bother with result sets for DDL statements. In all other cases, you're
going to call #next to get the next (or first) row anyway.

Still, I'm willing to listen to my users. It would certainly be possible
for the "execute" method to issue a step call on the underlying virtual
machine, caching the returned row. Subsequent calls to #next would fetch
(and cache) the next row, and return the last cached row. It would work
(and in fact is what you would need to do to implement a DBI interface
for this binding), but it seems a bit complicated, don't you think? And
99% of the time, you're never going to be using that level of the
interface anyway.

Anyway, opinions?


--
Jamis Buck
(e-mail address removed)
http://www.jamisbuck.org/jamis

"I use octal until I get to 8, and then I switch to decimal."
 
Z

Zach Dennis

Ok, despite a to late of a night.... last night and some wasted posts (i
should have just went to bed and waited until today to do it) I finally
got Arrow-0.1.0 to work. So here are my findings of the installation and
configuration process:

Installation Requires These Steps:
------------------------------------------------------------

0 - Be sure to have the online manual for arrow pulled up and read it!
(http://www.rubycrafters.com/arrow-manul/). I didn't and I ended up
with a lot of stupid questions. (Thanks daz for being nice about
pointing all of the answers out to me...although you probably could have
told me to RTFM)

0.5 - If you don't have Apache you will need to get. You will need
version 1.3 or higher.

1 - Download, untar Arrow, go into redist/ directory in the Arrow-0.1.0/
directory and untar all tar.gz files and run the install.rb for each
one. There are three free standing files: hashslice.rb, crosscase.rb and
delimscanner.rb in the redist/ directory. I copied these to the
/usr/local/lib/ruby/site_ruby/1.8/ directory. (HashSlice is mentioned on
the Online Manual page for Arrow, but I didn't see anything about the
other two...any one care to comment on them?) Now go back into the
Arrow-0.1.0/ directory and run the install.rb from here. Also check to
see if you have the strscan.rb file for you ruby installation. If you
don't you will need it (It does not come with the ruby debian package).

2 - If you don't have mod_ruby you will need to get it,
http://modruby.net. Download, compile and install.

3 - If you dont' hvae a libapreq shared library you will to get it,
http://httpd.apache.org/apreq/ . I downloaded from the ASF mirror (not
CPAN mirror) and downloaded version 1.3. Untar, and compile.
- ./configure --with-apache-includes=/usr/include/apache-1.3 ; make
; make install

- libapreq.so.1 was installed in my /usr/local/lib, check your
/etc/ld.so.conf file and see if the directory to where libapreq.so.1 is
listed. If it isn't then add it and run the command "ldconfig".

4 - I then moved the Arrow-0.1.0/ directory to be /etc/arrow/ directory


Configuration
------------------------

0 - Follow the configuration instructions at
http://www.rubycrafters.com/arrow-manual/config.html. I had pasted my
Apache portion of the configuration inside of a VirtualHost. The
RubyAddPath value should be "/etc/arrow/lib" if you followed step 4 from
above. The RubyHandler was set to:
"Arrow::Dispatcher::create('/etc/arrow/demo.cfg')"

0.5 - Then I had to modify the demo.cfg file and add to the path section
under applets: - "/etc/arrow/applets" . Also to note that you need to
make sure you use 2 spaces to indent each section of the configuration
file deeper you go. I used tabs and it didn't work. (This may be a
simple YAML requirement? but I have never used YAML so I didn't know)

1 - Restart Apache. Try to go to a URL to access the link:
http://localhost/tutorial/hello ). If it doesn't work check your apache
error.log


And that is how I got the Arrow-0.1.0 up and going with the samples. Now
on to testing the framework with some custom stuff.

One thing that would be nice is for better Error documentation on
Arrow's errors. I have no clue what "Applet returned false, OK Status =
-1" means in the apache error.log file. Is that a missing file? A
malformed applet file? etc... Most of the errors were because of my own
lack of patience and reading, but I hope that this post will help others.

Also it'd be nice if the README file or the online manual would state
how-to run the demo/samples all you need to do are these steps: boom,
bang, bing! Then I would be much more inclined to reading the Tutorial
page on the Arrow web site and put 2 and 2 together. It is often easier
to see an end result and then go back and figure out how it got there,
then it is to read about it all upfront and have to figure out how the
pieces interact. Just another perspective.


Zach
 
D

David Ross

So what do you plan on creating with arrow, and could
you tell after you finish how it turned out?

--David Ross

--- Zach Dennis said:
Ok, despite a to late of a night.... last night and
some wasted posts (i
should have just went to bed and waited until today
to do it) I finally
got Arrow-0.1.0 to work. So here are my findings of
the installation and
configuration process:

Installation Requires These Steps:
------------------------------------------------------------

0 - Be sure to have the online manual for arrow
pulled up and read it!
(http://www.rubycrafters.com/arrow-manul/). I
didn't and I ended up
with a lot of stupid questions. (Thanks daz for
being nice about
pointing all of the answers out to me...although you
probably could have
told me to RTFM)

0.5 - If you don't have Apache you will need to get.
You will need
version 1.3 or higher.

1 - Download, untar Arrow, go into redist/ directory
in the Arrow-0.1.0/
directory and untar all tar.gz files and run the
install.rb for each
one. There are three free standing files:
hashslice.rb, crosscase.rb and
delimscanner.rb in the redist/ directory. I copied
these to the
/usr/local/lib/ruby/site_ruby/1.8/ directory.
(HashSlice is mentioned on
the Online Manual page for Arrow, but I didn't see
anything about the
other two...any one care to comment on them?) Now go
back into the
Arrow-0.1.0/ directory and run the install.rb from
here. Also check to
see if you have the strscan.rb file for you ruby
installation. If you
don't you will need it (It does not come with the
ruby debian package).

2 - If you don't have mod_ruby you will need to get
it,
http://modruby.net. Download, compile and install.

3 - If you dont' hvae a libapreq shared library you
will to get it,
http://httpd.apache.org/apreq/ . I downloaded from
the ASF mirror (not
CPAN mirror) and downloaded version 1.3. Untar, and
compile.
- ./configure
--with-apache-includes=/usr/include/apache-1.3 ;
make
; make install

- libapreq.so.1 was installed in my
/usr/local/lib, check your
/etc/ld.so.conf file and see if the directory to
where libapreq.so.1 is
listed. If it isn't then add it and run the command
"ldconfig".

4 - I then moved the Arrow-0.1.0/ directory to be
/etc/arrow/ directory


Configuration
------------------------

0 - Follow the configuration instructions at
http://www.rubycrafters.com/arrow-manual/config.html.
I had pasted my
Apache portion of the configuration inside of a
VirtualHost. The
RubyAddPath value should be "/etc/arrow/lib" if you
followed step 4 from
above. The RubyHandler was set to:
"Arrow::Dispatcher::create('/etc/arrow/demo.cfg')"

0.5 - Then I had to modify the demo.cfg file and add
to the path section
under applets: - "/etc/arrow/applets" . Also to note
that you need to
make sure you use 2 spaces to indent each section of
the configuration
file deeper you go. I used tabs and it didn't work.
(This may be a
simple YAML requirement? but I have never used YAML
so I didn't know)

1 - Restart Apache. Try to go to a URL to access
the link:
http://localhost/tutorial/hello ). If it doesn't
work check your apache
error.log


And that is how I got the Arrow-0.1.0 up and going
with the samples. Now
on to testing the framework with some custom stuff.

One thing that would be nice is for better Error
documentation on
Arrow's errors. I have no clue what "Applet returned
false, OK Status =
-1" means in the apache error.log file. Is that a
missing file? A
malformed applet file? etc... Most of the errors
were because of my own
lack of patience and reading, but I hope that this
post will help others.

Also it'd be nice if the README file or the online
manual would state
how-to run the demo/samples all you need to do are
these steps: boom,
bang, bing! Then I would be much more inclined to
reading the Tutorial
page on the Arrow web site and put 2 and 2 together.
It is often easier
to see an end result and then go back and figure out
how it got there,
then it is to read about it all upfront and have to
figure out how the
pieces interact. Just another perspective.


Zach




__________________________________
Do you Yahoo!?
Yahoo! Mail is new and improved - Check it out!
http://promotions.yahoo.com/new_mail
 
Z

Zach Dennis

David said:
So what do you plan on creating with arrow,
My brother owns a basketball camp in Michigan and he has contacts with
other College coaches who run even more basketball camps. They are
interested in getting nice websites for their camps, but they want an
all or nothing deal as far as functionality goes. So I thought Arrow
might work perfectly for the features they requested:

User Authentication for adminstrators of the camps for the ability to
perform:
- ability to update camp information from their home or office at
any time
- ability to perform online registration for each camp and for the
ability to
track each registered camper and whether payment was received or not
- ability to add announcements to the web site, or other notes from
home or office on the fly
- ability to track donations to the camp

I could have chosen a different tool for the job but I think Arrow will
give me the kind of flexibility and extensibility that I need to be able
to support these camps and potentially other types of camps all from
within one framework. And I have a few more hidden expectations of
Arrow, but I dont' want to mention those until I learn more about Arrow.
and could
you tell after you finish how it turned out?
For all of the wasted posts I've added to the list for simple or
nonsense questions....you can be sure that once I have something of
"usefulness" it will be posted. ;)

Zach
 
M

Michael Granger

--Apple-Mail-2-740839531
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset=US-ASCII; format=flowed

First of all, I must apologize for my lack of prompt reply to this (and
your other emails). I've been traveling, and haven't kept up with
ruby-talk as faithfully as I should have. Thanks to daz and others who
have replied in my absence.

There are three free standing files: hashslice.rb, crosscase.rb and
delimscanner.rb in the redist/ directory. I copied these to the
/usr/local/lib/ruby/site_ruby/1.8/ directory. (HashSlice is mentioned
on the Online Manual page for Arrow, but I didn't see anything about
the other two...any one care to comment on them?)

The only one that is required for normal operation is 'hashslice.rb'.
'delimscanner.rb' is no longer used, so I'll remove it from the redist/
directory. 'crosscase.rb' was only required by 'delimscanner.rb', so
I'll remove that, too. Thanks for mentioning this.
0.5 - Then I had to modify the demo.cfg file and add to the path
section under applets: - "/etc/arrow/applets" . Also to note that you
need to make sure you use 2 spaces to indent each section of the
configuration file deeper you go. I used tabs and it didn't work.
(This may be a simple YAML requirement? but I have never used YAML so
I didn't know)

This has tripped me up in the past, too, but I don't quite know how to
detect when it's happened. I'll spend some time with the YAML modules
and see if I can't try to warn about this situation.
One thing that would be nice is for better Error documentation on
Arrow's errors. I have no clue what "Applet returned false, OK Status
= -1" means in the apache error.log file. Is that a missing file? A
malformed applet file? etc... Most of the errors were because of my
own lack of patience and reading, but I hope that this post will help
others.

I've tried to make the actual errors self-explanatory, but I'll
continue to work on this. One thing I could improve on is trying to
detect and provide suggestions for possible fixes for things that look
like errors (like no applets found, invalid YAML, etc.). The message
you cited isn't an error, but you're right: the message is sorely
lacking in useful content for anyone that isn't familiar with the
internals of Arrow.

We intend to alleviate this somewhat by finishing the tutorial part of
the documentation. While the "Applet" part of the tutorial does mention
the above situation:

"Returning a non-true value causes a DECLINED status
to be sent back to Apache. This can be used to pass
control to a further handler if the action determines
it cannot handle the request."

it assumes you've done mod_ruby development before and know about
Apache status codes, which isn't a valid assumption. We'll try to do
better. =:)
Also it'd be nice if the README file or the online manual would state
how-to run the demo/samples all you need to do are these steps: boom,
bang, bing! Then I would be much more inclined to reading the Tutorial
page on the Arrow web site and put 2 and 2 together. It is often
easier to see an end result and then go back and figure out how it got
there, then it is to read about it all upfront and have to figure out
how the pieces interact. Just another perspective.

The installation script should do all this for you: it can install demo
applets and templates in a directory of your choice, create an
appropriate config file for your installation, and then generates and
outputs an appropriate section for your httpd.conf. Did this not work
for you?

One of the things it doesn't do is attempt to install the stuff in
redist/ for you or check your mod_ruby installation. It would appear
from your installation attempts as if this might be valuable. I'm a bit
leery of doing either because of cross-platform concerns, but I guess I
could do it for UNIXish installations and see where that gets us.

I'll also create an INSTALL file with the information from the online
manual in it and add that to the distribution.

Thanks so much for your posts to this list. Ease of installation is one
of the things I had hoped to work out before the 1.0 release, and your
posts have illuminated some of the weak points in the documentation.
Any additional suggestions or comments you have would be equally
appreciated.

--
Michael Granger <[email protected]>
Rubymage, Believer, Architect
The FaerieMUD Consortium <http://www.FaerieMUD.org/>
12383406064495388618631689469409153107.to_s(36).tr('z',' ')

--Apple-Mail-2-740839531
content-type: application/pgp-signature; x-mac-type=70674453;
name=PGP.sig
content-description: This is a digitally signed message part
content-disposition: inline; filename=PGP.sig
content-transfer-encoding: 7bit

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (Darwin)

iD8DBQFBRI9B+zlz4UKpE6QRAjXOAJ92uLNgubf2/7+QAbEehQouCTw74gCeMr99
ClUbtUAgYp0KSNM2wYnKfsg=
=mo8d
-----END PGP SIGNATURE-----

--Apple-Mail-2-740839531--
 
Z

Zach Dennis

Michael said:
First of all, I must apologize for my lack of prompt reply to this
(and your other emails). I've been traveling, and haven't kept up with
ruby-talk as faithfully as I should have. Thanks to daz and others who
have replied in my absence.

No need to apologize, we can't expect you and other developers to be
able to reply 24/7 and I know that people do have life outside of the
Ruby ML. I just don't hold anything back if I have a question. And you
are replying now, so no harm no foul.
it assumes you've done mod_ruby development before and know about
Apache status codes, which isn't a valid assumption. We'll try to do
better. =:)

I have used mod_ruby once or twice in the past for benchmarking tests at
work. Nothing fancy, just basic stuff and it was a while ago.
The installation script should do all this for you: it can install
demo applets and templates in a directory of your choice, create an
appropriate config file for your installation, and then generates and
outputs an appropriate section for your httpd.conf. Did this not work
for you?

It installed the demo applets and templates and it did create a
demo.cfg. I had to manually add the httpd.conf configuration. I run a
Debian woody box. Once I figure out Arrow and mod_ruby a little better
I will be installing on another Debian server at work(the one I use now
is my home development server) so I will pay closer attention to what
happens during installation and update the you and the list.
One of the things it doesn't do is attempt to install the stuff in
redist/ for you or check your mod_ruby installation. It would appear
from your installation attempts as if this might be valuable. I'm a
bit leery of doing either because of cross-platform concerns, but I
guess I could do it for UNIXish installations and see where that gets us.

The redist/ part was my fault for not starting off reading the online
documentation for Arrow. I just read the README file and away I went.
But perhaps the install script to output to the user: "formvalidator is
not installed, it can be found in the redist/ directory".


Zach
 
W

why the lucky stiff

Michael said:
This has tripped me up in the past, too, but I don't quite know how to
detect when it's happened. I'll spend some time with the YAML modules
and see if I can't try to warn about this situation.

This is my responsibility. I should display a readable message when
tabs are used in indentation. I've placed this in the Syck bug tracker
on RubyForge and I'll get to it right away.

Anyone else have Syck bugs?? I know they are out there!!
<http://rubyforge.org/tracker/?atid=927&group_id=224&func=browse>

_why
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top