SQLite3/Ruby 1.2.5 Released!

Posted: July 25th, 2009 | Author: FreedomCoder | Filed under: Open Source, Programming, SQL | Tags: , , | No Comments »

I just released an updated version of SQLite3/Ruby, officially to RubyForge!

Read the news here

This release includes binaries for Windows, but not any kind of binary, but fat ones!

That means that using either 1.8 or 1.9 versions of Ruby you will be able to access SQLite3/Ruby bindings and script your craziest applications!

This also solves the major PITA for gem update that lot of user experienced in the past.

Don’t forget to read a getting started guide here

Now is time to hunt down MySQL gem author and politely ask him integrate my patches ;)

(Via DEV_MEM.dump_to(:blog) – Multimedia systems blog.) Original Link: SQLite3/Ruby 1.2.5 Released!


Stepping up as SQLite3/Ruby maintainer

Posted: July 13th, 2009 | Author: FreedomCoder | Filed under: Open Source, Programming, SQL | Tags: , , | No Comments »

So, I think this may be good news for some folks.

February 24, 2009 is the date that Jamis Buck marked as the end of several of his open source projects, including SQLite3/Ruby. (you can read the post here)

Previously, he asked for help updating SQLite3/Ruby to make it work on Windows.

That sad news left a lot of us with a bad taste, and very unhappy, not because we no longer will have someone to complain at, but because he no longer enjoyed working on those projects.

Over the past months I’ve been improving rake-compiler to be able to catch most of the building issues of several projects, including my own (I love to scratch my own itch).

As you have noticed on my “getting started with Rails and SQLite3″: http://blog.mmediasys.com/2009/07/06/getting-started-with-rails-and-sqlite3/ post, I successfully built, installed and used a SQLite3/Ruby gem on Windows.

The next question was, what to do? The work to get all those lovely gems was there, initial 1.9 was there, but was not official

While SQLite3/Ruby being the de-facto for getting started with Rails, we couldn’t let it die.

Enough words, sent some emails to Jamis and now I can publish those gems to RubyForge.

What all that babbling means?

This means:

  • My fork at GitHub is the new mainstream for the releases
  • I’m going to go over the open bugs and tickets and asses validity and relevancy based on work that was already done in my fork.
  • The release cycle has been improved and almost automated. It can be performed from Windows, Linux or OSX, even using latter to create Windows native gems.

Now, what happens with new features:

  • Pull requests with patches and bug fixes are going to be accepted.
  • New features will be evaluated as long they don’t impose structural changes and carry with them tests cases.
  • Patches that improve Ruby 1.9 compatibility are highly appreciated.

I don’t have strong knowledge of all the internals of this tool, so don’t expect earth breaking changes from me, except ensuring stability.

I hope this is good news to everybody. Now I’m going to stalk MySQL binding author and get permission to push those lovely gems ;-)

Cheers everybody!

(Via DEV_MEM.dump_to(:blog) – Multimedia systems blog.) Original Link: Stepping up as SQLite3/Ruby maintainer


RubyInstaller: Getting Started with Rails and SQLite3

Posted: July 7th, 2009 | Author: FreedomCoder | Filed under: Rails, SQL, how-to | Tags: , , | 1 Comment »

A few folks asked this over the past weeks, and since I released preview1 version of RubyInstaller, wouldn’t be awesome I write a guide for it?

So, here we go

First, Getting Ruby

Please download from here one of the preview1 installers for Ruby.

For this demonstration, I’m going to use Ruby 1.9.1-p129. Downloaded, executed and installed to it’s default location C:\Ruby19

Now, start a Command prompt with Ruby (under start menu, inside Ruby 1.9.1-p129).

Command Prompt with Ruby

Getting SQLite3

As you may know, Windows do not came out of the box with libraries like SQLite3. For this, we are going to download it from Internet.

Going to SQLite downloads, under Precompiled binaries for Windows, download sqlitedll-3_6_16.zip and sqlite-3_6_16.zip. Those two packages contains the DLL (sqlite3.dll) and the command line executable for SQLite (sqlite3.exe).

Please extract those contents inside C:\Ruby19\bin

Now, let’s get the Ruby bindings for SQLite3

Getting SQLite3/Ruby bindings

As you may know, the preferred way to distribute Ruby libraries is using Gems. Users on other platforms usually compile themselves these components, using the mechanisms provided by the operating system distribution.

We are going to avoid the compilation process using pre-compiled binaries that has been cooked for us.

So, back to the Command Prompt with Ruby, let’s install the sqlite3 bindings:

gem install sqlite3-ruby --source http://gems.rubyinstaller.org

Adding --source help us indicate a non-standard location from where gems are going to be installed. RubyInstaller team has built and packaged special versions of these gems that we hope get published soon into RubyForge, the official place for gem distribution.

Once installed, you should see something like this at the screen:

Successfully installed sqlite3-ruby-1.2.4.1-x86-mingw32
1 gem installed

These special version of the gem are fat binaries, which means these can be safely installed on Ruby 1.8.6 or 1.9.1.

Getting Rails

Now it’s time to install and build a Rails application. First, let’s install the rails gem:

gem install rails

That command is going to take a bit, since is a 2MB or so download, and will install several of the Rails dependencies (ActiveRecord, ActionPack, ActiveSupport, etc). You should expect similar output to this:

Successfully installed activesupport-2.3.2
Successfully installed activerecord-2.3.2
Successfully installed actionpack-2.3.2
Successfully installed actionmailer-2.3.2
Successfully installed activeresource-2.3.2
Successfully installed rails-2.3.2
6 gems installed

Let’s build our application now.

Creating a Rails application.

Let’s call the application railsapp

rails railsapp

An excerpt of the output you should get:

      create
      create  app/controllers
      create  app/helpers
      create  app/models
      create  app/views/layouts
      create  config/environments
      create  config/initializers
      create  config/locales
      create  db
...

Rails 2.3.2 defaults it’s database format to SQLite3, so there is no need for us to tweak anything.

Checking if everything is ok, using script\about:

cd railsapp
ruby script\about

And the output should be something like this:

About your application's environment
Ruby version              1.9.1 (i386-mingw32)
RubyGems version          1.3.4
Rack version              1.0 bundled
Rails version             2.3.2
Active Record version     2.3.2
Action Pack version       2.3.2
Active Resource version   2.3.2
Action Mailer version     2.3.2
Active Support version    2.3.2
Application root          C:/Users/Luis/railsapp
Environment               development
Database adapter          sqlite3
Database schema version   0

Now, it’s up to you create your models, controllers and everything.

Some notes and considerations.

At the time of this writing, Mongrel has not been updated to build and install properly either on 1.9 or MinGW versions of Ruby.

As part of Mongrel development team, I’m going to work on a solution for this in the upcoming days.

If you find something wrong with the Ruby Installer, please report here, but issues with your code, Rails or other are not responsability of RubyInstaller.

The binary gems provided at gems.rubyinstaller.org are based on our forks of sqlite3-ruby, which can be cloned and explored here at GitHub.

Keep in mind that some gems would not work under Ruby 1.9, or you will need a compiler (DevKit) for it. See previous post with details how to get those from our download page.

(Via DEV_MEM.dump_to(:blog) – Multimedia systems blog.) Original Link: RubyInstaller: Getting Started with Rails and SQLite3


RubyInstaller: Getting Started with Rails and MySQL

Posted: July 7th, 2009 | Author: FreedomCoder | Filed under: Rails, SQL, how-to | Tags: , , | No Comments »

This is a follow up instruction set from previous post, but this time, using MySQL

Getting Ruby

These steps are the same for Ruby 1.9 or Ruby 1.8, please feel free to download the installer from here

For this guide I’m going to use Ruby 1.9.1-p129, since it the coolest new version that all the guys are playing with ;)

Now, start a Command prompt with Ruby (under start menu, inside Ruby 1.9.1-p129).

Command Prompt with Ruby 1.9

Getting the right MySQL version

While building the MySQL/Ruby bindings, we found that mixing versions of the bindings with different versions of MySQL installations ended on undesired results (abnormal program termination, weird errors, etc.)

For this guide, and because we are going to use binary gems, we are going to stick to MySQL version 5.0.83.

Now is time to download MySQL. For this guide, I’m going to install the essentials version, which contains only MySQL and command line tools, no Query Builder or any other administrative tool.

Please go to this page and download Windows Essentials (x86). Once downloaded you will end with mysql-essential-5.0.83-win32.msi file. Execute it and install with defaults.

Configure MySQL

If you’re an advanced and savvy MySQL user, you can skip the following steps. For the sake of this guide, I’m going to list the simple options you must follow when installing it.

Once you installed MySQL, the installer should have started the Configuration Wizard page.

Inside of it, please apply the following options:

Option/Screen Value
Configuration Type Detailed configuration
Server type Developer Machine
Database usage Transactional Database only
InnoDB datafile Your option or leave defaults
Number of connections Decision Support
Networking options Check Add firewall exceptions
Character set Best support for Multilingualism (UTF8)
Windows Options Add to PATH if you want mysql available on every prompt
Security Options Uncheck if you want root password be blank

Once done with all this, on the summary screen, please click Execute to complete the configuration of MySQL Server.

Under some system, starting of MySQL server will fail during this wizard, but don’t be afraid, most of the times, this can be safely ignored.

To check everything was properly installed, please go to the Start Menu, and inside MySQL Server 5.0, click on MySQL Command Line Client

If you changed the root password, or, like me, leaved it unchecked, you can simply press enter when asked for the password and see that the server is running!

MySQL Console Client

If you decided to add MySQL to the PATH, you will require to restart your computer so the PATH change is available to the system.

If you decided not to add MySQL to the PATH, please go, with Explorer to the location where you installed MySQL Server and copy libmySQL.dll into C:\Ruby19\bin

In my case, I found this file in C:\Program Files\MySQL\MySQL Server 5.0\bin

Now, it is time to install the bindings.

Getting MySQL/Ruby

For this version of Ruby, there is no official binary gems for both Ruby 1.8 and 1.9. So we are going to install the specially built version from RubyInstaller gems repository.

At the Command Prompt with Ruby, please enter the following command:

gem install mysql --source http://gems.rubyinstaller.org
  

This is going to install the special version of MySQL bindings. This version works with Ruby 1.8 and 1.9, since bundles fat binaries. You should expect a similar output like this:

Successfully installed mysql-2.8.1.1-x86-mingw32
1 gem installed

Getting Rails

Now is time to install Rails and build our application. At the same command prompt, please enter the following command:

gem install rails

This is going to take a bit, since Rails and it’s dependencies takes around 2MB or so, and need to be downloaded and installed.

Once done, expect see at the screen something like this:

Successfully installed activesupport-2.3.2
Successfully installed activerecord-2.3.2
Successfully installed actionpack-2.3.2
Successfully installed actionmailer-2.3.2
Successfully installed activeresource-2.3.2
Successfully installed rails-2.3.2
6 gems installed

Creating a Rails application

Let’s name our application mysqlapp

rails mysqlapp --database=mysql

The --database option indicates to Rails that we want to use MySQL instead of the default database adapter (SQLite3).

Rails will output a lot of lines when creating your application structure, just an excerpt of what to see:

...
      create  config/database.yml
      create  config/routes.rb
      create  config/locales/en.yml
      create  config/initializers/backtrace_silencers.rb
      create  config/initializers/inflections.rb
      create  config/initializers/mime_types.rb
      create  config/initializers/new_rails_defaults.rb
      create  config/initializers/session_store.rb
      create  config/environment.rb
...

Configuring our Database

Now Rails have configured for us the name of the database we want to use, and you can verify it in config\database.yml

Rails will try to connect to mysqlapp_development, but that database do not exist in our fresh new MySQL server.

So, let’s create it:

cd mysqlapp
rake db:create

Just that, simple db:create is going to connect to our MySQL server, and create the database for us.

Keep in mind that if you changed root password or want to use other MySQL user to connect to the database, you need to edit database.yml to reflect those changes.

Let’s verify that everything is in place, using the following command:

About your application's environment
Ruby version              1.9.1 (i386-mingw32)
RubyGems version          1.3.4
Rack version              1.0 bundled
Rails version             2.3.2
Active Record version     2.3.2
Action Pack version       2.3.2
Active Resource version   2.3.2
Action Mailer version     2.3.2
Active Support version    2.3.2
Application root          C:/Users/Luis/mysqlapp
Environment               development
Database adapter          mysql
Database schema version   0

Now is up to you to create your models, controllers and views!

Some notes and considerations

On other post I’m going to guide you with steps on building the bindings against MySQL 5.1.36, since you will need to install the Ruby Development Kit and the development headers for MySQL.

If you find something wrong with the Ruby Installer, please report it here, but issues with your code, Rails or other are not responsability of RubyInstaller.

The binary gems provided at gems.rubyinstaller.org are based on our forks of mysql bindings, which can be cloned and explored here at GitHub.

Keep in mind that some gems would not work under Ruby 1.9, or you will need a compiler (DevKit) for it. See previous post with details how to get those from our download page.

(Via DEV_MEM.dump_to(:blog) – Multimedia systems blog.) Original Link: RubyInstaller: Getting Started with Rails and MySQL


Creando consultas ActiveRecord a partir de SQL

Posted: March 22nd, 2009 | Author: FreedomCoder | Filed under: ActiveRecord, Programming, SQL | Tags: , , , | Comments Off

Buscando la razón por la cual me falla un find_each dentro de un rake, me encontré con este sitio que sin dudas no deja de ser interesante. Suele pasar que tenemos en claro como construir una sentencia SQL pero no sabemos como hacerlo en ActiveRecord. Este pequeño script lo resuelve. Lo estuve probando y hay casos en los que no devuelve nada, como ser pasando rangos con BETWEEN, por ejemplo.


select * from members where first_name = 'Harold' and age = '34'
=> Members.find(:all, :conditions => {:age => "34", :first_name => "Harold"}

select * from members
=> Members.find(:all)

select * from members where first_name = 'Harold'
=> Members.find(:all, :conditions => {:first_name => "Harold"}

select * from members where first_name like '%Harold%'
=> Members.find(:all, :conditions => ["first_name like ?", '%Harold%'])

leer más

(Via Rodolinux – Rodolinux’s Playground.)Original Link: Creando consultas ActiveRecord a partir de SQL