Permalink
Browse files

Fixed Insert Command for PostgreSQL

  • Loading branch information...
1 parent 8a514ee commit 6176751659338e5ea5631d800077d44eea4d9396 @kcprogrammer committed Jul 14, 2012
Showing with 1 addition and 2 deletions.
  1. +1 −2 Massive.PostgreSQL.cs
@@ -597,8 +597,7 @@ public virtual dynamic Insert(object o)
{
var cmd = CreateInsertCommand(ex);
cmd.Connection = conn;
- cmd.ExecuteNonQuery();
@kcprogrammer
kcprogrammer Jul 19, 2012 Owner

This line is executing the raw Insert statement returned from CreateInsertCommand(..) but needs the " returned {0} as newid " appended before execution.

- cmd.CommandText = " returning {0} as newid ";
@kcprogrammer
kcprogrammer Jul 19, 2012 Owner

This line is not replacing the {0} with the Primary Key Fields name

+ cmd.CommandText += String.Format(" returning {0} as newid ", PrimaryKeyField);
@kcprogrammer
kcprogrammer Jul 19, 2012 Owner

Here I append " returning {0} as newid " to the Insert Statement as well as fix the {0} replacement with the tables Primary Key Field.

Insert runs as 1 statement to the server returning the ID inserted if it succeeds.

ex.ID = cmd.ExecuteScalar();
Inserted(ex);
}

0 comments on commit 6176751

Please sign in to comment.