I'm using Ruby 1.9.3, MS Sql Server and Windows 7 Ultimate
I'd like to know how to check if a certain record is already existing in the database so that I would avoid duplicate records. In rails it would have been easy to just invoke Object.exists? but I'm using Ruby only.
Thanks
Check the source code for exists? in activerecord
It basically checks if there primary key with the id exists already using sql query.
you can use these to write your own helper method.
or else u can also use activerecord gem in ruby too.
Related
I'm using Ruby to create a test script connecting to oracle BD.
I have all the structure already set up, I can already connect and search the database.
Is there any way for me to display the SELECT content? Using only RUBY, I don't use Ruby on Rails.
I am Looking to import(Rather run the schema.sql and seed.sql) in to the SQL server database using sequel gem. Is it possible with the gem? I did some very basic things like creating a database, running few queries etc. But Can not find any example for importing SQL file.
Thanks
j
Sequel doesn't support taking a string/file of multiple SQL statements and running it. You need to provide each SQL statement as a separate query string. Some adapters may allow the submission of multiple SQL statements in a single query string, but it is undefined behavior that depends on which driver is being used.
I have to do a query into an Oracle Database (11g) to extract an HTML file that is stored as a BLOB (yes BLOB, not CLOB) from my Rails 4 Application. So far while working with this database, since it is not well designed, I have been using a number of workarounds to get what I need to out of it. Unfortunately these are no longer working properly, and it would appear that the easiest way to get the HTML file, to later render in my Rails App, would just be to query the Oracle DB for it.
I have googled around on this issue, but everything I have found on the matter with any body to it is from a couple of years ago and no longer of much use to me. So I was wondering if anyone could tell me the best way to connect to an Oracle 11g Database for a single query from a Rails 4 Application / point me in the right direction to find documentation that will help me accomplish this.
Important to Reiterate: I am not trying to get this working with ActiveRecord as my primary DB for my app, instead I need to send one query and manipulate the response of that query.
The ruby-OCI8 gem can be configured to make a single SQL query to an Oracle Database, the docs have instructions on how to set up the necessary Oracle Instant Client.
I'm a newbie to all of this. I'm running a project that uses the sqlite3 Ruby gem, but for some reason one of the table exists already. The project contains a ".sql" and ".db" file, among others.
How can you "view" or manipulate this database if it's running from a sqlite3 gem? Specifically, can you bundle exec rake, etc on it?
From a Rails perspective Sqlite works the same as any other database such as PostreSQL or MySQL in that you can run rake tasks on it (e.g. rake db:create, or db:setup, db:reset, db:migrate, etc. all work as expected). You can also use the rails console to query for or insert new data via your active record model objects.
From a non-Rails perspective, Sqlite has various command-line and GUI interfaces that you can install to interact with a Sqlite database using SQL commands.
I would like to use ActiveRecord in a project without Rails.
I would also like to specify the database connections in config/database.yml like Rails does.
There is already one answer how multiple database connections work with Rails.
ActiveRecord talk to two databases?
I was unsuccessful using this approach and I'm not sure why. I only get the error message "database configuration does not specify adapter".
Is there some kind of magic in Rails that reads the database.yml that is not in ActiveRecord?
I could read it myself but then I don't know how to feed it to ActiveRecord so that I can use establish_connection in each model.
I found out how it works. You just fill the ActiveRecord::Base.configurations hash and then it works.
http://apidock.com/rails/ActiveRecord/Base/configurations/class