SubSonic Forums
All Your Database Are Belong To Us

SubSonicRepository Insert bug

Latest post 06-20-2008 4:56 PM by spookytooth. 5 replies.
  • 06-12-2008 8:26 AM

    SubSonicRepository Insert bug

    Hello!

    I think I found a bug in the repository insert when not using autoincrement-pk. The query will never execute unless its autoincrement.

    My fix was just to move the ExecuteScalar-statement to make sure its run. I dont know if its the correct way though!

     

    Index: SubSonicRepository.cs
    ===================================================================
    --- SubSonicRepository.cs    (revision 453)
    +++ SubSonicRepository.cs    (working copy)
    @@ -206,13 +206,16 @@
                 
                 int result = 0;
                 QueryCommand cmd = ActiveHelper<T>.GetInsertCommand(item, userName);
    +
                 TableSchema.Table schema = item.GetSchema();
                 if (schema.PrimaryKey != null)
                 {
    +                object qResult = DataService.ExecuteScalar(cmd);
    +
                     if(schema.PrimaryKey.AutoIncrement)
                     {
    -                    object qResult = DataService.ExecuteScalar(cmd);
                         item.SetColumnValue(schema.PrimaryKey.ColumnName, qResult);
    +
                         if(qResult != null)
                             int.TryParse(qResult.ToString(), out result);
                     }

    Filed under: , ,
  • 06-17-2008 3:53 PM In reply to

    Re: SubSonicRepository Insert bug

    Thanks for this - i'll see what I can do here; not sure what you've added will solve the issue but it's close ;).

    Find a bug? Create a Work Item for a fast response.. Want to help? Create a patch for us!

  • 06-17-2008 3:57 PM In reply to

    Re: SubSonicRepository Insert bug

    I added an else in there to make sure it gets executed - thanks for the catch!

    Find a bug? Create a Work Item for a fast response.. Want to help? Create a patch for us!

  • 06-20-2008 9:37 AM In reply to

    • Soni
    • Not Ranked
    • Joined on 06-20-2008
    • Posts 3

    Re: SubSonicRepository Insert bug

    Hello

     

    There still is a bug in the insert.

     

    If you have a table with a Primary Key thats NOT autoincremented, it wont run the insert.

    I made this change

     

                if (schema.PrimaryKey != null)
                {

                    object qResult = DataService.ExecuteScalar(cmd); // Moved this line out of the AutoIncrement test

                    if(schema.PrimaryKey.AutoIncrement)
                    {
                        item.SetColumnValue(schema.PrimaryKey.ColumnName, qResult);
                        if(qResult != null)
                            int.TryParse(qResult.ToString(), out result);
                    }
                }
                else
                {
                    result = DataService.ExecuteQuery(cmd);
                }

    Im using the newest RC1 download today.

     

    BR

    Søren

     

  • 06-20-2008 2:23 PM In reply to

    Re: SubSonicRepository Insert bug

    Did you check the version from SVN

    If I am I because I am I, and You are You because You are You, then I am I, and you are you. But If I am I because You are You, and You are You because I am I, then I am not I and You are not You. -Rabbi of Kotzk

  • 06-20-2008 4:56 PM In reply to

    Re: SubSonicRepository Insert bug

    Hi Soren - this won't fix the issue. What I did was to move your "else" statement one level deeper, and that fixed the problem. Your check here will run the insert if there's no PK - which I also added :)

    Find a bug? Create a Work Item for a fast response.. Want to help? Create a patch for us!

Page 1 of 1 (6 items) | RSS