See "UPDATE" below for what I now know is the crux of the problem.
I have a legacy Derby database that I want to make a Rails application to interface with.
I am using RVM so here are the steps I took:
1. rvm install jruby (installed 1.6.7.2)
2. rvm use jruby
3. gem install rails
4. rails new myapp
5. add "gem 'activerecord-jdbcderby-adapter'" to Gemfile of new rails app
6. bundle
7. copied my derby db folder (named 'perm') under db in the rails app
8. changed database.yml as follows:
development:
adapter: jdbcderby
database: db/perm
Then I made a model file and used set_table_name to set it to one of the table names and when I run rails c I get an exception that the table does not exist.
Also in the console when I do
ActiveRecord::Base.connection.tables
the only table that comes back is "schema_migrations".
I know there is nothing wrong with the database as I can connect to this exact copy and see all the tables using SquirrelSQL. Also, the rails app is connecting in some way since when I open the console I cannot, while the console is running, connect to the same instance using SquirrelSQL, and vice versa.
Does anyone have any suggestion as to why active record doesn't see the tables?
UPDATE:
The problem has something to do with how derby "organizes" tables into multiple "schemas" in the same file. When I create a new table from rails (i.e. with a migration) the table ends up in the "SA" schema. All of my legacy tables are in the "APP" schema (maybe I could move them but I don't want to do that if I can avoid it...other apps would break). So when I access the db from rails this way it's like only the "SA" schema exists. How do I tell Rails to 'use' the "App" schema (early on I tried prefacing the table name but that didn't work)?
I retitled the question accordingly.
UPDATE #2:
Apparently the jdbcderby gem supports the "schema" setting. On a guess I tried changing my database.yml to the following:
development:
adapter: jdbcderby
database: db/perm
schema: app (also tried APP)
When I have the app (or APP) schema setting when I do ActiveRecord::Base.connection.tables in the console I get the list of tables from the app schema (the list shows up with table names all lower case with no schema name).
But I am still having trouble accessing the tables. When I make a model file on an existing table and try to access it I get a JDBCError: "Schema 'SA' does not exist". I have tried various set_table_name calls with no success.
As far as I know there is nothing unusual about my database. But there is no information anywhere on how to do this. Am I the only person on earth who has ever tried to use a legacy Derby database with Rails?
The database name 'db/perm' is being interpreted relative to your current working directory, which is probably not the directory that you think it is. Try either (1) searching your hard disk for the file 'derby.log', which is probably being created in the actual current working directory of your rails app, or (2) specifying the absolute file path to your derby database, not a relative file path.
If the problem is the schema, Derby supports the SET SCHEMA statement: http://db.apache.org/derby/docs/10.8/ref/rrefsqlj32268.html
If you don't explicitly set the schema, it defaults to the username that you connect with, so you can also indirectly set the schema by logging in as the desired username.
Related
I would like to use Oracle database instead of MySQL in Joomla. Is this possible with Joomla, is there a workaround or a solution on how to implement Oracle database with Joomla? Any information will be greatly appreciated.
It is said that it can be done, but it is not a job for beginners and took those guys 3 working days to do it.
Here's why that combination doesn't work by default:
The database and table creation script does not work without modification.
The connection and the database class are written to connect to MySQL and not to Oracle (so they all use MySQL functions).
Some of the extensions use native MySQL functions directly, instead of connecting using the Joomla Database interface (class).
This is what they did to make it work:
We fix the SQL installation script to accommodate the Oracle database in case of a new installation. In case of an existing installation, we export all the database, as well as its data to a SQL file, and then we modify the SQL file (using find and replace) to make it work with an Oracle database.
We load the modified installation file or the modified exported SQL file into the Oracle database.
We then create a copy of the Joomla database class, and then we modify all the functions to work with Oracle instead of MySQL.
We ensure that the Oracle drivers are properly installed and loaded by the php.ini file.
We rename the original MySQL database (you will know in the next step why) to something like database_name_old.
We switch to the new database class and fully test the website to see if some extensions are not working. If an extension ceases to work then it is a sign that this extensions is calling the original MySQL database (which no longer exists because it was renamed) directly.
Hopefully, you aren't a beginner and those guidelines will help you do it. Otherwise, check how much it might cost by visiting the page.
I'm attempting to install Oracle Client 12c and am getting this error:
Ins:32104 - Specified Oracle Home user is not the owner of the specified Oracle Base
I'm thinking that this machine i'm using is missing a registry key for oracle, it looks to me like it does not have an oracle home registry entry which could be causing the issue.
Is there anyway to re-add that key? Or maybe thats not the right approach?
If you want to install a O12c Client in addition of previous Oracle products (O11g,...), in the same directory, you can use this trick:
Let's consider that your actual Oracle Base directory is C:\Oracle and you cannot set the same Base directory for O12c installation (blocked by INS-32104 error code).
You can set C:\Oracle\Product\12.2.0 as O12c Base dir.
Then just set C:\Oracle\Product\12.2.0\client_1 as O12c Home dir.
OUI accepts this, the setup goes on. So you keep a nearly standard setup, without removing neither changing any of your previous Oracle products.
I managed to finalize the installation by removing the environment variable ORACLE_HOME, because in my system I have another installed client (11.2).
I fixed this problem by removing previous oracle clients and manually removing files in the destination base folder (C:\oracle).
i have just started working on an application in PHP. I have configured the Postgres add on in my application on Heroku. But i am still not sure how to start working on the DATABASE. what i mean is that there is a thing called DATACLIP on the POSTGRES DB window on Heroku and when i try to create a table there, it gives me some weird errors.
But no matter what query i write there, it always gives me some error. So, i am not sure whether i can create the Tables and insert my data from DATACLIP or not. and If not, from where can i do this?
Dataclips are only useful for read-only queries. Think gist for SQL and data.
To create data on your database, you can:
Use database migrations that run within the heroku platform itself
Connect to your database using the provided credentials from anywhere (you must use SSL). To get credentials, either run heroku pg:credentials <DATABASE_COLOR> --app <YOUR_APP>, or go to your database in http://postgres.heroku.com. You should be able to use pg_admin or any other postgres front end to connect and create tables.
You can connect directly using the heroku toolbelt (and assuming you have a proper psql installation in your dev box) with heroku pg:psql --app <YOUR_APP>. From there just use SQL to create your data (CREATE TABLE, etc)
I was making a web app to deploy using Heroku.com when I realized that the only database type they support is PostgreSQL. Up until now, my app (powered by the Ruby gem Sinatra) accessed the database via the .Sqlite method for the Sequel gem.
Here's my Ruby script from when I used Sequel to access the .db file via SQLite:
DB = Sequel.sqlite('mydatabase.db')
DB.create_table :mytable do
primary_key :id
String :column_name
end
I installed PostgreSQL after learning Heroku used only that. Here's the script via postgres (my username is literally 'postgress', though I obviously won't reveal my password in this question):
DB = Sequel.postgres('mydatabase.db',:user=>'postgres',:password=>'my_password_here',:host=>'localhost',:port=>5432,:max_connections=>10)
DB.create_table :mytable do
primary_key :id
String :column_name
end
However, when I run this code, I get the following error:
C:/Ruby193/lib/ruby/gems/1.9.1/gems/sequel-3.38.0/lib/sequel/adapters/postgres.rb:208:in 'initialize': PG::Error: FATAL: database "mydatabase.db" does not exist (Sequel::DatabaseConnectionError)
I've tried searching Google, StackOverflow, Sequel documents, and the Heroku help documents for any help, but I've found no fix to this problem.
Does anyone know what I am doing wrong?
The database mydatabase.db doesn't exist, as per the error message from Pg. Likely reasons:
You probably meant mydatabase without the SQLite-specific .db filename suffix
It's possible you created the db with different case, eg "Mydatabase.db";
You might be connecting to a different Pg server than you think you are
You never created the database. Unlke SQLite's default behaviour, Pg doesn't create databases when you try to connect to a database that doesn't exist yet.
If in doubt, connect to Pg with psql and run \l to list databases, or connect via PgAdmin-III.
The PostgreSQL documentation and tutorial are highly recommended, too. They're well written and will teach you a lot about SQL in general as well as Pg in particular.
BTW, the postgres user is a superuser. You should not be using it for your application; it's like running your server as root, ie a really bad idea. Create a new PostgreSQL user without superuser, createdb or createuser rights and use that for your application. You can either CREATE DATABASE somedb WITH OWNER myappuser - or preferably, create the database owned by a different user to your webapp user and then expicitly GRANT the webapp user the minimum required permissions. See user management and GRANT.
On heroku all you need to do is tell Sequel to connect to the content of the DATABASE_URL environment variable (which is a properly formed url that Sequel understands):
DB = Sequel.connect(ENV['DATABASE_URL'])
I have an installer wizard thing called 'install creator'. I want to include my mySQL database into the installer or find another way that the user, upon installation, can just use my database. Prob is-not everyone has MySQL installed on the computer and even then, the user doesn't know the name of the database or my password. Somehow the database must be created automatically upon install, and for my purposes, some of the tables created. How can one do this. Thanks
If you are just using MySQL as a local storage engine, as it seems to be what you are doing, then you should consider using Sqlite with JDBC, instead of MySQL. MySQL is really intended to be used on a server, where information from multiple users is stored, and where the database is accessed only indirectly through the programs that you create that run on the server. You could, in theory, package up MySQL and MySQL Connector/J which lets JDBC talk with MySQL; however, MySQL is a pretty big beast, and I don't think it's nice to do that to your users (also, don't forget that they might already have MySQL installed, and if you were to install MySQL for the first time, you would effectively be forcing them to use your root password). Unlike MySQL, sqlite is intended to provide the structure of SQL for use with lightweight, local file storage.