private static OdbcParameter[] DeriveParametersFromStoredProcedure(OdbcConnection connection, OdbcCommand command)
        {
            List <OdbcParameter> list            = new List <OdbcParameter>();
            CMDWrapper           statementHandle = command.GetStatementHandle();
            OdbcStatementHandle  hrHandle        = statementHandle.StatementHandle;
            string leftQuote = connection.QuoteChar("DeriveParameters");

            string[] strArray = MultipartIdentifier.ParseMultipartIdentifier(command.CommandText, leftQuote, leftQuote, '.', 4, true, "ODBC_ODBCCommandText", false);
            if (strArray[3] == null)
            {
                strArray[3] = command.CommandText;
            }
            ODBC32.RetCode retcode = hrHandle.ProcedureColumns(strArray[1], strArray[2], strArray[3], null);
            if (retcode != ODBC32.RetCode.SUCCESS)
            {
                connection.HandleError(hrHandle, retcode);
            }
            using (OdbcDataReader reader = new OdbcDataReader(command, statementHandle, CommandBehavior.Default))
            {
                reader.FirstResult();
                int fieldCount = reader.FieldCount;
                while (reader.Read())
                {
                    OdbcParameter item = new OdbcParameter {
                        ParameterName = reader.GetString(3)
                    };
                    switch (reader.GetInt16(4))
                    {
                    case 1:
                        item.Direction = ParameterDirection.Input;
                        break;

                    case 2:
                        item.Direction = ParameterDirection.InputOutput;
                        break;

                    case 4:
                        item.Direction = ParameterDirection.Output;
                        break;

                    case 5:
                        item.Direction = ParameterDirection.ReturnValue;
                        break;
                    }
                    item.OdbcType = TypeMap.FromSqlType((ODBC32.SQL_TYPE)reader.GetInt16(5))._odbcType;
                    item.Size     = reader.GetInt32(7);
                    switch (item.OdbcType)
                    {
                    case OdbcType.Decimal:
                    case OdbcType.Numeric:
                        item.ScaleInternal     = (byte)reader.GetInt16(9);
                        item.PrecisionInternal = (byte)reader.GetInt16(10);
                        break;
                    }
                    list.Add(item);
                }
            }
            retcode = hrHandle.CloseCursor();
            return(list.ToArray());
        }
        private static void ThrowParse(string name, int expectedLength, bool removeQuotes = true, string leftQuotes = "[\"", string rightQuotes = "]\"", char separator = '.')
        {
            Exception originalException = Assert.Throws <ArgumentException>(
                () =>
            {
                MultipartIdentifier.ParseMultipartIdentifier(name, leftQuotes, rightQuotes, separator, expectedLength, removeQuotes, "test", true);
            }
                );

            Assert.NotNull(originalException);
        }
 private void ParseMultipartName()
 {
     if (null != _multipartName)
     {
         string[] parts = MultipartIdentifier.ParseMultipartIdentifier(_multipartName, "[\"", "]\"", SR.SQL_TDSParserTableName, false);
         _serverName    = parts[0];
         _catalogName   = parts[1];
         _schemaName    = parts[2];
         _tableName     = parts[3];
         _multipartName = null;
     }
 }
 private void ParseMultipartName()
 {
     if (this._multipartName != null)
     {
         string[] strArray = MultipartIdentifier.ParseMultipartIdentifier(this._multipartName, "[\"", "]\"", "SQL_TDSParserTableName", false);
         this._serverName    = strArray[0];
         this._catalogName   = strArray[1];
         this._schemaName    = strArray[2];
         this._tableName     = strArray[3];
         this._multipartName = null;
     }
 }
Ejemplo n.º 5
0
        private static List <string> ParsePath(string path)
        {
            List <string> multipartIdentifier = MultipartIdentifier.ParseMultipartIdentifier(path, "[", "]", '.');

            for (int index = multipartIdentifier.Count - 1; index >= 0; --index)
            {
                if (multipartIdentifier[index] == null)
                {
                    multipartIdentifier.RemoveAt(index);
                }
                else if (multipartIdentifier[index].Length == 0)
                {
                    throw new ArgumentException(Strings.ObjectQuery_Span_SpanPathSyntaxError);
                }
            }
            return(multipartIdentifier);
        }
Ejemplo n.º 6
0
        private static List <string> ParsePath(string path)
        {
            var navigations = MultipartIdentifier.ParseMultipartIdentifier(path, "[", "]", '.');

            for (var i = navigations.Count - 1; i >= 0; i--)
            {
                if (navigations[i] == null)
                {
                    navigations.RemoveAt(i);
                }
                else if (navigations[i].Length == 0)
                {
                    throw new ArgumentException(Strings.ObjectQuery_Span_SpanPathSyntaxError);
                }
            }

            Debug.Assert(navigations.Count > 0, "Empty path found");
            return(navigations);
        }
        private static void ThrowParse <TException>(string name, string[] expected, bool removeQuotes = true, string leftQuotes = "[\"", string rightQuotes = "]\"", char separator = '.')
            where TException : Exception
        {
            int maxCount = 0;

            for (int index = 0; index < expected.Length; index++)
            {
                if (expected[index] != null)
                {
                    maxCount += 1;
                }
            }

            Exception originalException = Assert.Throws <TException>(() =>
                                                                     MultipartIdentifier.ParseMultipartIdentifier(name, leftQuotes, rightQuotes, separator, maxCount, removeQuotes, "", true)
                                                                     );

            Assert.NotNull(originalException);
        }
Ejemplo n.º 8
0
        private static List <string> ParsePath(string path)
        {
            List <string> navigations = MultipartIdentifier.ParseMultipartIdentifier(path, "[", "]", '.');

            for (int i = navigations.Count - 1; i >= 0; i--)
            {
                if (navigations[i] == null)
                {
                    navigations.RemoveAt(i);
                }
                else if (navigations[i].Length == 0)
                {
                    throw EntityUtil.SpanPathSyntaxError();
                }
            }

            Debug.Assert(navigations.Count > 0, "Empty path found");
            return(navigations);
        }
        private static void RunParse(string name, string[] expected, bool removeQuotes = true, int maxCount = 0)
        {
            if (maxCount == 0)
            {
                for (int index = 0; index < expected.Length; index++)
                {
                    if (expected[index] != null)
                    {
                        maxCount += 1;
                    }
                }
            }

            string[] originalParts = MultipartIdentifier.ParseMultipartIdentifier(name, "[\"", "]\"", '.', maxCount, removeQuotes, "", true);

            for (int index = 0; index < expected.Length; index++)
            {
                string expectedPart = expected[index];
                string originalPart = originalParts[index];

                Assert.Equal(expectedPart, originalPart);
            }
        }
Ejemplo n.º 10
0
        // known difference: when getting the parameters for a sproc, the
        //   return value gets marked as a return value but for a sql stmt
        //   the return value gets marked as an output parameter.
        private static OleDbParameter[] DeriveParametersFromStoredProcedure(OleDbConnection connection, OleDbCommand command)
        {
            OleDbParameter[] plist = Array.Empty <OleDbParameter>();

            if (connection.SupportSchemaRowset(OleDbSchemaGuid.Procedure_Parameters))
            {
                string quotePrefix, quoteSuffix;
                connection.GetLiteralQuotes(ADP.DeriveParameters, out quotePrefix, out quoteSuffix);

                object?[] parsed = MultipartIdentifier.ParseMultipartIdentifier(command.CommandText, quotePrefix, quoteSuffix, '.', 4, true, SR.OLEDB_OLEDBCommandText, false);
                if (null == parsed[3])
                {
                    throw ADP.NoStoredProcedureExists(command.CommandText);
                }

                object?[] restrictions = new object[4];
                object    value;

                // Parse returns an enforced 4 part array
                // 0) Server - ignored but removal would be a run-time breaking change from V1.0
                // 1) Catalog
                // 2) Schema
                // 3) ProcedureName

                // Restrictions array which is passed to OleDb API expects:
                // 0) Catalog
                // 1) Schema
                // 2) ProcedureName
                // 3) ParameterName (leave null)

                // Copy from Parse format to OleDb API format
                Array.Copy(parsed, 1, restrictions, 0, 3);

                //if (cmdConnection.IsServer_msdaora) {
                //    restrictions[1] = Convert.ToString(cmdConnection.UserId).ToUpper();
                //}
                DataTable?table = connection.GetSchemaRowset(OleDbSchemaGuid.Procedure_Parameters, restrictions);

                if (null != table)
                {
                    DataColumnCollection columns = table.Columns;

                    DataColumn?parameterName      = null;
                    DataColumn?parameterDirection = null;
                    DataColumn?dataType           = null;
                    DataColumn?maxLen             = null;
                    DataColumn?numericPrecision   = null;
                    DataColumn?numericScale       = null;
                    DataColumn?backendtype        = null;

                    int index = columns.IndexOf(ODB.PARAMETER_NAME);
                    if (-1 != index)
                    {
                        parameterName = columns[index];
                    }

                    index = columns.IndexOf(ODB.PARAMETER_TYPE);
                    if (-1 != index)
                    {
                        parameterDirection = columns[index];
                    }

                    index = columns.IndexOf(ODB.DATA_TYPE);
                    if (-1 != index)
                    {
                        dataType = columns[index];
                    }

                    index = columns.IndexOf(ODB.CHARACTER_MAXIMUM_LENGTH);
                    if (-1 != index)
                    {
                        maxLen = columns[index];
                    }

                    index = columns.IndexOf(ODB.NUMERIC_PRECISION);
                    if (-1 != index)
                    {
                        numericPrecision = columns[index];
                    }

                    index = columns.IndexOf(ODB.NUMERIC_SCALE);
                    if (-1 != index)
                    {
                        numericScale = columns[index];
                    }

                    index = columns.IndexOf(ODB.TYPE_NAME);
                    if (-1 != index)
                    {
                        backendtype = columns[index];
                    }

                    DataRow[] dataRows = table.Select(null, ODB.ORDINAL_POSITION_ASC, DataViewRowState.CurrentRows);
                    plist = new OleDbParameter[dataRows.Length];
                    for (index = 0; index < dataRows.Length; ++index)
                    {
                        DataRow dataRow = dataRows[index];

                        OleDbParameter parameter = new OleDbParameter();

                        if ((null != parameterName) && !dataRow.IsNull(parameterName, DataRowVersion.Default))
                        {
                            // $CONSIDER - not trimming the @ from the beginning but to left the designer do that
                            parameter.ParameterName = Convert.ToString(dataRow[parameterName, DataRowVersion.Default], CultureInfo.InvariantCulture) !.TrimStart(new char[] { '@', ' ', ':' });
                        }
                        if ((null != parameterDirection) && !dataRow.IsNull(parameterDirection, DataRowVersion.Default))
                        {
                            short direction = Convert.ToInt16(dataRow[parameterDirection, DataRowVersion.Default], CultureInfo.InvariantCulture);
                            parameter.Direction = ConvertToParameterDirection(direction);
                        }
                        if ((null != dataType) && !dataRow.IsNull(dataType, DataRowVersion.Default))
                        {
                            // need to ping FromDBType, otherwise WChar->WChar when the user really wants VarWChar
                            short wType = Convert.ToInt16(dataRow[dataType, DataRowVersion.Default], CultureInfo.InvariantCulture);
                            parameter.OleDbType = NativeDBType.FromDBType(wType, false, false).enumOleDbType;
                        }
                        if ((null != maxLen) && !dataRow.IsNull(maxLen, DataRowVersion.Default))
                        {
                            parameter.Size = Convert.ToInt32(dataRow[maxLen, DataRowVersion.Default], CultureInfo.InvariantCulture);
                        }
                        switch (parameter.OleDbType)
                        {
                        case OleDbType.Decimal:
                        case OleDbType.Numeric:
                        case OleDbType.VarNumeric:
                            if ((null != numericPrecision) && !dataRow.IsNull(numericPrecision, DataRowVersion.Default))
                            {
                                // @devnote: unguarded cast from Int16 to Byte
                                parameter.PrecisionInternal = (byte)Convert.ToInt16(dataRow[numericPrecision], CultureInfo.InvariantCulture);
                            }
                            if ((null != numericScale) && !dataRow.IsNull(numericScale, DataRowVersion.Default))
                            {
                                // @devnote: unguarded cast from Int16 to Byte
                                parameter.ScaleInternal = (byte)Convert.ToInt16(dataRow[numericScale], CultureInfo.InvariantCulture);
                            }
                            break;

                        case OleDbType.VarBinary:
                        case OleDbType.VarChar:
                        case OleDbType.VarWChar:
                            value = dataRow[backendtype !, DataRowVersion.Default];
Ejemplo n.º 11
0
        // DeriveParametersFromStoredProcedure (
        //  OdbcConnection connection,
        //  OdbcCommand command);
        //
        // Uses SQLProcedureColumns to create an array of OdbcParameters
        //

        static private OdbcParameter[] DeriveParametersFromStoredProcedure(OdbcConnection connection, OdbcCommand command)
        {
            List <OdbcParameter> rParams = new List <OdbcParameter>();

            // following call ensures that the command has a statement handle allocated
            CMDWrapper          cmdWrapper = command.GetStatementHandle();
            OdbcStatementHandle hstmt      = cmdWrapper.StatementHandle;
            int cColsAffected;

            // maps an enforced 4-part qualified string as follows
            // parts[0] = null  - ignored but removal would be a run-time breaking change from V1.0
            // parts[1] = CatalogName (optional, may be null)
            // parts[2] = SchemaName (optional, may be null)
            // parts[3] = ProcedureName
            //
            string quote = connection.QuoteChar(ADP.DeriveParameters);

            string[] parts = MultipartIdentifier.ParseMultipartIdentifier(command.CommandText, quote, quote, '.', 4, true, Res.ODBC_ODBCCommandText, false);
            if (null == parts[3])
            { // match Everett behavior, if the commandtext is nothing but whitespace set the command text to the whitespace
                parts[3] = command.CommandText;
            }
            // note: native odbc appears to ignore all but the procedure name
            ODBC32.RetCode retcode = hstmt.ProcedureColumns(parts[1], parts[2], parts[3], null);

            // Note: the driver does not return an error if the given stored procedure does not exist
            // therefore we cannot handle that case and just return not parameters.

            if (ODBC32.RetCode.SUCCESS != retcode)
            {
                connection.HandleError(hstmt, retcode);
            }

            using (OdbcDataReader reader = new OdbcDataReader(command, cmdWrapper, CommandBehavior.Default))
            {
                reader.FirstResult();
                cColsAffected = reader.FieldCount;

                // go through the returned rows and filter out relevant parameter data
                //
                while (reader.Read())
                {
                    // devnote: column types are specified in the ODBC Programmer's Reference
                    // COLUMN_TYPE      Smallint    16bit
                    // COLUMN_SIZE      Integer     32bit
                    // DECIMAL_DIGITS   Smallint    16bit
                    // NUM_PREC_RADIX   Smallint    16bit

                    OdbcParameter parameter = new OdbcParameter();

                    parameter.ParameterName = reader.GetString(ODBC32.COLUMN_NAME - 1);
                    switch ((ODBC32.SQL_PARAM)reader.GetInt16(ODBC32.COLUMN_TYPE - 1))
                    {
                    case ODBC32.SQL_PARAM.INPUT:
                        parameter.Direction = ParameterDirection.Input;
                        break;

                    case ODBC32.SQL_PARAM.OUTPUT:
                        parameter.Direction = ParameterDirection.Output;
                        break;

                    case ODBC32.SQL_PARAM.INPUT_OUTPUT:
                        parameter.Direction = ParameterDirection.InputOutput;
                        break;

                    case ODBC32.SQL_PARAM.RETURN_VALUE:
                        parameter.Direction = ParameterDirection.ReturnValue;
                        break;

                    default:
                        Debug.Assert(false, "Unexpected Parametertype while DeriveParamters");
                        break;
                    }
                    parameter.OdbcType = TypeMap.FromSqlType((ODBC32.SQL_TYPE)reader.GetInt16(ODBC32.DATA_TYPE - 1))._odbcType;
                    parameter.Size     = (int)reader.GetInt32(ODBC32.COLUMN_SIZE - 1);
                    switch (parameter.OdbcType)
                    {
                    case OdbcType.Decimal:
                    case OdbcType.Numeric:
                        parameter.ScaleInternal     = (Byte)reader.GetInt16(ODBC32.DECIMAL_DIGITS - 1);
                        parameter.PrecisionInternal = (Byte)reader.GetInt16(ODBC32.NUM_PREC_RADIX - 1);
                        break;
                    }
                    rParams.Add(parameter);
                }
            }
            retcode = hstmt.CloseCursor();
            return(rParams.ToArray());;
        }
Ejemplo n.º 12
0
        // known difference: when getting the parameters for a sproc, the
        //   return value gets marked as a return value but for a sql stmt
        //   the return value gets marked as an output parameter.
        static private OleDbParameter[] DeriveParametersFromStoredProcedure(OleDbConnection connection, OleDbCommand command)
        {
            OleDbParameter[] plist = new OleDbParameter[0];

            if (connection.SupportSchemaRowset(OleDbSchemaGuid.Procedure_Parameters))
            {
                string quotePrefix, quoteSuffix;
                connection.GetLiteralQuotes(ADP.DeriveParameters, out quotePrefix, out quoteSuffix);

                Object[] parsed = MultipartIdentifier.ParseMultipartIdentifier(command.CommandText, quotePrefix, quoteSuffix, '.', 4, true, SR.OLEDB_OLEDBCommandText, false);
                if (null == parsed[3])
                {
                    throw ADP.NoStoredProcedureExists(command.CommandText);
                }

                Object[] restrictions = new object[4];
                object   value;

                // Parse returns an enforced 4 part array
                // 0) Server - ignored but removal would be a run-time breaking change from V1.0
                // 1) Catalog
                // 2) Schema
                // 3) ProcedureName

                // Restrictions array which is passed to OleDb API expects:
                // 0) Catalog
                // 1) Schema
                // 2) ProcedureName
                // 3) ParameterName (leave null)

                // Copy from Parse format to OleDb API format
                Array.Copy(parsed, 1, restrictions, 0, 3);

                //if (cmdConnection.IsServer_msdaora) {
                //    restrictions[1] = Convert.ToString(cmdConnection.UserId).ToUpper();
                //}
                DataTable table = connection.GetSchemaRowset(OleDbSchemaGuid.Procedure_Parameters, restrictions);

                if (null != table)
                {
                    DataColumnCollection columns = table.Columns;

                    DataColumn parameterName      = null;
                    DataColumn parameterDirection = null;
                    DataColumn dataType           = null;
                    DataColumn maxLen             = null;
                    DataColumn numericPrecision   = null;
                    DataColumn numericScale       = null;
                    DataColumn backendtype        = null;

                    int index = columns.IndexOf(ODB.PARAMETER_NAME);
                    if (-1 != index)
                    {
                        parameterName = columns[index];
                    }

                    index = columns.IndexOf(ODB.PARAMETER_TYPE);
                    if (-1 != index)
                    {
                        parameterDirection = columns[index];
                    }

                    index = columns.IndexOf(ODB.DATA_TYPE);
                    if (-1 != index)
                    {
                        dataType = columns[index];
                    }

                    index = columns.IndexOf(ODB.CHARACTER_MAXIMUM_LENGTH);
                    if (-1 != index)
                    {
                        maxLen = columns[index];
                    }

                    index = columns.IndexOf(ODB.NUMERIC_PRECISION);
                    if (-1 != index)
                    {
                        numericPrecision = columns[index];
                    }

                    index = columns.IndexOf(ODB.NUMERIC_SCALE);
                    if (-1 != index)
                    {
                        numericScale = columns[index];
                    }

                    index = columns.IndexOf(ODB.TYPE_NAME);
                    if (-1 != index)
                    {
                        backendtype = columns[index];
                    }

                    DataRow[] dataRows = table.Select(null, ODB.ORDINAL_POSITION_ASC, DataViewRowState.CurrentRows);
                    plist = new OleDbParameter[dataRows.Length];
                    for (index = 0; index < dataRows.Length; ++index)
                    {
                        DataRow dataRow = dataRows[index];

                        OleDbParameter parameter = new OleDbParameter();

                        if ((null != parameterName) && !dataRow.IsNull(parameterName, DataRowVersion.Default))
                        {
                            // $CONSIDER - not trimming the @ from the beginning but to left the designer do that
                            parameter.ParameterName = Convert.ToString(dataRow[parameterName, DataRowVersion.Default], CultureInfo.InvariantCulture).TrimStart(new char[] { '@', ' ', ':' });
                        }
                        if ((null != parameterDirection) && !dataRow.IsNull(parameterDirection, DataRowVersion.Default))
                        {
                            short direction = Convert.ToInt16(dataRow[parameterDirection, DataRowVersion.Default], CultureInfo.InvariantCulture);
                            parameter.Direction = ConvertToParameterDirection(direction);
                        }
                        if ((null != dataType) && !dataRow.IsNull(dataType, DataRowVersion.Default))
                        {
                            // need to ping FromDBType, otherwise WChar->WChar when the user really wants VarWChar
                            short wType = Convert.ToInt16(dataRow[dataType, DataRowVersion.Default], CultureInfo.InvariantCulture);
                            parameter.OleDbType = NativeDBType.FromDBType(wType, false, false).enumOleDbType;
                        }
                        if ((null != maxLen) && !dataRow.IsNull(maxLen, DataRowVersion.Default))
                        {
                            parameter.Size = Convert.ToInt32(dataRow[maxLen, DataRowVersion.Default], CultureInfo.InvariantCulture);
                        }
                        switch (parameter.OleDbType)
                        {
                        case OleDbType.Decimal:
                        case OleDbType.Numeric:
                        case OleDbType.VarNumeric:
                            if ((null != numericPrecision) && !dataRow.IsNull(numericPrecision, DataRowVersion.Default))
                            {
                                // @devnote: unguarded cast from Int16 to Byte
                                parameter.PrecisionInternal = (Byte)Convert.ToInt16(dataRow[numericPrecision], CultureInfo.InvariantCulture);
                            }
                            if ((null != numericScale) && !dataRow.IsNull(numericScale, DataRowVersion.Default))
                            {
                                // @devnote: unguarded cast from Int16 to Byte
                                parameter.ScaleInternal = (Byte)Convert.ToInt16(dataRow[numericScale], CultureInfo.InvariantCulture);
                            }
                            break;

                        case OleDbType.VarBinary:
                        case OleDbType.VarChar:
                        case OleDbType.VarWChar:
                            value = dataRow[backendtype, DataRowVersion.Default];
                            if (value is string)
                            {
                                string backendtypename = ((string)value).ToLower(CultureInfo.InvariantCulture);
                                switch (backendtypename)
                                {
                                case "binary":
                                    parameter.OleDbType = OleDbType.Binary;
                                    break;

                                //case "varbinary":
                                //    parameter.OleDbType = OleDbType.VarBinary;
                                //    break;
                                case "image":
                                    parameter.OleDbType = OleDbType.LongVarBinary;
                                    break;

                                case "char":
                                    parameter.OleDbType = OleDbType.Char;
                                    break;

                                //case "varchar":
                                //case "varchar2":
                                //    parameter.OleDbType = OleDbType.VarChar;
                                //    break;
                                case "text":
                                    parameter.OleDbType = OleDbType.LongVarChar;
                                    break;

                                case "nchar":
                                    parameter.OleDbType = OleDbType.WChar;
                                    break;

                                //case "nvarchar":
                                //    parameter.OleDbType = OleDbType.VarWChar;
                                case "ntext":
                                    parameter.OleDbType = OleDbType.LongVarWChar;
                                    break;
                                }
                            }
                            break;
                        }
                        //if (AdapterSwitches.OleDbSql.TraceVerbose) {
                        //    ADP.Trace_Parameter("StoredProcedure", parameter);
                        //}
                        plist[index] = parameter;
                    }
                }
                if ((0 == plist.Length) && connection.SupportSchemaRowset(OleDbSchemaGuid.Procedures))
                {
                    restrictions = new Object[4] {
                        null, null, command.CommandText, null
                    };
                    table = connection.GetSchemaRowset(OleDbSchemaGuid.Procedures, restrictions);
                    if (0 == table.Rows.Count)
                    {
                        throw ADP.NoStoredProcedureExists(command.CommandText);
                    }
                }
            }
            else if (connection.SupportSchemaRowset(OleDbSchemaGuid.Procedures))
            {
                Object[] restrictions = new Object[4] {
                    null, null, command.CommandText, null
                };
                DataTable table = connection.GetSchemaRowset(OleDbSchemaGuid.Procedures, restrictions);
                if (0 == table.Rows.Count)
                {
                    throw ADP.NoStoredProcedureExists(command.CommandText);
                }
                // we don't ever expect a procedure with 0 parameters, they should have at least a return value
                throw ODB.NoProviderSupportForSProcResetParameters(connection.Provider);
            }
            else
            {
                throw ODB.NoProviderSupportForSProcResetParameters(connection.Provider);
            }
            return(plist);
        }
Ejemplo n.º 13
0
        private static OleDbParameter[] DeriveParametersFromStoredProcedure(OleDbConnection connection, OleDbCommand command)
        {
            OleDbParameter[] parameterArray = new OleDbParameter[0];
            if (connection.SupportSchemaRowset(OleDbSchemaGuid.Procedure_Parameters))
            {
                string str3;
                string str4;
                connection.GetLiteralQuotes("DeriveParameters", out str4, out str3);
                object[] sourceArray = MultipartIdentifier.ParseMultipartIdentifier(command.CommandText, str4, str3, '.', 4, true, "OLEDB_OLEDBCommandText", false);
                if (sourceArray[3] == null)
                {
                    throw ADP.NoStoredProcedureExists(command.CommandText);
                }
                object[] destinationArray = new object[4];
                Array.Copy(sourceArray, 1, destinationArray, 0, 3);
                DataTable schemaRowset = connection.GetSchemaRowset(OleDbSchemaGuid.Procedure_Parameters, destinationArray);
                if (schemaRowset != null)
                {
                    DataColumnCollection columns = schemaRowset.Columns;
                    DataColumn           column6 = null;
                    DataColumn           column5 = null;
                    DataColumn           column4 = null;
                    DataColumn           column3 = null;
                    DataColumn           column2 = null;
                    DataColumn           column  = null;
                    DataColumn           column7 = null;
                    int index = columns.IndexOf("PARAMETER_NAME");
                    if (-1 != index)
                    {
                        column6 = columns[index];
                    }
                    index = columns.IndexOf("PARAMETER_TYPE");
                    if (-1 != index)
                    {
                        column5 = columns[index];
                    }
                    index = columns.IndexOf("DATA_TYPE");
                    if (-1 != index)
                    {
                        column4 = columns[index];
                    }
                    index = columns.IndexOf("CHARACTER_MAXIMUM_LENGTH");
                    if (-1 != index)
                    {
                        column3 = columns[index];
                    }
                    index = columns.IndexOf("NUMERIC_PRECISION");
                    if (-1 != index)
                    {
                        column2 = columns[index];
                    }
                    index = columns.IndexOf("NUMERIC_SCALE");
                    if (-1 != index)
                    {
                        column = columns[index];
                    }
                    index = columns.IndexOf("TYPE_NAME");
                    if (-1 != index)
                    {
                        column7 = columns[index];
                    }
                    DataRow[] rowArray = schemaRowset.Select(null, "ORDINAL_POSITION ASC", DataViewRowState.CurrentRows);
                    parameterArray = new OleDbParameter[rowArray.Length];
                    for (index = 0; index < rowArray.Length; index++)
                    {
                        DataRow        row       = rowArray[index];
                        OleDbParameter parameter = new OleDbParameter();
                        if ((column6 != null) && !row.IsNull(column6, DataRowVersion.Default))
                        {
                            parameter.ParameterName = Convert.ToString(row[column6, DataRowVersion.Default], CultureInfo.InvariantCulture).TrimStart(new char[] { '@', ' ', ':' });
                        }
                        if ((column5 != null) && !row.IsNull(column5, DataRowVersion.Default))
                        {
                            short num3 = Convert.ToInt16(row[column5, DataRowVersion.Default], CultureInfo.InvariantCulture);
                            parameter.Direction = ConvertToParameterDirection(num3);
                        }
                        if ((column4 != null) && !row.IsNull(column4, DataRowVersion.Default))
                        {
                            short dbType = Convert.ToInt16(row[column4, DataRowVersion.Default], CultureInfo.InvariantCulture);
                            parameter.OleDbType = NativeDBType.FromDBType(dbType, false, false).enumOleDbType;
                        }
                        if ((column3 != null) && !row.IsNull(column3, DataRowVersion.Default))
                        {
                            parameter.Size = Convert.ToInt32(row[column3, DataRowVersion.Default], CultureInfo.InvariantCulture);
                        }
                        switch (parameter.OleDbType)
                        {
                        case OleDbType.VarChar:
                        case OleDbType.VarWChar:
                        case OleDbType.VarBinary:
                        {
                            string str;
                            object obj2 = row[column7, DataRowVersion.Default];
                            if ((obj2 is string) && ((str = ((string)obj2).ToLower(CultureInfo.InvariantCulture)) != null))
                            {
                                if (str == "binary")
                                {
                                    break;
                                }
                                if (str == "image")
                                {
                                    goto Label_03B9;
                                }
                                if (str == "char")
                                {
                                    goto Label_03C6;
                                }
                                if (str == "text")
                                {
                                    goto Label_03D3;
                                }
                                if (str == "nchar")
                                {
                                    goto Label_03E0;
                                }
                                if (str == "ntext")
                                {
                                    goto Label_03ED;
                                }
                            }
                            goto Label_03F8;
                        }

                        case OleDbType.VarNumeric:
                        case OleDbType.Decimal:
                        case OleDbType.Numeric:
                            if ((column2 != null) && !row.IsNull(column2, DataRowVersion.Default))
                            {
                                parameter.PrecisionInternal = (byte)Convert.ToInt16(row[column2], CultureInfo.InvariantCulture);
                            }
                            if ((column != null) && !row.IsNull(column, DataRowVersion.Default))
                            {
                                parameter.ScaleInternal = (byte)Convert.ToInt16(row[column], CultureInfo.InvariantCulture);
                            }
                            goto Label_03F8;

                        default:
                            goto Label_03F8;
                        }
                        parameter.OleDbType = OleDbType.Binary;
                        goto Label_03F8;
Label_03B9:
                        parameter.OleDbType = OleDbType.LongVarBinary;
                        goto Label_03F8;
Label_03C6:
                        parameter.OleDbType = OleDbType.Char;
                        goto Label_03F8;
Label_03D3:
                        parameter.OleDbType = OleDbType.LongVarChar;
                        goto Label_03F8;
Label_03E0:
                        parameter.OleDbType = OleDbType.WChar;
                        goto Label_03F8;
Label_03ED:
                        parameter.OleDbType = OleDbType.LongVarWChar;
Label_03F8:
                        parameterArray[index] = parameter;
                    }
                }
                if ((parameterArray.Length == 0) && connection.SupportSchemaRowset(OleDbSchemaGuid.Procedures))
                {
                    object[] objArray3 = new object[4];
                    objArray3[2]     = command.CommandText;
                    destinationArray = objArray3;
                    if (connection.GetSchemaRowset(OleDbSchemaGuid.Procedures, destinationArray).Rows.Count == 0)
                    {
                        throw ADP.NoStoredProcedureExists(command.CommandText);
                    }
                }
                return(parameterArray);
            }
            if (!connection.SupportSchemaRowset(OleDbSchemaGuid.Procedures))
            {
                throw ODB.NoProviderSupportForSProcResetParameters(connection.Provider);
            }
            object[] objArray2 = new object[4];
            objArray2[2] = command.CommandText;
            object[] restrictions = objArray2;
            if (connection.GetSchemaRowset(OleDbSchemaGuid.Procedures, restrictions).Rows.Count == 0)
            {
                throw ADP.NoStoredProcedureExists(command.CommandText);
            }
            throw ODB.NoProviderSupportForSProcResetParameters(connection.Provider);
        }
        private BulkCopySimpleResultSet CreateAndExecuteInitialQuery()
        {
            string[] strArray;
            try
            {
                strArray = MultipartIdentifier.ParseMultipartIdentifier(this.DestinationTableName, "[\"", "]\"", "SQL_BulkCopyDestinationTableName", true);
            }
            catch (Exception exception)
            {
                throw SQL.BulkLoadInvalidDestinationTable(this.DestinationTableName, exception);
            }
            if (ADP.IsEmpty(strArray[3]))
            {
                throw SQL.BulkLoadInvalidDestinationTable(this.DestinationTableName, null);
            }
            BulkCopySimpleResultSet bulkCopyHandler = new BulkCopySimpleResultSet();
            string str3 = "select @@trancount; SET FMTONLY ON select * from " + this.DestinationTableName + " SET FMTONLY OFF ";

            if (this._connection.IsShiloh)
            {
                string str5;
                if (this._connection.IsKatmaiOrNewer)
                {
                    str5 = "sp_tablecollations_100";
                }
                else if (this._connection.IsYukonOrNewer)
                {
                    str5 = "sp_tablecollations_90";
                }
                else
                {
                    str5 = "sp_tablecollations";
                }
                string str  = strArray[3];
                bool   flag = (str.Length > 0) && ('#' == str[0]);
                if (!ADP.IsEmpty(str))
                {
                    str = SqlServerEscapeHelper.EscapeIdentifier(SqlServerEscapeHelper.EscapeStringAsLiteral(str));
                }
                string str2 = strArray[2];
                if (!ADP.IsEmpty(str2))
                {
                    str2 = SqlServerEscapeHelper.EscapeIdentifier(SqlServerEscapeHelper.EscapeStringAsLiteral(str2));
                }
                string str4 = strArray[1];
                if (flag && ADP.IsEmpty(str4))
                {
                    str3 = str3 + string.Format(null, "exec tempdb..{0} N'{1}.{2}'", new object[] { str5, str2, str });
                }
                else
                {
                    if (!ADP.IsEmpty(str4))
                    {
                        str4 = SqlServerEscapeHelper.EscapeIdentifier(str4);
                    }
                    str3 = str3 + string.Format(null, "exec {0}..{1} N'{2}.{3}'", new object[] { str4, str5, str2, str });
                }
            }
            Bid.Trace("<sc.SqlBulkCopy.CreateAndExecuteInitialQuery|INFO> Initial Query: '%ls' \n", str3);
            this._parser.TdsExecuteSQLBatch(str3, this.BulkCopyTimeout, null, this._stateObj);
            this._parser.Run(RunBehavior.UntilDone, null, null, bulkCopyHandler, this._stateObj);
            return(bulkCopyHandler);
        }