nsabiyera / Oak

Frictionless development for ASP.NET MVC single page web apps. Prototypical and dynamic capabilities brought to C#.
http://amirrajan.github.com/Oak
MIT License
6 stars 7 forks source link

Unable to excute database query due table name is the same as T-Sql keyword #46

Open sharpcoder7 opened 8 years ago

sharpcoder7 commented 8 years ago

Hello! I begin dig this good project and found an issue. If I have table [Order] massive throws an exception because the table name is a t-sql keyword. So in all requests we need to use [Order] instead of Order. So I think the solution will be a creating of HashSet of t-sql keywords and check table name before it will be inserted into a query. Possible another easiest solutions exists?

ps I cant rename the table because another software uses this database .

amirrajan commented 8 years ago

Can you give me some sample code? Are you using DynamicDb or DynamicRepository?

sharpcoder7 commented 8 years ago
dynamic db = new DynamicDb();
var all = db.Order.All();
amirrajan commented 8 years ago

Just change this line: https://github.com/amirrajan/Oak/blob/master/Oak/DynamicDb.cs#L30 to

var tableName = "[" + callInfo.Name + "]";

The source code should be under a folder called /Oak in your project.

sharpcoder7 commented 8 years ago

sorry but this will not work. In method TableExists. we quering .Query("select name from sysobjects where name = @0", table) if table name will contain square brackets like [DailySettlements] then this script returns zero record. program will fail due table [DailySettlements] is not exists

amirrajan commented 8 years ago

Hmm, maybe just put "[" + tableName + "]" around this line? https://github.com/amirrajan/Oak/blob/master/Oak/DynamicDb.cs#L39

amirrajan commented 8 years ago

You could also add table.Replace("[", "").Replace("]", "") here: https://github.com/amirrajan/Oak/blob/master/Oak/Association.cs#L1031