Forum: Ruby MySQL

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
024df81c5a19da7762f694e801518af5?d=identicon&s=25 Marcin Tyman (sirtyman)
on 2007-07-26 13:47
Hi,
 How to operate on MySQL? I would like to delete, create database and
upgrade with prepared files. I know mysql library but I'm not sure
whether it let me operate on  commands such as delete database, source
file_path etc.

I will be appreciated for any help

MT
C667185722eaecf12461cb423dc8b410?d=identicon&s=25 Ronald Fischer (Guest)
on 2007-07-26 14:10
(Received via mailing list)
> I would like to delete, create database and
> upgrade with prepared files. I know mysql library but I'm not sure
> whether it let me operate on  commands such as delete database, source
> file_path etc.

If you connect with administrator privileges, you should be able
to execute any command you could also execute from the mysql
command line interface.

Ronald
15a5043475dac9278ae75efb4c71f1f6?d=identicon&s=25 Felix Windt (Guest)
on 2007-07-26 14:14
(Received via mailing list)
> library but I'm not sure whether it let me operate on
> commands such as delete database, source file_path etc.
>
> I will be appreciated for any help
>
> MT
> --
> Posted via http://www.ruby-forum.com/.
>

Pretty much all database interfaces allow you to send raw commands.

Such as:

require "mysql"
dbh = Mysql.real_connect("localhost", "testuser", "testpass", "test")
dbh.query("CREATE TABLE test(column VARCHAR(255))")
dbh.query("DROP TABLE IF EXISTS test")
File.open("sql_commands_in_textfile") do |file|
  while line = file.gets
    dbh.query(line)
  end
end
024df81c5a19da7762f694e801518af5?d=identicon&s=25 Marcin Tyman (sirtyman)
on 2007-07-26 14:25
Ronald Fischer wrote:
>> I would like to delete, create database and
>> upgrade with prepared files. I know mysql library but I'm not sure
>> whether it let me operate on  commands such as delete database, source
>> file_path etc.
>
> If you connect with administrator privileges, you should be able
> to execute any command you could also execute from the mysql
> command line interface.
>
> Ronald

dbh.query("source c:/create.sql") - doesn't work. It causes SQL syntax.
C667185722eaecf12461cb423dc8b410?d=identicon&s=25 Ronald Fischer (Guest)
on 2007-07-26 14:46
(Received via mailing list)
> dbh.query("source c:/create.sql") - doesn't work. It causes
> SQL syntax.

True, but for this case, you can always do

  IO.readlines("c:/create.sql").each { |s| dbh.query(s) }

Ronald
024df81c5a19da7762f694e801518af5?d=identicon&s=25 Marcin Tyman (sirtyman)
on 2007-07-26 14:51
Ronald Fischer wrote:
>> dbh.query("source c:/create.sql") - doesn't work. It causes
>> SQL syntax.
>
> True, but for this case, you can always do
>
>   IO.readlines("c:/create.sql").each { |s| dbh.query(s) }
>
> Ronald


Thanks, I'll check it. It seems to be ok. At the moment I cannot check
it (the db is used)
15a5043475dac9278ae75efb4c71f1f6?d=identicon&s=25 Felix Windt (Guest)
on 2007-07-26 15:10
(Received via mailing list)
> >
> --
> Posted via http://www.ruby-forum.com/.
>


NEVER develop against a live database.
425cab08658a06567879717de154552c?d=identicon&s=25 Ari Brown (Guest)
on 2007-07-26 16:24
(Received via mailing list)
On Jul 26, 2007, at 7:47 AM, Marcin Tyman wrote:

> Hi,
>  How to operate on MySQL? I would like to delete, create database and
> upgrade with prepared files. I know mysql library but I'm not sure
> whether it let me operate on  commands such as delete database, source
> file_path etc.
>
> I will be appreciated for any help


You can use Ruby/MySQL, MySQL/Ruby, DBI, or ActiveRecord

~ Ari
English is like a pseudo-random number generator - there are a
bajillion rules to it, but nobody cares.
1c0cd550766a3ee3e4a9c495926e4603?d=identicon&s=25 John Joyce (Guest)
on 2007-07-29 06:33
(Received via mailing list)
On Jul 26, 2007, at 8:06 AM, Felix Windt wrote:

>>>
>> --
>> Posted via http://www.ruby-forum.com/.
>>
>
>
> NEVER develop against a live database.
Safest advice, yes, but...
Well, you can, but that's when safety mechanisms like not developing
under root or not having all priveledges are good ideas.
It's their database though.
This topic is locked and can not be replied to.