[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

mysql source command doesn't work?

Raymond O'connor

12/2/2006 1:22:00 AM

I'm trying to use the mysql 'source' command within a ruby script to run
a batch file, but it doens't seem to work. When I run the source
command straight from mysql, though, it runs just fine. Here's a short
example of what I'm trying to do:

require 'mysql'
db = Mysql.real_connect(db_host, db_user, db_pass, db_name)
filename = "/Users/test/batch.sql"
db.query "source #{filename}"


I keep getting this error when I try to do dbh.query "source
${filename}"

Error code: 1064
Error message: You have an error in your SQL syntax; check the manual
that corresponds to your MySQL server version for the right syntax to
use near 'SOURCE /Users/test/batch.sql' at line 1
Error SQLSTATE: 42000


Anyone have any ideas? Thanks in advance.

--
Posted via http://www.ruby-....

3 Answers

Park Heesob

12/2/2006 2:08:00 AM

0


Hi,

>From: Raymond O'connor <nappin713@yahoo.com>
>Reply-To: ruby-talk@ruby-lang.org
>To: ruby-talk@ruby-lang.org (ruby-talk ML)
>Subject: mysql source command doesn't work?
>Date: Sat, 2 Dec 2006 10:21:49 +0900
>
>I'm trying to use the mysql 'source' command within a ruby script to run
>a batch file, but it doens't seem to work. When I run the source
>command straight from mysql, though, it runs just fine. Here's a short
>example of what I'm trying to do:
>
>require 'mysql'
>db = Mysql.real_connect(db_host, db_user, db_pass, db_name)
>filename = "/Users/test/batch.sql"
>db.query "source #{filename}"
>
>
>I keep getting this error when I try to do dbh.query "source
>${filename}"
>
>Error code: 1064
>Error message: You have an error in your SQL syntax; check the manual
>that corresponds to your MySQL server version for the right syntax to
>use near 'SOURCE /Users/test/batch.sql' at line 1
>Error SQLSTATE: 42000
>
>
>Anyone have any ideas? Thanks in advance.
>

'source' is not an SQL command, but an internal command of the mysql command
line client.

You could use Ruby's system like this:

system("/path/to/mysql -uuser -ppassword database <#{filename}");

Regards,

Park Heesob

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/...


David Vallner

12/2/2006 11:27:00 AM

0

Park Heesob wrote:
>> I'm trying to use the mysql 'source' command within a ruby script to run
>> a batch file, but it doens't seem to work. When I run the source
>> command straight from mysql, though, it runs just fine. Here's a short
>> example of what I'm trying to do:
>>
>> Anyone have any ideas? Thanks in advance.
>>
>
> 'source' is not an SQL command, but an internal command of the mysql
> command line client.
>
> You could use Ruby's system like this:
>
> system("/path/to/mysql -uuser -ppassword database <#{filename}");
>

That presumes the ruby script and the SQL script are colocated (and this
being MySQL, if my assumptions on users of that product hold, the
database server will also be on the same machine).

In that case, you can also read the file inside the Ruby process and
then feed the commands to the database connection. This has the
advantage that you don't show your DB username and password to all and
sundry connected to that machine in ps output. (Passwords on command
lines are bad, 'mmmkay.)

David Vallner

Blackwater

10/5/2010 2:08:00 PM

0

rfischer@sonic.net (Ray Fischer) wrote:

>Mr.B1ack <bw@barrk.net> wrote:
>>"5732 Dead, 875 since 1/20/09" <deadis@deadduz.com> wrote:
>>
>>>On Sun, 03 Oct 2010 02:34:50 -0400, Mr.B1ack wrote:
>>>
>>>> "5732 Dead, 875 since 1/20/09" <dead@dead> wrote:
>>>>
>>>>>On Sat, 02 Oct 2010 22:55:20 -0400, Mr.B1ack <bw@barrk.net> wrote:
>>>>>
>>>>>>"5732 Dead, 875 since 1/20/09" <deadis@deadduz.com> wrote:
>>>>>>
>>>>>>>From The Manitoba Herald , Canada
>>>>>>>?Reported" by Clive Runnels
>>>>>>>Canadians: ?Build a Damn Fence !"
>>>>>>>
>>>>>>>The flood of American liberals sneaking across the border into Canada
>>>>>>>has intensified in the past week, sparking calls for increased patrols
>>>>>>>to stop the illegal immigration. The recent actions of the Tea Party
>>>>>>>are prompting an exodus among left-leaning citizens who fear they'll
>>>>>>>soon be required to hunt, pray, and to agree with Bill O'Reilly and
>>>>>>>Glenn Beck.
>>>>>>
>>>>>> I suggest legislation requiring those who flee to Canada to be
>>>>>> forever barred from returning to the USA. :-)
>>>>>
>>>>>You realize that you'll get the enthusiastic support of "patriots" whose
>>>>>knowledge of the Constitution is as limited as their sense of humor,
>>>>>right?
>>>>
>>>> Yea ... but sometimes the will of the ignorant masses can serve a
>>>> higher good. An America without modern "liberals" ... closer to
>>>> paradise ! :-)
>>>
>>>Seig HEIL!
>>
>> Nah ... we'll lure the fascists to Argentina
>> at the same time :-)
>
>"Lure"? Surely you meant "join".

Actually, just hint that there's gonna
be a sanctioned 'beaner hunt' down in
Mexico ... and as soon as they all rush
down there we raise that fence :-)