ServiceStack/ServiceStack.OrmLite — pull request #353 by Aaronaught (2014-01-30 20:00:47+00:00)
Title: Fixing insert no-op bug with Oracle dialect

The first time you try to perform an insert when using the Oracle dialect with a sequence... nothing happens.

Note that I use ODP.NET - not sure if the same behaviour happens with the Microsoft provider but I suspect that it does.

Simple repro:

POCO:

```c#
public class Foo
{
[Sequence("FOO_SEQ")]
public int Id { get; set; }
public string Name { get; set; }
}
```

Steps to repro:

```c#
OrmLiteConfig.DialectProvider = OracleDialect.Provider;
var connectionString = "";
var db = new OracleConnection(connectionString);
db.Open();
db.Insert(new Foo { Name = "Test" });
```

After executing this code and inspecting the database, the record is not present. A second call to `db.Insert` with the same object will create the record.

The cause appears to be the `GetNextValue` method in the `OracleOrmLiteDialectProvider` accepting an `IDbCommand` and overwriting its `CommandText`. It does not restore the command text afterward, so the insert never happens; when the dialect tries to execute the "real" command, it just does another select on the sequence itself. On the second attempt, the sequence value is cached (so to speak) so the insert proceeds normally.

I changed that method to accept an `IDbConnection` instead of an `IDbCommand`, and to just create a new command to select the sequence value instead of tampering with the original command. It's working for me, and I can't see any reason why it would cause problems anywhere else, but I can't be 100% certain without more comprehensive regression tests...

P.S. During my search, I noticed a very similar pattern being used in the Firebird dialect. I don't really know much about Firebird, so I didn't touch that code, but I suspect it may have the same/similar issue.