Example #1
0
        /// <summary>
        /// Binds a PHP variable to an SQL parameter of a statement.
        /// </summary>
        /// <param name="statement">Statement resource.</param>
        /// <param name="parameterName">Parameter name starting with '@' character.</param>
        /// <param name="variable">PHP variable to bind to the parameter.</param>
        /// <param name="type">SQL type of the parameter.</param>
        /// <param name="isOutput">Whether the parameter is an output parameter.</param>
        /// <param name="isNullable">Whether the parameter accepts <B>null</B> values.</param>
        /// <param name="maxLength">Maximum size of input data.</param>
        /// <returns>Whether binding succeeded.</returns>
        public static bool mssql_bind(PhpResource statement, string parameterName, PhpAlias variable, VariableType type,
                                      bool isOutput = false, bool isNullable = false, int maxLength = -1)
        {
            PhpSqlDbProcedure procedure = PhpSqlDbProcedure.ValidProcedure(statement);

            if (procedure == null)
            {
                return(false);
            }

            if (parameterName == null)
            {
                PhpException.ArgumentNull(nameof(parameterName));
                return(false);
            }

            var param_type = PhpSqlDbProcedure.VariableTypeToParamType(type);

            if (param_type == PhpSqlDbProcedure.ParameterType.Invalid)
            {
                PhpException.ArgumentValueNotSupported("type", (int)type);
                return(false);
            }

            SqlParameter parameter = new SqlParameter();

            parameter.ParameterName = parameterName;

            // it is necessary to set size for in-out params as the results are truncated to this size;
            // 8000 is maximal size of the data according to the doc:
            if (maxLength >= 0)
            {
                parameter.Size = maxLength;
            }
            else
            {
                parameter.Size = 8000;
            }

            if (string.Equals(parameterName, "RETVAL", StringComparison.OrdinalIgnoreCase))
            {
                parameter.Direction = ParameterDirection.ReturnValue;
            }
            else if (isOutput)
            {
                parameter.Direction = ParameterDirection.InputOutput;
            }
            else
            {
                parameter.Direction = ParameterDirection.Input;
            }

            if (!procedure.AddBinding(parameter, variable, param_type))
            {
                PhpException.Throw(PhpError.Notice, Resources.parameter_already_bound, parameterName);
                return(false);
            }

            return(true);
        }
Example #2
0
        /// <summary>
        /// Releases a resource represening a statement.
        /// </summary>
        /// <param name="statement">Statement resource.</param>
        /// <returns><B>true</B> on success, <B>false</B> on failure (invalid resource).</returns>
        public static bool mssql_free_statement(PhpResource statement)
        {
            PhpSqlDbProcedure procedure = PhpSqlDbProcedure.ValidProcedure(statement);

            if (procedure == null)
            {
                return(false);
            }

            procedure.Dispose();
            return(true);
        }
Example #3
0
        internal static PhpSqlDbProcedure ValidProcedure(PhpResource handle)
        {
            PhpSqlDbProcedure result = handle as PhpSqlDbProcedure;

            if (result != null && result.IsValid)
            {
                return(result);
            }

            PhpException.Throw(PhpError.Warning, Resources.invalid_stored_procedure_resource);
            return(null);
        }
Example #4
0
        /// <summary>
        /// Executes a specified stored procedure statement.
        /// </summary>
        /// <param name="statement">Statement resource (stored procedure).</param>
        /// <param name="skipResults">Whether to retrieve and return procedure output.</param>
        /// <returns>
        /// Result resource containing procedure output,
        /// <B>true</B> if the procedure succeeded yet doesn't return any value, or
        /// <B>false</B> on failure.
        /// </returns>
        public static object mssql_execute(PhpResource statement, bool skipResults = false)
        {
            PhpSqlDbProcedure procedure = PhpSqlDbProcedure.ValidProcedure(statement);

            if (procedure == null)
            {
                return(false);
            }

            bool           success;
            PhpSqlDbResult result = procedure.Execute(skipResults, out success);

            if (!success)
            {
                return(false);
            }
            if (skipResults)
            {
                return(true);
            }
            return(result);
        }