internal DataTypeTimestamp( string typeName, VirtDbType vdbType, System.Data.DbType dbType, CLI.SqlType sqlType) : base(typeName, vdbType, dbType, sqlType, BufferTypes.Binary) { }
internal DataTypeXml( string typeName, VirtDbType vdbType, System.Data.DbType dbType, CLI.SqlType sqlType) : base(typeName, vdbType, dbType, sqlType, BufferTypes.Xml, true) { }
internal DataTypeNumeric( string typeName, VirtDbType vdbType, System.Data.DbType dbType, CLI.SqlType sqlType) : base(typeName, vdbType, dbType, sqlType, BufferTypes.Numeric) { }
internal DataTypeDateTime( string typeName, VirtDbType vdbType, System.Data.DbType dbType, CLI.SqlType sqlType) : base(typeName, vdbType, dbType, sqlType, BufferTypes.DateTime) { }
internal DataTypeInt16( string typeName, VirtDbType vdbType, System.Data.DbType dbType, CLI.SqlType sqlType) : base(typeName, vdbType, dbType, sqlType, BufferTypes.Short) { }
internal DataTypeSingle( string typeName, VirtDbType vdbType, System.Data.DbType dbType, CLI.SqlType sqlType) : base(typeName, vdbType, dbType, sqlType, BufferTypes.Float) { }
internal DataType( string typeName, VirtDbType vdbType, System.Data.DbType dbType, CLI.SqlType sqlType, BufferType bufferType) : this(typeName, vdbType, dbType, sqlType, bufferType, false) { }
internal DataTypeBinary( string typeName, VirtDbType vdbType, System.Data.DbType dbType, CLI.SqlType sqlType, bool isLong) : base(typeName, vdbType, dbType, sqlType, BufferTypes.Binary, isLong) { }
internal DataTypeChar( string typeName, VirtDbType vdbType, System.Data.DbType dbType, CLI.SqlType sqlType, bool isLong) #if false : base(typeName, vdbType, dbType, sqlType, BufferTypes.Char, isLong) #else : base(typeName, vdbType, dbType, sqlType, BufferTypes.WChar, isLong)
internal DataType( string typeName, VirtDbType vdbType, System.Data.DbType dbType, CLI.SqlType sqlType, BufferType bufferType, bool isLong) { this.typeName = typeName; this.vdbType = vdbType; this.dbType = dbType; this.sqlType = sqlType; this.bufferType = bufferType; this.isLong = isLong; }
internal static DataType MapSqlType(CLI.SqlType type) { switch (type) { case CLI.SqlType.SQL_CHAR: return(Char); case CLI.SqlType.SQL_VARCHAR: return(VarChar); case CLI.SqlType.SQL_LONGVARCHAR: return(LongVarChar); case CLI.SqlType.SQL_WCHAR: return(NChar); case CLI.SqlType.SQL_WVARCHAR: return(NVarChar); case CLI.SqlType.SQL_WLONGVARCHAR: return(NLongVarChar); case CLI.SqlType.SQL_BINARY: return(Timestamp); case CLI.SqlType.SQL_VARBINARY: return(VarBinary); case CLI.SqlType.SQL_LONGVARBINARY: return(LongVarBinary); case CLI.SqlType.SQL_BIGINT: return(BigInt); case CLI.SqlType.SQL_INTEGER: return(Integer); case CLI.SqlType.SQL_SMALLINT: return(SmallInt); case CLI.SqlType.SQL_REAL: return(Real); case CLI.SqlType.SQL_FLOAT: return(Float); case CLI.SqlType.SQL_DOUBLE: return(Double); case CLI.SqlType.SQL_DECIMAL: //return Decimal; case CLI.SqlType.SQL_NUMERIC: return(Numeric); case CLI.SqlType.SQL_DATE: case CLI.SqlType.SQL_TYPE_DATE: return(Date); case CLI.SqlType.SQL_TIME: case CLI.SqlType.SQL_TYPE_TIME: return(Time); case CLI.SqlType.SQL_TIMESTAMP: case CLI.SqlType.SQL_TYPE_TIMESTAMP: return(DateTime); } return(null); }
internal DataType ( string typeName, VirtDbType vdbType, System.Data.DbType dbType, CLI.SqlType sqlType, BufferType bufferType, bool isLong) { this.typeName = typeName; this.vdbType = vdbType; this.dbType = dbType; this.sqlType = sqlType; this.bufferType = bufferType; this.isLong = isLong; }
public static void DeriveParameters(VirtuosoCommand command) { if (command == null) { throw new ArgumentNullException("command"); } if (command.CommandType != CommandType.StoredProcedure) { throw new InvalidOperationException("DeriveParameters supports only stored procedures."); } VirtuosoConnection connection = (VirtuosoConnection)command.Connection; if (connection == null) { throw new InvalidOperationException("The Connection property is not set."); } if (connection.State == ConnectionState.Closed) { throw new InvalidOperationException("The connection is closed."); } IInnerCommand innerCommand = null; VirtuosoDataReader reader = null; try { innerCommand = connection.innerConnection.CreateInnerCommand(null); innerCommand.GetProcedureColumns(command.CommandText); reader = new VirtuosoDataReader(connection, innerCommand, null, CommandBehavior.Default, false); command.Parameters.Clear(); while (reader.Read()) { CLI.InOutType iotype = (CLI.InOutType)reader.GetInt16(reader.GetOrdinal("COLUMN_TYPE")); ParameterDirection direction; switch (iotype) { case CLI.InOutType.SQL_PARAM_INPUT: direction = ParameterDirection.Input; break; case CLI.InOutType.SQL_PARAM_OUTPUT: direction = ParameterDirection.Output; break; case CLI.InOutType.SQL_PARAM_INPUT_OUTPUT: direction = ParameterDirection.InputOutput; break; case CLI.InOutType.SQL_PARAM_RETURN_VALUE: direction = ParameterDirection.ReturnValue; break; default: #if MONO direction = ParameterDirection.Input; #endif continue; } string name = reader.GetString(reader.GetOrdinal("COLUMN_NAME")); if (name == "" && iotype == CLI.InOutType.SQL_PARAM_RETURN_VALUE) { name = "ReturnValue"; } CLI.SqlType sqlType = (CLI.SqlType)reader.GetInt16(reader.GetOrdinal("DATA_TYPE")); DataType type = DataTypeInfo.MapSqlType(sqlType); if (type == null) { throw new SystemException("Unknown data type"); } int sizeOrdinal = reader.GetOrdinal("COLUMN_SIZE"); if (sizeOrdinal < 0) { sizeOrdinal = reader.GetOrdinal("PRECISION"); } int size = reader.IsDBNull(sizeOrdinal) ? 0 : reader.GetInt32(sizeOrdinal); int scaleOrdinal = reader.GetOrdinal("DECIMAL_DIGITS"); if (scaleOrdinal < 0) { scaleOrdinal = reader.GetOrdinal("SCALE"); } short scale = reader.IsDBNull(scaleOrdinal) ? (short)0 : reader.GetInt16(scaleOrdinal); int nullableOrdinal = reader.GetOrdinal("NULLABLE"); CLI.Nullable nullable = (CLI.Nullable)reader.GetInt16(nullableOrdinal); bool isNullable = (nullable != CLI.Nullable.SQL_NO_NULLS); VirtuosoParameter parameter = (VirtuosoParameter)command.CreateParameter(); parameter.ParameterName = name; parameter.Direction = direction; parameter.VirtDbType = type.vdbType; parameter.Size = type.GetFieldSize(size); parameter.Precision = type.GetPrecision(size); parameter.Scale = (byte)scale; parameter.IsNullable = isNullable; command.Parameters.Add(parameter); } } finally { if (reader != null) { reader.Close(); } if (innerCommand != null) { innerCommand.Dispose(); } } }
internal void SetParameters(VirtuosoConnection connection, IntPtr hstmt) { Debug.WriteLineIf(CLI.FnTrace.Enabled, "ParameterData.SetParameters()"); for (int i = 0; i < parameters.Count; i++) { VirtuosoParameter param = (VirtuosoParameter)parameters[i]; Debug.WriteLineIf(Switch.Enabled, " param: " + param.paramName); CLI.InOutType ioType; switch (param.Direction) { default: // case ParameterDirection.Input: ioType = CLI.InOutType.SQL_PARAM_INPUT; break; case ParameterDirection.InputOutput: ioType = CLI.InOutType.SQL_PARAM_INPUT_OUTPUT; break; case ParameterDirection.Output: case ParameterDirection.ReturnValue: ioType = CLI.InOutType.SQL_PARAM_OUTPUT; break; } Debug.WriteLineIf(Switch.Enabled, " direction: " + param.Direction); IntPtr paramBuffer = buffer.GetAddress(offset[i]); int bufferLength = length[i]; int lengthOffset = 4 * i; CLI.SqlType sqlType = (param.paramType != null ? param.paramType.sqlType : CLI.SqlType.SQL_UNKNOWN_TYPE); CLI.ReturnCode rc = (CLI.ReturnCode)CLI.SQLBindParameter( hstmt, (ushort)(i + 1), (short)ioType, (short)param.bufferType.sqlCType, (short)sqlType, (IntPtr)param.Size, param.Scale, paramBuffer, (IntPtr)bufferLength, buffer.GetAddress(lengthOffset)); if (rc != CLI.ReturnCode.SQL_SUCCESS) { Diagnostics.HandleResult(rc, CLI.HandleType.SQL_HANDLE_STMT, hstmt, connection); } if (param.Direction == ParameterDirection.Input || param.Direction == ParameterDirection.InputOutput) { object value = param.bufferType.ConvertValue(param.Value); Debug.WriteLineIf(Switch.Enabled, " value: " + param.Value); int dataLength; if (value == null) { dataLength = (int)CLI.LengthCode.SQL_NULL_DATA; } else if (Convert.IsDBNull(value)) { dataLength = (int)CLI.LengthCode.SQL_NULL_DATA; } else { dataLength = param.bufferType.ManagedToNative(value, paramBuffer, bufferLength); } Marshal.WriteInt32(buffer.Handle, lengthOffset, dataLength); } } }