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 “;”
sqlite> SQL
…> CREATE TABLE people (
…> id integer primary key,
…> name varchar(50),
…> job varchar(50),
…> gender varchar(6),
…> age integer);
Error: near “SQL”: syntax error
sqlite>

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

Thanks much!

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

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?

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

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!(/>/, “<”).gsub!(/</, ">)

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

my_string.gsub!(/>/, “<”)
my_string.gsub!(/</, ">)

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

Wayne

On Fri, Aug 3, 2012 at 9:59 AM, Wayne B. [email protected] wrote:

my_string.gsub!(/>/, “<”)
my_string.gsub!(/</, ">)

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

1.9.3p125 :001 > “”.gsub(/[<>]/,’<’ => ‘<’, ‘>’ => ‘>’)
=> “<link>”

There’s a nice little example in the (cough) documentation…

‘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

From: Hassan S. [email protected]

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:

http://www.ruby-doc.org/core-1.9.3/String.html#method-i-gsub-21

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

Wayne

Chris H. 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.”

Or did I misunderstood? Is the author saying I can type ANY SQL
commands, and not ‘SQL’ itself, and press Enter to execute it?
Thank you.

On Fri, Aug 3, 2012 at 11:28 AM, Wayne B. [email protected]
wrote:

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

http://www.ruby-doc.org/core-1.9.3/String.html#method-i-gsub-21

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

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

On Aug 3, 2012, at 21:25 , Kaye Ng [email protected] wrote:

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

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”

Hello,

On 4 Αυγ 2012, at 07:25 , Kaye Ng [email protected] wrote:

Ruby at all. Just run

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 A.

On Fri, Aug 3, 2012 at 6:59 PM, Wayne B. [email protected] wrote:

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 = {
‘>’ => ‘<’,
‘<’ => ‘>’
}

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("").to_s
=> “<a>”

Kind regards

robert

2012/8/4 [email protected]:

It should work (without typo):

1.9.3p194 :001 > ‘’.gsub!(/>/, ‘<’).gsub!(/</, ‘>’)
=> “>test<”

Nope.

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

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

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

– Matma R.

Am 03.08.2012 18:59, schrieb Wayne B.:

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!(/>/, “<”).gsub!(/</, ">)
^^^^

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

It should work (without typo):

1.9.3p194 :001 > ‘’.gsub!(/>/, ‘<’).gsub!(/</, ‘>’)
=> “>test<”

On Fri, Aug 3, 2012 at 11:59 AM, Wayne B. [email protected]
wrote:

my_string.gsub!(/>/, “<”)
my_string.gsub!(/</, ">)

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

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

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

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

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

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}

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs