Help with sqlite3 please

I'm on Windows 7 Ultimate, 64-bit

Installed sqlite:

C:\Users\Kaye>gem install sqlite3
Successfully installed sqlite3-1.3.6-x86-mingw32
1 gem installed
Installing ri documentation for sqlite3-1.3.6-x86-mingw32...
Installing RDoc documentation for sqlite3-1.3.6-x86-mingw32...

then did this:

C:\Users\Kaye>sqlite3 test.db
SQLite version 3.7.10 2012-01-16 13:28:40
Enter ".help" for instructions
Enter SQL statements terminated with a ";"

SQL

   ...> CREATE TABLE people (
   ...> id integer primary key,
   ...> name varchar(50),
   ...> job varchar(50),
   ...> gender varchar(6),
   ...> age integer);
Error: near "SQL": syntax error

I didn't have this problem with my other machine, windows 7 32-bit.
Help pls?

Thanks much!

···

--
Posted via http://www.ruby-forum.com/\.

sqlite is not ruby, so you should look for a sqlite group :wink:

However it looks like you have 'SQL' at the beginning of your CREATE
command which is the problem

···

On Fri, Aug 3, 2012 at 12:21 PM, Kaye Ng <lists@ruby-forum.com> wrote:

I'm on Windows 7 Ultimate, 64-bit

Installed sqlite:

C:\Users\Kaye>gem install sqlite3
Successfully installed sqlite3-1.3.6-x86-mingw32
1 gem installed
Installing ri documentation for sqlite3-1.3.6-x86-mingw32...
Installing RDoc documentation for sqlite3-1.3.6-x86-mingw32...

then did this:

C:\Users\Kaye>sqlite3 test.db
SQLite version 3.7.10 2012-01-16 13:28:40
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
> SQL
   ...> CREATE TABLE people (
   ...> id integer primary key,
   ...> name varchar(50),
   ...> job varchar(50),
   ...> gender varchar(6),
   ...> age integer);
Error: near "SQL": syntax error
>

I didn't have this problem with my other machine, windows 7 32-bit.
Help pls?

Thanks much!

--
Posted via http://www.ruby-forum.com/\.

I''ve been using ruby sqlite on windows 7 64 bit with out any problem.
Here's a copy of the program you can use as an example
I'm using ruby 1.93. It wouldn't work on earlier versions of ruby

···

#================================================
#
# Create dxcc_diamond sqlite data base
#
#================================================
ctable = false #true to create new tables and database. (delete previous database if starting over)
require 'sqlite3'

db = SQLite3::Database.new( "dxcc.sq3" )
db.execute("create table if not exists dxid(dpfx primary key unique, country, continent,ditu,dcq,call)")
db.execute("create table if not exists callid(cpfx primary key unique,dxpfx, citu, ccq)")

if ctable
       fdx = File.new("dxcc_list2.txt")
       fdx.each do |l|
             l.gsub!("\'","-")
             d = l.chomp.split("\t")
            db.execute("insert into dxid values('#{d[0]}','#{d[1]}','#{d[2]}','#{d[3]}','#{d[4]}','#{d[5]}')")
       end
       fdx.close
       p "============================="

       fdx = File.new("call_list2.txt")
       fdx.each do |l|
             l.gsub!("\'","-")
             d = l.chomp.split("\t")
            db.execute("insert into callid values('#{d[0]}','#{d[1]}','#{d[2]}','#{d[3]}')")
       end
       fdx.close
end

#SELECT Call_list.DM_PFX, Dxcc_list.PFX, Dxcc_list.COUNTRY, Dxcc_list.CONTINENT
#FROM Call_list INNER JOIN Dxcc_list ON Call_list.PFX = Dxcc_list.PFX
#WHERE (((Call_list.DM_PFX) Like [call_prefix]));

#WHERE (((callid.cpfx) = 'CO'))

#db.execute("select callid.cpfx from callid") {|x| p x}

db.execute("SELECT callid.cpfx, dxid.dpfx, dxid.country, dxid.continent \
FROM callid JOIN dxid ON callid.dxpfx = dxid.dpfx \
WHERE (((callid.cpfx) like 'X%'))") {|x| p x}

#db.execute("insert into callid values( '4UTAR', '4U1U', '88', '99')")
#db.execute("insert into rlog values (2,'N4ddn','2/3/04')")
#db.execute("insert into rlog (call,cdate) values ('zk5rd','2/3/4')")
#db.execute("select * from rlog sort order by call") {|x| p x}

Kaye Ng wrote:

I'm on Windows 7 Ultimate, 64-bit

Installed sqlite:

C:\Users\Kaye>gem install sqlite3
Successfully installed sqlite3-1.3.6-x86-mingw32
1 gem installed
Installing ri documentation for sqlite3-1.3.6-x86-mingw32...
Installing RDoc documentation for sqlite3-1.3.6-x86-mingw32...

then did this:

C:\Users\Kaye>sqlite3 test.db
SQLite version 3.7.10 2012-01-16 13:28:40
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
> SQL
    ...> CREATE TABLE people (
    ...> id integer primary key,
    ...> name varchar(50),
    ...> job varchar(50),
    ...> gender varchar(6),
    ...> age integer);
Error: near "SQL": syntax error
>

I didn't have this problem with my other machine, windows 7 32-bit.
Help pls?

Thanks much!

However it looks like you have 'SQL' at the beginning of your CREATE
command which is the problem

But I'm studying the basics of SQL so I can use it with Ruby. Anyway,
isn't the 'SQL' at the beginning necessary?

···

--
Posted via http://www.ruby-forum.com/\.

Wanting to use a tool with ruby doesn't mean that the tool is written in ruby. That's a SQL command, not ruby.

Having said which, try the command on your other box.

Jams

···

On Aug 3, 2012, at 10:43 AM, Kaye Ng <lists@ruby-forum.com> wrote:

However it looks like you have 'SQL' at the beginning of your CREATE
command which is the problem

But I'm studying the basics of SQL so I can use it with Ruby. Anyway,
isn't the 'SQL' at the beginning necessary?

--
Posted via http://www.ruby-forum.com/\.

I have a script that I wrote that uses nokogiri to parse some HTML, the results
I get back, I need to change several of the HTML entities (><&), I thought I
could stack the gsub! commands so they would be something like this:

my_string.gsub!(/>/, "&lt;").gsub!(/</, "&gt;)

but I found that work, so for now I'm using:

my_string.gsub!(/>/, "&lt;")
my_string.gsub!(/</, "&gt;)

which works, but I'm sure is horribly inefficient. Is there a better way to do
multiple global substitutions on a string?

Wayne

'SQL' is not part of the command
See the example here: http://www.sqlite.org/sqlite.html

You may be thinking of the syntax to run the command when not in an
interactive sqlite session

1.9.3p125 :001 > "<link>".gsub(/[<>]/,'<' => '&lt;', '>' => '&gt;')
=> "&lt;link&gt;"

There's a nice little example in the (cough) documentation...

···

On Fri, Aug 3, 2012 at 9:59 AM, Wayne Brisette <wbrisett@att.net> wrote:

my_string.gsub!(/>/, "&lt;")
my_string.gsub!(/</, "&gt;)

which works, but I'm sure is horribly inefficient. Is there a better way to do
multiple global substitutions on a string?

--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com

twitter: @hassan

Chris Hulan wrote in post #1071197:

'SQL' is not part of the command
See the example here: http://www.sqlite.org/sqlite.html

Got it. But I was only following a book, can you tell me why it says
'type SQL and press enter'?

"If you want to play along at home, you can use the command-line sqlite3
client to create a
database and perform SQL queries upon it without getting involved with
Ruby at all. Just run
sqlite3 test.db, where test.db is your chosen database file name. You
can then type SQL and
press Enter to execute it. To leave the client, you can type .quit on a
separate line and press
Enter."

Thank you.

···

--
Posted via http://www.ruby-forum.com/\.

I have a script that I wrote that uses nokogiri to parse some HTML, the results
I get back, I need to change several of the HTML entities (><&), I thought I
could stack the gsub! commands so they would be something like this:

my_string.gsub!(/>/, "&lt;").gsub!(/</, "&gt;)

but I found that work, so for now I'm using:

my_string.gsub!(/>/, "&lt;")
my_string.gsub!(/</, "&gt;)

which works, but I'm sure is horribly inefficient.

What makes you so sure?

Is there a better way to do
multiple global substitutions on a string?

REPLACEMENTS = {
  '>' => '&lt;',
  '<' => '&gt;'
}

RX = Regexp.union(REPLACEMENTS.keys)

my_string.gsub! RX do |m|
  replacements.fetch m do
    raise "Not found: #{m}"
  end
end

Use an XML tool:

irb(main):001:0> require 'rexml/text'
=> true
irb(main):002:0> s = REXML::Text.new("<a>").to_s
=> "&lt;a&gt;"

Kind regards

robert

···

On Fri, Aug 3, 2012 at 6:59 PM, Wayne Brisette <wbrisett@att.net> wrote:

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

I have a script that I wrote that uses nokogiri to parse some HTML, the results
I get back, I need to change several of the HTML entities (><&), I thought I
could stack the gsub! commands so they would be something like this:

my_string.gsub!(/>/, "&lt;").gsub!(/</, "&gt;)

                                              ^^^^

but I found that work, so for now I'm using:

It should work (without typo):

1.9.3p194 :001 > '<test>'.gsub!(/>/, '&lt;').gsub!(/</, '&gt;')
  => "&gt;test&lt;"

···

Am 03.08.2012 18:59, schrieb Wayne Brisette:

--
<https://github.com/stomar/&gt;

Why would it be inefficient? It looks like the same thing to me.

···

On Fri, Aug 3, 2012 at 11:59 AM, Wayne Brisette <wbrisett@att.net> wrote:

I have a script that I wrote that uses nokogiri to parse some HTML, the
results
I get back, I need to change several of the HTML entities (><&), I thought
I
could stack the gsub! commands so they would be something like this:

my_string.gsub!(/>/, "&lt;").gsub!(/</, "&gt;)

but I found that work, so for now I'm using:

my_string.gsub!(/>/, "&lt;")
my_string.gsub!(/</, "&gt;)

which works, but I'm sure is horribly inefficient. Is there a better way
to do
multiple global substitutions on a string?

From: Hassan Schroeder <hassan.schroeder@gmail.com>

There's a nice little example in the (cough) documentation...

Thanks... Maybe I'm looking in the wrong place for the docs, but I don't see any
examples here:

Is there some other place I should be looking at the docs?

Wayne

Hello,

···

On 4 Αυγ 2012, at 07:25 , Kaye Ng <lists@ruby-forum.com> wrote:

Chris Hulan wrote in post #1071197:

'SQL' is not part of the command
See the example here: http://www.sqlite.org/sqlite.html

Got it. But I was only following a book, can you tell me why it says
'type SQL and press enter'?

"If you want to play along at home, you can use the command-line sqlite3
client to create a
database and perform SQL queries upon it without getting involved with
Ruby at all. Just run
sqlite3 test.db, where test.db is your chosen database file name. You
can then type SQL and
press Enter to execute it. To leave the client, you can type .quit on a
separate line and press
Enter."

Thank you.

--
Posted via http://www.ruby-forum.com/\.

I don't know exactly what book are you reading. The references that other users showed and the comments they made are all valid. If you want to see a small readable example of SQLite3 usage in ruby, take a look at my script, which saves tweets into an SQLite3 database.

It's not advanced in any way but it clearly shows how to handle SQLite3 queries and issue commands using ruby.

https://github.com/atmosx/morula/blob/master/morula

Best Regards,

Panagiotis Atmatzidis
-----------------------------
Pharmacy Student at VFU

email4lists: ml@convalesco.org
More info: http://about.me/atmosx

The wise man said: "Never argue with an idiot, he brings you down to his level and beat you with experience."

you took this phrase too literally. They mean you can type a sql statement at the prompt and press enter to see the result.

If I gave an equivalent for ruby, it'd be something like "run irb, then type (some) ruby and press enter to execute it"

···

On Aug 3, 2012, at 21:25 , Kaye Ng <lists@ruby-forum.com> wrote:

You
can then type SQL and
press Enter to execute it.

Nope.

irb(main):001:0> 'test'.gsub!(/>/, '&lt;').gsub!(/</
NoMethodError: undefined method `gsub!' for nil:NilC
        from (irb):1
        from F:/Ruby193/bin/irb:12:in `<main>'

#gsub! (with bang) modifies the receiver and returns nil if no changes
were made.

#gsub (without bang) always returns a new string.

-- Matma Rex

···

2012/8/4 <sto.mar@web.de>:

It should work (without typo):

1.9.3p194 :001 > '<test>'.gsub!(/>/, '&lt;').gsub!(/</, '&gt;')
=> "&gt;test&lt;"

Actually, having not done any timing runs, I was just making a guess since I was doing the same thing twice serially. Seems maybe I wasn't doing a bad thing, but I do like the compactness of the code Hassan provided.

Wayne

···

On Aug 4, 2012, at 12:02 PM, Josh Cheek wrote:

Why would it be inefficient? It looks like the same thing to me.

On that page there are 5 examples under gsub, the last one being:

'hello'.gsub(/[eo]/, 'e' => 3, 'o' => '*') #=> "h3ll*"

···

On Fri, Aug 3, 2012 at 11:28 AM, Wayne Brisette <wbrisett@att.net> wrote:

Thanks... Maybe I'm looking in the wrong place for the docs, but I don't see any
examples here:

Class: String (Ruby 1.9.3)

--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com

twitter: @hassan