google-code-export / dblinq2007

Automatically exported from code.google.com/p/dblinq2007
Other
0 stars 0 forks source link

PostgreSql uuid data type #257

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.Create a table TestTable with an identifier using the uuid type and a
second column with a character varying as testdata
2.generate the DataContext using sqlmetal
3.use the data context in some code to insert a "new TestTable {ID =
Guid.NewGuid(), TestData = "Data" }"
4.use DataContext.Log = Console.Out (or to a file)

What is the expected output? What do you see instead?
Expected :
in the WHERE statement after the INSERT statement has run, we should see :
WHERE ("ID" = ('7DCBA342-D28B-443b-8196-717014501B51')::uuid)

What we see instead :
WHERE ("ID" = 7DCBA342-D28B-443b-8196-717014501B51)

What version of the product are you using? On what operating system?
System.Data.Linq in Mono-2-6 branches (which is supposed to be 0.20 ?)
~/Mono/mono-2-6
$ svn info
Chemin : .
URL : svn://anonsvn.mono-project.com/source/branches/mono-2-6
Racine du dépôt : svn://anonsvn.mono-project.com/source
UUID du dépôt : e3ebcda4-bce8-0310-ba0a-eca2169e7518
Révision : 158311
...
$ sqlmetal /?
DbLinq Database mapping generator 2008 version 0.20
...

PostgreSql version : 8.4.4

Npgsql version : 2.0.9

Linux : ArchLinux (http://archlinux.org/)

In my understanding of the DbLinq code in this mono branch, UUID use is not
provided.

Here is my sample test DataContext.Log, it's not exactly the same as
described in my issue, but still shows that uuid use is not provided :

INSERT INTO "public"."Characters" ("Id", "Name") VALUES (:ID, :Name)
-- :ID: Input Guid (Size = 0; Prec = 0; Scale = 0)
[3e2731f1-4ce2-4d89-b310-6397c2d1197a]
-- :Name: Input String (Size = 0; Prec = 0; Scale = 0) [Toto]
-- Context: PostgreSQL Model: AttributedMetaModel Build: 3.5.0.0
SELECT "CharacterId", "DateRanking", "ExpInLevel", "Id", "Level"
FROM "public"."History"
WHERE ("CharacterId" = 3e2731f1-4ce2-4d89-b310-6397c2d1197a)
-- Context: PostgreSQL Model: AttributedMetaModel Build: 3.5.0.0

Unhandled Exception: Npgsql.NpgsqlException:
syntax error at or near "f1"
Severity: ERROR
Code: 42601
  at
Npgsql.NpgsqlState+<ProcessBackendResponses_Ver_3>c__Iterator1.MoveNext ()
[0x00000] in <filename unknown>:0
  at Npgsql.ForwardsOnlyDataReader.GetNextResponseObject () [0x00000] in
<filename unknown>:0

Original issue reported on code.google.com by guillaum...@gmail.com on 2 Jun 2010 at 10:56

GoogleCodeExporter commented 9 years ago
I had the same issue. Here' what I changed to fix it (in 
src\DbLinq.PostgreSql\PgsqlSqlProvider.cs)

Index: PgsqlSqlProvider.cs
===================================================================
--- PgsqlSqlProvider.cs (revision 1411)
+++ PgsqlSqlProvider.cs (working copy)
@@ -55,6 +55,21 @@
             return SqlStatement.Format("SELECT {0}", SqlStatement.Join(", ", ids.ToArray()));
         }

+        public SqlStatement GetLiteral(Guid literal)
+        {
+            return ("'" + literal.ToString("B") + "'");
+        }
+
+        public override SqlStatement GetLiteral(object literal)
+        {
+            if (literal is Guid)
+            {
+                return this.GetLiteral((Guid)literal);
+            }
+            return base.GetLiteral(literal);
+        }
+
+
         public override SqlStatement GetLiteral(DateTime literal)
         {
             return "'" + literal.ToString("o") + "'::timestamp";
@@ -129,6 +144,7 @@

             {typeof(DateTime),"timestamp"},
             //{typeof(Guid),"uniqueidentifier"}
+            {typeof(Guid),"uuid"},
             {typeof(byte[]),"bytea"},
         };

Original comment by goossens...@gmail.com on 10 Sep 2010 at 2:24

GoogleCodeExporter commented 9 years ago
Hi!

I confirm this issue too. Though I have a slightly different patch to solve it.

Dom

Original comment by kandrait...@gmail.com on 18 Sep 2012 at 4:39

Attachments: