SQL Shell for MS Access

P

Paul Smith

What I want is an SQL command prompt allowing me to run SQL queries
against an Access .mdb.

I thought that Ruby/DBI included a sqlsh.rb script that essentially
did this, but no matter how I install Ruby/DBI I can't find the SQL
shell that I want.

So - does Ruby/DBI even include an SQL shell anymore? Is there
another way to get an SQL prompt for MS Access in a similar way to
what you can do with mysql for example?

Thanks for any insight,

Paul
 
D

David Mullet

Paul said:
What I want is an SQL command prompt allowing me to run SQL queries
against an Access .mdb.

I thought that Ruby/DBI included a sqlsh.rb script that essentially
did this, but no matter how I install Ruby/DBI I can't find the SQL
shell that I want.

So - does Ruby/DBI even include an SQL shell anymore? Is there
another way to get an SQL prompt for MS Access in a similar way to
what you can do with mysql for example?

Thanks for any insight,

Paul

--
Paul Smith
http://www.nomadicfun.co.uk

(e-mail address removed)

I'm not familiar with the mysql shell that you mentioned, but (assuming
you're on Windows) you could probably tweak the AccessDb wrapper found
here...

http://rubyonwindows.blogspot.com/2007/06/using-ruby-ado-to-work-with-ms-access.html

...to meet your needs.

David

http://rubyonwindows.blogspot.com
http://rubyonwindows.blogspot.com/search/label/access
 
R

Robert Klemme

2009/10/27 Paul Smith said:
What I want is an SQL command prompt allowing me to run SQL queries
against an Access .mdb.

I thought that Ruby/DBI included a sqlsh.rb script that essentially
did this, but no matter how I install Ruby/DBI I can't find the SQL
shell that I want.

So - does Ruby/DBI even include an SQL shell anymore? =A0Is there
another way to get an SQL prompt for MS Access in a similar way to
what you can do with mysql for example?

I doubt Ruby/DBI ever included what you need. In order to be able to
directly run SQL against an mdb file you need any DB engine. Ruby/DBI
is just an interfacing layer and does not include anything like a
complete DB engine.

Having said that, you can use OpenOffice to open mdb files and also
execute queries against it.

Kind regards

robert

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

Paul Smith

I doubt Ruby/DBI ever included what you need. =A0In order to be able to
directly run SQL against an mdb file you need any DB engine. =A0Ruby/DBI
is just an interfacing layer and does not include anything like a
complete DB engine.

Well, to be more complete, Ruby/DBI using a ruby-odbc DBD to connect
out to an access database.

This cached page
http://209.85.229.132/search?q=3Dcache:oks0dAPyNbQJ:doc.gnu-darwin.org/dbi/=
html/+ruby/dbi+sql+command+line&cd=3D9&hl=3Den&ct=3Dclnk&gl=3Duk&client=3Df=
irefox-a
suggests that sqlsh.rb did indeed once exist.

Page 137, Chapter 3 of "Accessing Databases with Ruby" also describes
what I want - http://books.google.co.uk/books?id=3DSvTuCXEKBvkC&pg=3DPA137&=
lpg=3DPA137&dq=3Druby+ms+access+interactive+sql+client&source=3Dbl&ots=3DSP=
gHkn7a76&sig=3D-Vk-Jpfm0f_LlS5z-AaCKw67NGU&hl=3Den&ei=3D8MzmSpmeLZXSjAediLW=
1CA&sa=3DX&oi=3Dbook_result&ct=3Dresult&resnum=3D1&ved=3D0CA4Q6AEwAA#v=3Don=
epage&q=3D&f=3Dfalse
Having said that, you can use OpenOffice to open mdb files and also
execute queries against it.

Maybe this is the right way to go, I just really like the command
line, as I'm used to working with mysql, and there you can just fire
up mysql-client, get a mysql> prompt, and start typing things like
show tables to list all the tables in the db, desc table to describe
the layout of a given table.

I'm just trying to make working with MS Access feel more like working
with mysql :)
--=20
Paul Smith
http://www.nomadicfun.co.uk

(e-mail address removed)
 
R

Robert Klemme

2009/10/27 Paul Smith said:
Well, to be more complete, Ruby/DBI using a ruby-odbc DBD to connect
out to an access database.

Oh, OK, ODBC is a different story. I didn't think of that.
This cached page
http://209.85.229.132/search?q=3Dcache:oks0dAPyNbQJ:doc.gnu-darwin.org/db= i/html/+ruby/dbi+sql+command+line&cd=3D9&hl=3Den&ct=3Dclnk&gl=3Duk&client=
=3Dfirefox-a
suggests that sqlsh.rb did indeed once exist.

Page 137, Chapter 3 of "Accessing Databases with Ruby" also describes
what I want - http://books.google.co.uk/books?id=3DSvTuCXEKBvkC&pg=3DPA13= 7&lpg=3DPA137&dq=3Druby+ms+access+interactive+sql+client&source=3Dbl&ots=3D=
SPgHkn7a76&sig=3D-Vk-Jpfm0f_LlS5z-AaCKw67NGU&hl=3Den&ei=3D8MzmSpmeLZXSjAedi=
LW1CA&sa=3DX&oi=3Dbook_result&ct=3Dresult&resnum=3D1&ved=3D0CA4Q6AEwAA#v=3D=
onepage&q=3D&f=3Dfalse


Maybe this is the right way to go, I just really like the command
line, as I'm used to working with mysql, and there you can just fire
up mysql-client, get a mysql> prompt, and start typing things like
show tables to list all the tables in the db, desc table to describe
the layout of a given table.

You could as well try a generic DB client (e.g. SQirreL) which should
also be capable of making use of Access's ODBC driver via the JDBC
ODBC bridge (although that is not perfect as well). Maybe there's
also a native Windows ODBC SQL client around that you could use.
I'm just trying to make working with MS Access feel more like working
with mysql :)

Seems like you are forced to work with MS Access. I would try to
avoid it if possible. :)

Kind regards

robert

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

Paul Smith

Maybe this is the right way to go, I just really like the command
You could as well try a generic DB client (e.g. SQirreL) which should
also be capable of making use of Access's ODBC driver via the JDBC
ODBC bridge (although that is not perfect as well). =A0Maybe there's
also a native Windows ODBC SQL client around that you could use.

I'll keep on investigating. So close, but yet so far.
Seems like you are forced to work with MS Access. =A0I would try to
avoid it if possible. :)

I would too :) I'm maintaining a database as a bit of a side job at
work, and it's currently in MS Access. There's no real reason I guess
to keep it in MS Access, other than I may have to pass it on to
someone else at a later date, and they're more likely to have some
Access knowledge than anything else.

If it was my main job I'd probably spend the effort to convert, but it
isn't and I'm honestly trying to lose it to someone else.
Kind regards

robert



--=20
Paul Smith
http://www.nomadicfun.co.uk

(e-mail address removed)
 
C

Coey_Minear

-----Original Message-----
From: (e-mail address removed) [mailto:p[email protected]]
On Behalf Of Paul Smith
Sent: Tuesday, October 27, 2009 8:18 AM
To: ruby-talk ML
Subject: Re: SQL Shell for MS Access
=20
I doubt Ruby/DBI ever included what you need. =A0In order to be able to
directly run SQL against an mdb file you need any DB engine. =A0Ruby/DBI
is just an interfacing layer and does not include anything like a
complete DB engine.
=20
Well, to be more complete, Ruby/DBI using a ruby-odbc DBD to
connect
out to an access database.
=20
This cached page
http://209.85.229.132/search?q=3Dcache:oks0dAPyNbQJ:doc.gnu-
darwin.org/dbi/html/+ruby/dbi+sql+command+line&cd=3D9&hl=3Den&ct=3Dclnk&g
l=3Duk&client=3Dfirefox-a
suggests that sqlsh.rb did indeed once exist.
=20
Page 137, Chapter 3 of "Accessing Databases with Ruby" also
describes
what I want -
http://books.google.co.uk/books?id=3DSvTuCXEKBvkC&pg=3DPA137&lpg=3DPA137&
dq=3Druby+ms+access+interactive+sql+client&source=3Dbl&ots=3DSPgHkn7a76&s
ig=3D-Vk-Jpfm0f_LlS5z-
AaCKw67NGU&hl=3Den&ei=3D8MzmSpmeLZXSjAediLW1CA&sa=3DX&oi=3Dbook_result&ct= =3Dr
esult&resnum=3D1&ved=3D0CA4Q6AEwAA#v=3Donepage&q=3D&f=3Dfalse
=20

According to this page: http://ruby-dbi.rubyforge.org/git?p=3Druby-dbi.git;=
a=3Dcommit;h=3D556e08726d9716e5b06d558b8250eb9f0d06df9e
'sqlsh.rb' was renamed to 'dbi'. You should find a 'dbi' file in the same =
directory where 'ruby' is installed. Of course, there have been changes to=
'dbi' since this change was made, but it's a place to start.
=20
Maybe this is the right way to go, I just really like the command
line, as I'm used to working with mysql, and there you can just
fire
up mysql-client, get a mysql> prompt, and start typing things like
show tables to list all the tables in the db, desc table to
describe
the layout of a given table.
=20
I'm just trying to make working with MS Access feel more like
working
with mysql :)
--
Paul Smith
http://www.nomadicfun.co.uk
=20
(e-mail address removed)

Coey Minear
 
P

Paul Smith

-----Original Message-----
From: (e-mail address removed) [mailto:p[email protected]]
On Behalf Of Paul Smith
Sent: Tuesday, October 27, 2009 8:18 AM
To: ruby-talk ML
Subject: Re: SQL Shell for MS Access

2009/10/27 Paul Smith <[email protected]>:
What I want is an SQL command prompt allowing me to run SQL queries
against an Access .mdb.

I thought that Ruby/DBI included a sqlsh.rb script that essentially
did this, but no matter how I install Ruby/DBI I can't find the SQL
shell that I want.

So - does Ruby/DBI even include an SQL shell anymore? =A0Is there
another way to get an SQL prompt for MS Access in a similar way to
what you can do with mysql for example?

I doubt Ruby/DBI ever included what you need. =A0In order to be able to
directly run SQL against an mdb file you need any DB engine. =A0Ruby/DBI
is just an interfacing layer and does not include anything like a
complete DB engine.

Well, to be more complete, Ruby/DBI using a ruby-odbc DBD to
connect
out to an access database.

This cached page
http://209.85.229.132/search?q=3Dcache:oks0dAPyNbQJ:doc.gnu-
darwin.org/dbi/html/+ruby/dbi+sql+command+line&cd=3D9&hl=3Den&ct=3Dclnk&= g
l=3Duk&client=3Dfirefox-a
suggests that sqlsh.rb did indeed once exist.

Page 137, Chapter 3 of "Accessing Databases with Ruby" also
describes
what I want -
http://books.google.co.uk/books?id=3DSvTuCXEKBvkC&pg=3DPA137&lpg=3DPA137= &
dq=3Druby+ms+access+interactive+sql+client&source=3Dbl&ots=3DSPgHkn7a76&= s
ig=3D-Vk-Jpfm0f_LlS5z-
AaCKw67NGU&hl=3Den&ei=3D8MzmSpmeLZXSjAediLW1CA&sa=3DX&oi=3Dbook_result&c= t=3Dr
esult&resnum=3D1&ved=3D0CA4Q6AEwAA#v=3Donepage&q=3D&f=3Dfalse

According to this page: http://ruby-dbi.rubyforge.org/git?p=3Druby-dbi.gi= t;a=3Dcommit;h=3D556e08726d9716e5b06d558b8250eb9f0d06df9e
'sqlsh.rb' was renamed to 'dbi'. =A0You should find a 'dbi' file in the s=
ame directory where 'ruby' is installed. =A0Of course, there have been chan=
ges to 'dbi' since this change was made, but it's a place to start.

Brilliant! Thanks so much for finding that, I had given up :)

Now I just need to get ruby-odbc working with Ruby 1.9 on windows...
or install Ruby 1.8.6. It's looking like the latter is the better
option from here.

--=20
Paul Smith
http://www.nomadicfun.co.uk

(e-mail address removed)
 
M

Max Williams

I connected to an mdb (access db) in windows with the 'win32ole' gem. I
also got this class from a blog post by David Mullet:
http://rubyonwindows.blogspot.com/2007/06/using-ruby-ado-to-work-with-ms-access.html

which also has a guide on how to connect.

I modified the class on this page to return results as an array of
hashes, like ActiveRecord's find_rows method, and added a "find" method
which just takes an sql string. So, it's pretty like mysql (my desire
as well, i was amazed to discover that access has no sql command line).

If this has problems then blame me and not David :) Here's my complete
class, see the blog post by David above on how to use it.

class AccessDb

attr_accessor :mdb, :connection, :data, :fields, :rows, :sql



def initialize(mdb=nil)

@mdb = mdb

@connection = nil

@data = nil

@fields = nil

@rows = []

self.open

end



def open

connection_string = 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source='

connection_string << @mdb

@connection = WIN32OLE.new('ADODB.Connection')

@connection.Open(connection_string)

end



def query(sql, options = {})

self.sql = sql

puts "Querying: #{sql}" if options[:verbose]

recordset = WIN32OLE.new('ADODB.Recordset')

recordset.Open(sql, @connection)

@fields = []

@rows = []

recordset.Fields.each do |field|

@fields << field.Name

end

begin

@data = recordset.GetRows.transpose

@data.each do |row|

row_hash = {}

row.each_with_index do |value, i|

row_hash[@fields] = value

end

@rows << row_hash

end

rescue

@data = []

end

recordset.Close

end



def find(sql, options = {})

self.sql = sql

self.query(sql, options)

self.rows

end



def execute(sql, options = {})

self.sql = sql

puts "Executing: #{sql}" if options[:verbose]

begin

@connection.Execute(sql)

rescue

raise "!!ERROR executing \n#{sql}\n: (#{@mdb.inspect}) #{$!}"

end

end



def close

@connection.Close

end

end
 
P

Paul Smith

I connected to an mdb (access db) in windows with the 'win32ole' gem. =A0= I
also got this class from a blog post by David Mullet:
http://rubyonwindows.blogspot.com/2007/06/using-ruby-ado-to-work-with-ms-= access.html

which also has a guide on how to connect.

I modified the class on this page to return results as an array of
hashes, like ActiveRecord's find_rows method, and added a "find" method
which just takes an sql string. =A0So, it's pretty like mysql (my desire
as well, i was amazed to discover that access has no sql command line).

If this has problems then blame me and not David :) =A0Here's my complete
class, see the blog post by David above on how to use it.

class AccessDb

Thanks Max! Making a painful job easier, one step at a time.

--=20
Paul Smith
http://www.nomadicfun.co.uk

(e-mail address removed)
 

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

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top