|
From: <aye...@us...> - 2008-10-11 00:01:43
|
Revision: 3839
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=3839&view=rev
Author: ayenderahien
Date: 2008-10-11 00:01:33 +0000 (Sat, 11 Oct 2008)
Log Message:
-----------
NH-1520 SQLite Dialect does not properly escape names surrounded by backticks
(should learn to commit to the right branch)
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Dialect/SQLiteDialect.cs
trunk/nhibernate/src/NHibernate.Test/DialectTest/SQLiteDialectFixture.cs
Modified: trunk/nhibernate/src/NHibernate/Dialect/SQLiteDialect.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Dialect/SQLiteDialect.cs 2008-10-10 23:34:34 UTC (rev 3838)
+++ trunk/nhibernate/src/NHibernate/Dialect/SQLiteDialect.cs 2008-10-11 00:01:33 UTC (rev 3839)
@@ -113,24 +113,52 @@
public override string Qualify(string catalog, string schema, string table)
{
StringBuilder qualifiedName = new StringBuilder();
+ bool quoted = false;
if (!string.IsNullOrEmpty(catalog))
{
- if (catalog.EndsWith(CloseQuote.ToString()))
- catalog = catalog.Substring(0, catalog.Length - 1);
+ if (catalog.StartsWith(OpenQuote.ToString()))
+ {
+ catalog = catalog.Substring(1, catalog.Length - 1);
+ quoted = true;
+ }
+ if (catalog.EndsWith(CloseQuote.ToString()))
+ {
+ catalog = catalog.Substring(0, catalog.Length - 1);
+ quoted = true;
+ }
qualifiedName.Append(catalog).Append(StringHelper.Underscore);
}
if (!string.IsNullOrEmpty(schema))
{
if (schema.StartsWith(OpenQuote.ToString()))
- schema = schema.Substring(0, schema.Length - 1);
- qualifiedName.Append(schema).Append(StringHelper.Underscore);
+ {
+ schema = schema.Substring(0, schema.Length - 1);
+ quoted = true;
+ }
+ if (schema.EndsWith(OpenQuote.ToString()))
+ {
+ schema = schema.Substring(1, schema.Length - 1);
+ quoted = true;
+ }
+ qualifiedName.Append(schema).Append(StringHelper.Underscore);
}
if (table.StartsWith(OpenQuote.ToString()))
- table = table.Substring(1, table.Length - 1);
+ {
+ table = table.Substring(1, table.Length - 1);
+ quoted = true;
+ }
+ if (table.EndsWith(OpenQuote.ToString()))
+ {
+ table = table.Substring(0, table.Length - 1);
+ quoted = true;
+ }
- return qualifiedName.Append(table).ToString();
+ string name = qualifiedName.Append(table).ToString();
+ if (quoted)
+ return OpenQuote + name + CloseQuote;
+ return name;
}
Modified: trunk/nhibernate/src/NHibernate.Test/DialectTest/SQLiteDialectFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/DialectTest/SQLiteDialectFixture.cs 2008-10-10 23:34:34 UTC (rev 3838)
+++ trunk/nhibernate/src/NHibernate.Test/DialectTest/SQLiteDialectFixture.cs 2008-10-11 00:01:33 UTC (rev 3839)
@@ -43,6 +43,48 @@
}
[Test]
+ public void QuotedTableNameWithoutSchemaWithSqlLite()
+ {
+ Table tbl = new Table();
+ tbl.Name = "`name`";
+
+ Assert.AreEqual("\"name\"", tbl.GetQualifiedName(dialect));
+ }
+
+ [Test]
+ public void QuotedSchemaNameWithUnqoutedTableInSqlLite()
+ {
+ Table tbl = new Table();
+ tbl.Schema = "`schema`";
+ tbl.Name = "name";
+
+ Assert.AreEqual("\"schema_name\"", tbl.GetQualifiedName(dialect));
+ Assert.AreEqual("\"schema_table\"", dialect.Qualify("", "\"schema\"", "table"));
+ }
+
+ [Test]
+ public void QuotedCatalogSchemaNameWithSqlLite()
+ {
+ Table tbl = new Table();
+ tbl.Catalog = "dbo";
+ tbl.Schema = "`schema`";
+ tbl.Name = "`name`";
+
+ Assert.AreEqual("\"dbo_schema_name\"", tbl.GetQualifiedName(dialect));
+ Assert.AreEqual("\"dbo_schema_table\"", dialect.Qualify("dbo", "\"schema\"", "\"table\""));
+ }
+
+ [Test]
+ public void QuotedTableNameWithSqlLite()
+ {
+ Table tbl = new Table();
+ tbl.Name = "`Group`";
+
+ Assert.AreEqual("\"Group\"", tbl.GetQualifiedName(dialect));
+ }
+
+
+ [Test]
public void SchemaNameWithSqlLite()
{
Table tbl = new Table();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|