Giter Site home page Giter Site logo

Comments (9)

metaskills avatar metaskills commented on May 22, 2024

Yea... this is a major problem and I'm inclined to think there is something special about your setup, else a LOT MORE people would be seeing this, including myself. Can you investigate that a bit more? What table name setting (if any) are you using in a particular AR model? Does this happen everywhere? SQL Server version? Etc etc. The more info the better.

from activerecord-sqlserver-adapter.

metaskills avatar metaskills commented on May 22, 2024

Reported by chagar | April 7th, 2009 @ 06:12 PM

When the model has set_table_name 'MYDATABASE.dbo.myTable', I get the following error, because the column_definitions method lacks a period in its query, or because unqualify_db_name is getting a database name that lacks a period.

Adding a single period in one place, makes it work.

The relevant line in column_definitions is:
FROM #{db_name}INFORMATION_SCHEMA.COLUMNS columns

Error message:

DBI::DatabaseError: S0002 (208) [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name 'MYDATABASEINFORMATION_SCHEMA.COLUMNS'.: SELECT columns.TABLE_NAME as table_name, columns.COLUMN_NAME as name, columns.DATA_TYPE as type, columns.COLUMN_DEFAULT as default_value, columns.NUMERIC_SCALE as numeric_scale, columns.NUMERIC_PRECISION as numeric_precision, CASE WHEN columns.DATA_TYPE IN ('nchar','nvarchar') THEN columns.CHARACTER_MAXIMUM_LENGTH ELSE COL_LENGTH(columns.TABLE_NAME, columns.COLUMN_NAME) END as length, CASE WHEN columns.IS_NULLABLE = 'YES' THEN 1 ELSE NULL end as is_nullable, CASE WHEN COLUMNPROPERTY(OBJECT_ID(columns.TABLE_NAME), columns.COLUMN_NAME, 'IsIdentity') = 0 THEN NULL ELSE 1 END as is_identity FROM MYDATABASEINFORMATION_SCHEMA.COLUMNS columns WHERE columns.TABLE_NAME = 'myTable' ORDER BY columns.ordinal_position

from activerecord-sqlserver-adapter.

sethladd avatar sethladd commented on May 22, 2024

sql server 2005, and we're always using the simple table name, like set_table_name 'foo'

from activerecord-sqlserver-adapter.

metaskills avatar metaskills commented on May 22, 2024

Us too... any idea why this is not working? Can you provide a patch and run the tests against it?

from activerecord-sqlserver-adapter.

sethladd avatar sethladd commented on May 22, 2024

there's a patch on the original lighthouse issue. take a look at that and let me know.

from activerecord-sqlserver-adapter.

metaskills avatar metaskills commented on May 22, 2024

I see this, http://gist.github.com/104210

But that does not tell me if there are tests and/or this has been tested with all the unit tests for the adapter/activerecord?

from activerecord-sqlserver-adapter.

ReggieBeans avatar ReggieBeans commented on May 22, 2024

I get the same error.

I presume the issue is that if a database name isn't specified the SQL code needs to be just:

FROM INFORMATION_SCHEMA.COLUMNS columns

Therefore add a private method:

def db_name_with_period(db_name)

"#{db_name}."

end

And then update the problem line to:

FROM #{db_name_with_period(db_name) if db_name}INFORMATION_SCHEMA.COLUMNS columns

from activerecord-sqlserver-adapter.

metaskills avatar metaskills commented on May 22, 2024

I fixed this in a few places that should wrap up this ticket.
http://github.com/rails-sqlserver/2000-2005-adapter/commit/b9e786b0435840d91681a3e998b15d67de2e5b59

from activerecord-sqlserver-adapter.

ReggieBeans avatar ReggieBeans commented on May 22, 2024

That should do it, and a neater alternative to my suggestion :o)

from activerecord-sqlserver-adapter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.