protected static void DeriveParameters(AbstractDbCommand command) { if (command.Connection.State != ConnectionState.Open) { throw new InvalidOperationException("DeriveParameters requires an open and available Connection. The connection's current state is Closed."); } if (command.CommandType != CommandType.StoredProcedure) { throw ExceptionHelper.DeriveParametersNotSupported(command.GetType(), command.CommandType); } ArrayList parameters = command.DeriveParameters(command.CommandText, true); command.Parameters.Clear(); foreach (AbstractDbParameter param in parameters) { command.Parameters.Add(param.Clone()); } }
public virtual object Clone() { AbstractDbCommand target = (AbstractDbCommand)MemberwiseClone(); target._statement = null; target._isCommandPrepared = false; target._internalParameters = null; target._javaCommandText = null; target._recordsAffected = -1; target._currentResultSet = null; target._currentReader = null; target._nullParametersInPrepare = false; target._hasResultSet = false; target._explicitPrepare = false; if (Parameters != null && Parameters.Count > 0) { target._parameters = CreateParameterCollection(target); for(int i=0 ; i < Parameters.Count; i++) { target.Parameters.Add(((AbstractDbParameter)Parameters[i]).Clone()); } } return target; }
public AbstractDbParameterCollection(DbCommand parent) { _parent = (AbstractDbCommand)parent; }
internal ArrayList GetProcedureColumns(AbstractDBConnection connection, String commandText,AbstractDbCommand command) { string connectionCatalog = connection.JdbcConnection.getCatalog(); string key = String.Concat(connection.ConnectionString, connectionCatalog, commandText); System.Collections.Hashtable cache = Cache; ArrayList col = cache[key] as ArrayList; if (null != col) { return col; } col = connection.GetProcedureColumns(commandText,command); if (col != null) cache[key] = col; return col; }
protected abstract DbParameterCollection CreateParameterCollection(AbstractDbCommand parent);
internal ArrayList GetProcedureColumns(String procedureString, AbstractDbCommand command) { ArrayList col = new ArrayList(); try { ObjectNameResolver[] nameResolvers = SyntaxPatterns; java.sql.ResultSet res = null; string catalog = null; string schema = null; string spname = null; java.sql.DatabaseMetaData metadata = JdbcConnection.getMetaData(); bool storesUpperCaseIdentifiers = false; bool storesLowerCaseIdentifiers = false; try { storesUpperCaseIdentifiers = metadata.storesUpperCaseIdentifiers(); storesLowerCaseIdentifiers = metadata.storesLowerCaseIdentifiers(); } catch (SQLException e) { // suppress } for (int i = 0; i < nameResolvers.Length; i++) { ObjectNameResolver nameResolver = nameResolvers[i]; Match match = nameResolver.Match(procedureString); if (match.Success) { spname = ObjectNameResolver.GetName(match); schema = ObjectNameResolver.GetSchema(match); catalog = ObjectNameResolver.GetCatalog(match); // make all identifiers uppercase or lowercase according to database metadata if (storesUpperCaseIdentifiers) { spname = (spname.Length > 0) ? spname.ToUpper() : null; schema = (schema.Length > 0) ? schema.ToUpper() : null; catalog = (catalog.Length > 0) ? catalog.ToUpper() : null; } else if (storesLowerCaseIdentifiers) { spname = (spname.Length > 0) ? spname.ToLower() : null; schema = (schema.Length > 0) ? schema.ToLower() : null; catalog = (catalog.Length > 0) ? catalog.ToLower() : null; } else { spname = (spname.Length > 0) ? spname : null; schema = (schema.Length > 0) ? schema : null; catalog = (catalog.Length > 0) ? catalog : null; } // catalog from db is always in correct caps if (catalog == null) { catalog = JdbcConnection.getCatalog(); } try { // always get the first procedure that db returns res = metadata.getProcedures(catalog, schema, spname); if (res.next()) { catalog = res.getString(1); schema = res.getString(2); spname = res.getString(3); break; } spname = null; } catch // suppress exception { return(null); } finally { if (res != null) { res.close(); } } } } if (spname == null || spname.Length == 0) { return(null); } try { // get procedure columns based o procedure metadata res = metadata.getProcedureColumns(catalog, schema, spname, null); while (res.next()) { // since there is still a possibility that some of the parameters to getProcedureColumn were nulls, // we need to filter the results with strict matching if ((res.getString(1) != catalog) || (res.getString(2) != schema) || (res.getString(3) != spname)) { continue; } AbstractDbParameter parameter = (AbstractDbParameter)command.CreateParameter(); parameter.SetParameterName(res); parameter.SetParameterDbType(res); parameter.SetSpecialFeatures(res); //get parameter direction short direction = res.getShort("COLUMN_TYPE"); if (direction == 1) //DatabaseMetaData.procedureColumnIn { parameter.Direction = ParameterDirection.Input; } else if (direction == 2) //DatabaseMetaData.procedureColumnInOut { parameter.Direction = ParameterDirection.InputOutput; } else if (direction == 4) //DatabaseMetaData.procedureColumnOut { parameter.Direction = ParameterDirection.Output; } else if (direction == 5) //DatabaseMetaData.procedureColumnReturn { parameter.Direction = ParameterDirection.ReturnValue; } //get parameter precision and scale parameter.SetParameterPrecisionAndScale(res); parameter.SetParameterSize(res); parameter.SetParameterIsNullable(res); col.Add(parameter); } } finally { if (res != null) { res.close(); } } } catch (Exception e) { //supress #if DEBUG Console.WriteLine("Exception catched at AbstractDBConnection.GetProcedureColumns() : {0}\n{1}\n{2}", e.GetType().FullName, e.Message, e.StackTrace); #endif } return(col); }