Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot update record if primary key of table is uuid #152

Closed
GoogleCodeExporter opened this issue Apr 24, 2015 · 5 comments
Closed

Cannot update record if primary key of table is uuid #152

GoogleCodeExporter opened this issue Apr 24, 2015 · 5 comments

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
1.Select a record from a table which has a uuid primary key
2.updated a field
3.call submitchanges()

What is the expected output? What do you see instead?
ERROR: 42601: syntax error at or near "b6"

What version of the product are you using? On what operating system?
dblinq 0.19.0.0 with bundled npgsql dll

Please provide any additional information below.

The problem is because the update query parameter for the uuid is not
surrounded by quotes.

What SHOULD be UPDATE "Unit" SET name = 'dammit' WHERE auditablerecordid =
'938147b6-69a0-475a-9f0b-9c9600bc1cd2';
is actually executed by dblinq/npgsql as 
UPDATE "Unit" SET name = 'dammit' WHERE auditablerecordid =
938147b6-69a0-475a-9f0b-9c9600bc1cd2; <<<bad

The definition for Unit contains this primary key info:

#region Guid AuditAbleRecordID

    private Guid _auditAbleRecordID;
    [DebuggerNonUserCode]
    [Column(Storage = "_auditAbleRecordID", Name = "auditablerecordid", DbType
= "uuid", IsPrimaryKey = true, AutoSync = AutoSync.Never, CanBeNull = false)]
    public Guid AuditAbleRecordID
    {
        get
        {
            return _auditAbleRecordID;
        }
        set
        {
            if (value != _auditAbleRecordID)
            {
                _auditAbleRecordID = value;
                OnPropertyChanged("AuditAbleRecordID");
            }
        }
    }

    #endregion

Stack trace:

   at Npgsql.NpgsqlState.<ProcessBackendResponses_Ver_3>d__a.MoveNext()
   at Npgsql.ForwardsOnlyDataReader.GetNextResponseObject()
   at Npgsql.ForwardsOnlyDataReader.GetNextRowDescription()
   at Npgsql.ForwardsOnlyDataReader.NextResult()
   at Npgsql.ForwardsOnlyDataReader..ctor(IEnumerable`1 dataEnumeration,
CommandBehavior behavior, NpgsqlCommand command, NotificationThreadBlock
threadBlock, Boolean synchOnReadError)
   at Npgsql.NpgsqlCommand.GetReader(CommandBehavior cb)
   at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior cb)
   at Npgsql.NpgsqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
   at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader()
   at
DbLinq.Data.Linq.Sugar.Implementation.QueryRunner.Select[T](SelectQuery
selectQuery) in
C:\Users\whitcombecr\Desktop\dblinq\DbLinq\Data\Linq\Sugar\Implementation\QueryR
unner.cs:line
70
   at DbLinq.Data.Linq.Implementation.QueryProvider`1.GetEnumerator() in
C:\Users\whitcombecr\Desktop\dblinq\DbLinq\Data\Linq\Implementation\QueryProvide
r.cs:line
216
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at DbLinq.Data.Linq.EntitySet`1.get_Source() in
C:\Users\whitcombecr\Desktop\dblinq\DbLinq\Data\Linq\EntitySet.cs:line 59
   at DbLinq.Data.Linq.EntitySet`1.GetEnumerator() in
C:\Users\whitcombecr\Desktop\dblinq\DbLinq\Data\Linq\EntitySet.cs:line 118
   at
DbLinq.Data.Linq.EntitySet`1.System.Collections.IEnumerable.GetEnumerator()
in C:\Users\whitcombecr\Desktop\dblinq\DbLinq\Data\Linq\EntitySet.cs:line 127
   at DbLinq.Data.Linq.DataContext.UpdateReferencedObjects(Object root) in
C:\Users\whitcombecr\Desktop\dblinq\DbLinq\Data\Linq\DataContext.cs:line 534
   at DbLinq.Data.Linq.DataContext.UpdateEntity(Object entity, QueryContext
queryContext) in
C:\Users\whitcombecr\Desktop\dblinq\DbLinq\Data\Linq\DataContext.cs:line 506
   at DbLinq.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode)
in C:\Users\whitcombecr\Desktop\dblinq\DbLinq\Data\Linq\DataContext.cs:line 435
   at DbLinq.Data.Linq.DataContext.SubmitChanges() in
C:\Users\whitcombecr\Desktop\dblinq\DbLinq\Data\Linq\DataContext.cs:line 369
   at joiislinqtest.Form1..ctor() in
D:\Data\Projects\EventGen\joiislinqtest\joiislinqtest\Form1.cs:line 33
   at joiislinqtest.Program.Main() in
D:\Data\Projects\EventGen\joiislinqtest\joiislinqtest\Program.cs:line 18
   at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

Original issue reported on code.google.com by craig.wh...@gmail.com on 2 Oct 2009 at 12:27

@GoogleCodeExporter
Copy link
Author

forgot of course to mention that I am using Postgresql (version 8.3),
Thanks,
Craig

Original comment by craig.wh...@gmail.com on 2 Oct 2009 at 12:29

@GoogleCodeExporter
Copy link
Author

Sqlite suffers from the same issue. I managed to fix it for both of them but I 
feel
my solution is pretty hackish. I overloaded

protected virtual SqlStatement GetLiteralEqual(SqlStatement a, SqlStatement b)

in SqlProvider for PgsqlSqlProvider and SqliteSqlProvider as such (for sqlite):

    protected override SqlStatement GetLiteralEqual(SqlStatement a, SqlStatement b)

        {

            if (a.Count == 1 && b.Count == 1 && b[0].Sql.Length > 0 && b[0].Sql.Substring (0,
1) != ":")

                return SqlStatement.Format("{0} = '{1}'", a, b);

            else

                return SqlStatement.Format("{0} = {1}", a, b);

        }



        protected override SqlStatement GetLiteralNotEqual(SqlStatement a,
SqlStatement b)

        {

            if (a.Count == 1 && b.Count == 1 && b[0].Sql.Length > 0 && b[0].Sql.Substring (0,
1) != ":")

                return SqlStatement.Format("{0} <> '{1}'", a, b);

            else

                return SqlStatement.Format("{0} <> {1}", a, b);

        }       

It works fine using this. Didn't test it too much yet but it doesn't seem to 
have any
side effects.

Original comment by matthieu...@gmail.com on 19 Jan 2010 at 3:29

@GoogleCodeExporter
Copy link
Author

DbLinq 0.19 wasn't released until December, so I wonder what 0.19 this was...

That aside, this sounds rather like 
http://code.google.com/p/dblinq2007/issues/detail?
id=137 in that Guid's aren't properly supported.

Is this a dup?

Original comment by jonmpr...@gmail.com on 20 Jan 2010 at 10:04

  • Changed state: StandBy
  • Added labels: Component-DbLinq, Priority-Low, Type-Defect

@GoogleCodeExporter
Copy link
Author

I have the problem using 0.19final. I checked the bug report and to me, it 
seems like
a dup.

Original comment by matthieu...@gmail.com on 21 Jan 2010 at 5:23

@GoogleCodeExporter
Copy link
Author

Closing due to lack of response.

Original comment by jonmpr...@gmail.com on 9 Apr 2010 at 7:48

  • Changed state: Closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant