DbLinq / dblinq2007

LINQ provider for Oracle, PostgreSQL, MySQL, Ingres, SQLite, Firebird and ... SQL Server
Other
62 stars 31 forks source link

Reserved MySql words caused an error #166

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a table with a reserved MySql word, like Default
2. Create an Object with DB Metal
3. Query the Object

What is the expected output? What do you see instead?
When you query MySql with reserved words, the field Default will be 
outputted like ('Default'), in Sql Server as [Default].

Original issue reported on code.google.com by ppdewe...@gmail.com on 30 Nov 2009 at 3:10

GoogleCodeExporter commented 9 years ago
Can you elaborate on what the problem is?

What is the table creation SQL?

What do you mean by "create an object with DbMetal"?  DbMetal creates type 
definitions, not object instances.

How are you querying "the Object"?

What exactly is the problem?  Is the generated SQL wrong?  Something else?

Thanks.

Original comment by jonmpr...@gmail.com on 30 Nov 2009 at 3:29

GoogleCodeExporter commented 9 years ago
CREATE TABLE `language` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Name` varchar(100) DEFAULT NULL,
  `Culture` varchar(20) DEFAULT NULL,
  `ImageName` varchar(100) DEFAULT NULL,
  `Default` bit(1) NOT NULL,
  `Active` bit(1) NOT NULL,
  PRIMARY KEY (`Id`),
  UNIQUE KEY `Id` (`Id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1;

This is my Table creation Sql.
The property in the class DBMetal generated is:
private bool _default;
        [DebuggerNonUserCode]
        [Column(Storage = "_default", Name = "Default", DbType = "bit(1)", AutoSync 
= AutoSync.Never, CanBeNull = false)]
        public bool Default
        {
            get
            {
                return _default;
            }
            set
            {
                if (value != _default)
                {
                    OnDefaultChanging(value);
                    SendPropertyChanging();
                    _default = value;
                    SendPropertyChanged("Default");
                    OnDefaultChanged();
                }
            }
        }

I query the object as: dataContext.Language.Where(l => l.Id == 
id).FirstOrDefault()

The generated SQL Query is Select Id, Default, Active From language etc...
The desirect SQL is Select Id, (`Default`) From language (backticks, no quote!)

Hope this is enough information. When i rename my Table column to IsDefault the 
error disappears, so i have a workaround

Original comment by ppdewe...@gmail.com on 30 Nov 2009 at 3:42

GoogleCodeExporter commented 9 years ago
Assuming you're on trunk, could you insert the following in 
src/DbLinq/Vendor/Implementation/SqlProvider.cs at line 1659:

            case "default":

(This is changing the SqlProvider.IsNameSafe() method.)

Then save and rebuild the project.  In theory, this should cause 'Default' to 
be 
quoted as `Default`.

If that works for you, I'll commit the fix.

Thanks!

Original comment by jonmpr...@gmail.com on 30 Nov 2009 at 4:02

GoogleCodeExporter commented 9 years ago
Thanx, this works!

Original comment by ppdewe...@gmail.com on 30 Nov 2009 at 4:23

GoogleCodeExporter commented 9 years ago
Fixed in r1285.

Original comment by jonmpr...@gmail.com on 30 Nov 2009 at 6:27