I’ve been trying to install RoR and get it connected to my installation of MySQL 5.5.
To get started I downloaded the intsaller kit from here http://railsinstaller.org/
I then followed this tutorial http://guides.rubyonrails.org/getting_started.html
As per the instructions I created my first project
rails new blog
And I updated my database.yml file to make a connection to MySQL in C:\Sites\blog\config\database.yml
development: adapter: mysql2 encoding: utf8 database: blog_development pool: 5 username: root password: socket: /tmp/mysql.sock
and I updated my Gemfile in the project’s root directory
So now all I have to do is to create a database with “rake”…
rake db:create --trace
But I get a horrible message!
uninitialized constant Mysql2
This is an issue with the installation of the MySQL Gem adaptor so lets install it properly
Download and install the C mysql connector http://dev.mysql.com/downloads/connector/c
Now run this
gem install mysql2 -- '--with-mysql-lib="c:\Program Files\MySQL\MySQL Connector C 6.0.2\lib\opt" --with-mysql-include="c:\Program Files\MySQL\MySQL Connector C 6.0.2\include"
Notice we make a reference to the newly installed C connector library.
copy libmysql.dll from above to the Ruby bin dir C:\RailsInstaller\Ruby1.9.2\bin
Now we can create our database….
rake db:create --trace
We should now have a database using the name from database.yml above.
More than occasionally you will find that you need to call the same DOS script with several different parameter values, say a list of names.
Create a looping bat file “LoopTest.bat”.
Note that this script checks thats the file exists and prints a nice dated report header too
::-----Init..... @echo off & setlocal SET day=%date:~0,2% SET month=%date:~3,2% SET year=%date:~6,4% SET DT=%year%\%month%\%day% @echo Running Loop Script on %DT% ::-----BatchScript1.... ::-----Check Input File Exists cd C:\DOS_Scripts IF NOT EXIST GirlsNames.txt goto :fileDoesNotExist For /F "delims=" %%i in (C:\DOS_Scripts\GirlsNames.txt) do call :callPrintGirlsNames "%%i" goto eof :callPrintGirlsNames Set "NameOfGirl=%~1" call C:\DOS_Scripts\PrintGirlsNames.bat %NameOfGirl% goto eof ::-----eo BatchScript1.... :fileDoesNotExist @ECHO Input File does not exist, End Program. :eof
So, for every instance of a girl’s name “%%i” you will call PrintGirlsNames.bat
Heres the code for PrintGirlsNames.bat
Heres some names to put in your GirlsNames.txt file ….
Joyce Judith Julia Juliana Julianna Julianne Julie Juliet Juliette Julissa Justice Justine Kacie Kaela Kaelyn Kaia Kaila Kailey Kailyn Kaitlin Kaitlyn Kaitlynn Kaiya Kaleigh Kaley Kali Kaliyah Kallie Kalyn Kamryn Kara Kari Karina Karissa Karla Karlee Karley Karli Karlie Karly Kasandra Kasey Kassandra Kassidy Katarina Kate Katelin Katelyn Katelynn Katerina Katharine Katherine Kathleen Kathryn Kathy Katie Katlyn Katrina Katy Kaya Kayla Kaylah Kaylee Kayleigh Kayley Kayli Kaylie Kaylin Kaylyn Kaylynn Keeley
Heres an example of where you might call a Stored Proc that takes a defined date as it’s input and does something with it. Start an iSQL session and …
declare @my_date datetime
select @my_date=CONVERT (datetime,’Jan 18 2011 00:00:000′)
exec myStoredProc @my_date
Copies definitions for specified views, rules, defaults, triggers, or procedures from a database to an operating system file or from an operating system file to a database
defncopy -SmyDatabaseServer -UmyUser –PmyPassword out myStoredProc.out myDatabase myStoredProc
more info on defncopy (12.5)
You’d want to do this to perhaps drop the Stored Proc, alter it in an editor (say vim) and reload it.
Occasionally you might get this error when running sql queries (especially against a “new” database)
ct_connect(): directory service layer: internal directory control layer error:
Which means that there is no details on how to connect to your database (like a tns_names.ora thing).
Short term, you can add a new interfaces file to your profile and use the –I iSQL parameter to override whats in $SYBASE/interfaces.
master tcp ether DBSERV01.systems.uk 10099
query tcp ether DBSERV01.systems.uk 10099
isql -UmyUser -SmyDatabaseServer -DmyDatabase –PmyPassword -I/home/users/kieran/tempIfaceFile
But you’ll be wanting to get your Unix admin to update the Inferaces file to provide a permanent link.
iSQL is the Sybase equivalent of Oracle’s SQL+ I guess. It’s handy to know how to use it as you may now have a nice Sybase GUI front end to use.
From unix try
isql -UmyUser -SmyDatabaseServer -DmyDatabase –PmyPassword
set nocount on
Now simply type your sql followed by “go”
This is a handy example of how to read a file of sql commands and spool the result to an output file.
isql -UmyUser -SmyDatabaseServer -DmyDatabase –PmyPassword -i imput.sql -o result.txt -w600
Comparing dates to timestamps in Sybase isn’t as nice as Oracle but this should do the trick.
select count(*) from MY_TABLE where M_SYS_DATE >= CONVERT (datetime,’Jan 18 2011 00:00:000′) and M_SYS_DATE < CONVERT (datetime,’Jan 19 2011 00:00:000′)
This is my main page for Joomla Content Management. It’s a bit messy at the moment but the idea is to start collecting all the useful tekkie stuff that I’ve picked up over the last several years.
In that time I’ve worked with Oracle, Sybase, Java, VBA, VB.net various Windows and Unix servers, Linux desktop, scripting (Bash, Perl) and various Vendor based commodities trading systems.