public override int ExecuteNonQuery(DbInsertStatement clause) { OracleDbInsertStatement _clause = (OracleDbInsertStatement)clause; string sequence_name = string.Format("{0}Seq", _clause.Tablename); sequence_name = FieldAlias(sequence_name); _clause.SequenceNumber = string.Format("{0}.nextval", sequence_name); //in case the record is imported from another database which comes //with its autoincrement value already attached, forced the //Oracle sequence follows sync with the imported data DbAutoIntFieldEntry autoinc_field = _clause.AutoIncrementField; if (autoinc_field != null) { if (autoinc_field.IsValidValue) { string query = string.Format("select {0}.nextval from dual", sequence_name); OracleCommand _cmd2 = ((OracleConnection)DbConnection).CreateCommand(); _cmd2.CommandText = query; int autoinc_val = Convert.ToInt32(_cmd2.ExecuteScalar()); _cmd2.Dispose(); int current_autoinc_val = Int32.Parse(autoinc_field.Value); while (autoinc_val < current_autoinc_val) { query = string.Format("select {0}.nextval from dual", sequence_name); _cmd2 = ((OracleConnection)DbConnection).CreateCommand(); _cmd2.CommandText = query; autoinc_val = Convert.ToInt32(_cmd2.ExecuteScalar()); _cmd2.Dispose(); } } } if (_clause.Tablename.Equals("Sales")) { Log(_clause.ToString()); } int result = 0; DbCommand _cmd = CreateDbCommand(_clause); result = _cmd.ExecuteNonQuery(); _cmd.Dispose(); //this is the last inserted ID if (autoinc_field != null && (!autoinc_field.IsValidValue)) { string query = string.Format("select {0}.currval from dual", sequence_name); OracleCommand _cmd2 = ((OracleConnection)DbConnection).CreateCommand(); _cmd2.CommandText = query; mLastInsertID = Convert.ToInt32(_cmd2.ExecuteScalar()); _cmd2.Dispose(); } return(result); }
public override DbInsertStatement CreateInsertClause() { OracleDbInsertStatement clause = new OracleDbInsertStatement(this); return(clause); }