// // Summary: // Executes a SQL statement against a connection object. // // Returns: // The number of rows affected. public override int ExecuteNonQuery() { PqsqlDataReader r = ExecuteReader(CommandBehavior.Default); // fill OUT and INOUT parameters with result tuple from the first row if (CommandType == CommandType.StoredProcedure) { r.Read(); // reading the first row will fill output parameters } int ra = Math.Max(-1, r.RecordsAffected); r.Consume(); // sync protocol: consume remaining rows if ((mCmdBehavior & CommandBehavior.SingleResult) == CommandBehavior.SingleResult) // only one statement available { return(ra); } // we have more than one statement while (r.NextResult()) { int n = r.RecordsAffected; // accumulate positive RecordsAffected for each UPDATE / DELETE / INSERT / CREATE * / ... statement if (n >= 0) { if (ra < 0) { ra = n; } else // ra >= 0 { ra += n; } } r.Consume(); // sync protocol: consume remaining rows } int last = r.RecordsAffected; // accumulate positive RecordsAffected for each UPDATE / DELETE / INSERT / CREATE * / ... statement if (last >= 0) { if (ra < 0) { ra = last; } else // ra >= 0 { ra += last; } } r.Consume(); // sync protocol: consume remaining rows return(ra); }
// // Summary: // Executes the query and returns the first column of the first row in the result // set returned by the query. All other columns and rows are ignored. // // Returns: // The first column of the first row in the result set. public override object ExecuteScalar() { PqsqlDataReader r = ExecuteReader(CommandBehavior.Default); object o; if (r.Read()) { o = r.GetValue(0); } else { o = null; } r.Consume(); // sync protocol: consume remaining rows return(o); }