示例#1
0
 public PreparedCommandSqlParser(StatementPreparer preparer, List <ParsedStatement> statements, List <int> statementStartEndIndexes, ByteBufferWriter writer)
 {
     m_preparer   = preparer;
     m_statements = statements;
     m_statementStartEndIndexes = statementStartEndIndexes;
     m_writer = writer;
 }
        private PayloadData CreateQueryPayload(string commandText, MySqlParameterCollection parameterCollection)
        {
            var statementPreparerOptions = StatementPreparerOptions.None;

            if (m_command.Connection.AllowUserVariables || m_command.CommandType == CommandType.StoredProcedure)
            {
                statementPreparerOptions |= StatementPreparerOptions.AllowUserVariables;
            }
            if (m_command.Connection.OldGuids)
            {
                statementPreparerOptions |= StatementPreparerOptions.OldGuids;
            }
            if (m_command.Connection.DateTimeKind == DateTimeKind.Utc)
            {
                statementPreparerOptions |= StatementPreparerOptions.DateTimeUtc;
            }
            else if (m_command.Connection.DateTimeKind == DateTimeKind.Local)
            {
                statementPreparerOptions |= StatementPreparerOptions.DateTimeLocal;
            }
            if (m_command.CommandType == CommandType.StoredProcedure)
            {
                statementPreparerOptions |= StatementPreparerOptions.AllowOutputParameters;
            }
            var preparer = new StatementPreparer(commandText, parameterCollection, statementPreparerOptions);

            return(new PayloadData(preparer.ParseAndBindParameters()));
        }
示例#3
0
        private PayloadData CreateQueryPayload(string commandText, MySqlParameterCollection parameterCollection)
        {
            var statementPreparerOptions = StatementPreparerOptions.None;

            if (m_command.Connection.AllowUserVariables || m_command.CommandType == CommandType.StoredProcedure)
            {
                statementPreparerOptions |= StatementPreparerOptions.AllowUserVariables;
            }
            if (m_command.Connection.DateTimeKind == DateTimeKind.Utc)
            {
                statementPreparerOptions |= StatementPreparerOptions.DateTimeUtc;
            }
            else if (m_command.Connection.DateTimeKind == DateTimeKind.Local)
            {
                statementPreparerOptions |= StatementPreparerOptions.DateTimeLocal;
            }
            if (m_command.CommandType == CommandType.StoredProcedure)
            {
                statementPreparerOptions |= StatementPreparerOptions.AllowOutputParameters;
            }

            switch (m_command.Connection.GuidFormat)
            {
            case MySqlGuidFormat.Char36:
                statementPreparerOptions |= StatementPreparerOptions.GuidFormatChar36;
                break;

            case MySqlGuidFormat.Char32:
                statementPreparerOptions |= StatementPreparerOptions.GuidFormatChar32;
                break;

            case MySqlGuidFormat.Binary16:
                statementPreparerOptions |= StatementPreparerOptions.GuidFormatBinary16;
                break;

            case MySqlGuidFormat.TimeSwapBinary16:
                statementPreparerOptions |= StatementPreparerOptions.GuidFormatTimeSwapBinary16;
                break;

            case MySqlGuidFormat.LittleEndianBinary16:
                statementPreparerOptions |= StatementPreparerOptions.GuidFormatLittleEndianBinary16;
                break;
            }

            var preparer = new StatementPreparer(commandText, parameterCollection, statementPreparerOptions);

            return(new PayloadData(preparer.ParseAndBindParameters(), isPooled: true));
        }
示例#4
0
 public ParameterSqlParser(StatementPreparer preparer, BinaryWriter writer)
 {
     m_preparer = preparer;
     m_writer   = writer;
 }
 protected SqlParser(StatementPreparer preparer) => Preparer = preparer;
示例#6
0
 public ParameterSqlParser(StatementPreparer preparer, ByteBufferWriter writer)
 {
     m_preparer = preparer;
     m_writer   = writer;
 }
示例#7
0
        private void WriteCommand(IMySqlCommand command, ByteBufferWriter writer)
        {
            var preparer = new StatementPreparer(command.CommandText, command.Parameters, command.CreateStatementPreparerOptions());

            preparer.ParseAndBindParameters(writer);
        }
示例#8
0
        private void WriteStoredProcedure(IMySqlCommand command, IDictionary <string, CachedProcedure> cachedProcedures, ByteBufferWriter writer)
        {
            var parameterCollection = command.Parameters;
            var cachedProcedure     = cachedProcedures[command.CommandText];

            if (cachedProcedure is object)
            {
                parameterCollection = cachedProcedure.AlignParamsWithDb(parameterCollection);
            }

            MySqlParameter returnParameter    = null;
            var            outParameters      = new MySqlParameterCollection();
            var            outParameterNames  = new List <string>();
            var            inParameters       = new MySqlParameterCollection();
            var            argParameterNames  = new List <string>();
            var            inOutSetParameters = "";

            for (var i = 0; i < (parameterCollection?.Count ?? 0); i++)
            {
                var param   = parameterCollection[i];
                var inName  = "@inParam" + i;
                var outName = "@outParam" + i;
                switch (param.Direction)
                {
                case ParameterDirection.Input:
                case ParameterDirection.InputOutput:
                    var inParam = param.WithParameterName(inName);
                    inParameters.Add(inParam);
                    if (param.Direction == ParameterDirection.InputOutput)
                    {
                        inOutSetParameters += $"SET {outName}={inName}; ";
                        goto case ParameterDirection.Output;
                    }
                    argParameterNames.Add(inName);
                    break;

                case ParameterDirection.Output:
                    outParameters.Add(param);
                    outParameterNames.Add(outName);
                    argParameterNames.Add(outName);
                    break;

                case ParameterDirection.ReturnValue:
                    returnParameter = param;
                    break;
                }
            }

            // if a return param is set, assume it is a function; otherwise, assume stored procedure
            var commandText = command.CommandText + "(" + string.Join(", ", argParameterNames) + ");";

            if (returnParameter is null)
            {
                commandText = inOutSetParameters + "CALL " + commandText;
                if (outParameters.Count > 0)
                {
                    commandText += "SELECT '" + OutParameterSentinelColumnName + "' AS '" + OutParameterSentinelColumnName + "', " + string.Join(", ", outParameterNames);
                }
            }
            else
            {
                commandText = "SELECT " + commandText;
            }
            command.OutParameters   = outParameters;
            command.ReturnParameter = returnParameter;

            var preparer = new StatementPreparer(commandText, inParameters, command.CreateStatementPreparerOptions());

            preparer.ParseAndBindParameters(writer);
        }
        private PayloadData CreateQueryPayload(string commandText, MySqlParameterCollection parameterCollection)
        {
            var preparer = new StatementPreparer(commandText, parameterCollection, m_command.CreateStatementPreparerOptions());

            return(new PayloadData(preparer.ParseAndBindParameters(), isPooled: true));
        }