Esempio n. 1
0
		public static void Main()
		{
			SQLRConnection con = new SQLRConnection("sqlrserver", 9000, "/tmp/example.socket", "user", "password", 0, 1);
			SQLRCursor cur = new SQLRCursor(con);

			cur.prepareQuery("begin  select image into :image from images;  select description into :desc from images;  end;");
        		cur.defineOutputBindBlob("image");
        		cur.defineOutputBindClob("desc");
        		cur.executeQuery();

        		String image = cur.getOutputBindBlob("image");
        		UInt32 imagelength = cur.getOutputBindLength("image");

        		String desc = cur.getOutputBindClob("desc");
        		UInt32 desclength = cur.getOutputBindLength("desc");

        		con.endSession();
Esempio n. 2
0
        private void bindParameters()
        {
            _sqlrcur.clearBinds();

            for (Int32 i = 0; i < Parameters.Count; i++)
            {
                SQLRelayParameter param = (SQLRelayParameter)Parameters[i];

                if (param.Direction == ParameterDirection.Input)
                {
                    if (param.IsNull)
                    {
                        _sqlrcur.inputBind(param.ParameterName, null);
                        continue;
                    }

                    switch (param.SQLRelayType)
                    {
                    case SQLRelayType.Clob:
                        _sqlrcur.inputBindClob(param.ParameterName, Convert.ToString(param.Value), (UInt32)Convert.ToString(param.Value).Length);
                        continue;

                    case SQLRelayType.Blob:
                        _sqlrcur.inputBindBlob(param.ParameterName, (Byte[])param.Value, (UInt32)((Byte[])param.Value).Length);
                        continue;

                    case SQLRelayType.Cursor:
                        throw new NotSupportedException();
                    }

                    switch (param.DbType)
                    {
                    case DbType.AnsiString:
                    case DbType.AnsiStringFixedLength:
                    case DbType.String:
                    case DbType.StringFixedLength:
                    case DbType.Time:
                    case DbType.Guid:
                        _sqlrcur.inputBind(param.ParameterName, Convert.ToString(param.Value));
                        continue;

                    case DbType.Date:
                    case DbType.DateTime:
                    case DbType.DateTime2:
                    case DbType.DateTimeOffset:
                        DateTime dt = Convert.ToDateTime(param.Value);
                        _sqlrcur.inputBind(param.ParameterName, Convert.ToInt16(dt.Year), Convert.ToInt16(dt.Month), Convert.ToInt16(dt.Day), Convert.ToInt16(dt.Hour), Convert.ToInt16(dt.Minute), Convert.ToInt16(dt.Second), Convert.ToInt16(dt.Millisecond) * 1000, null, false);
                        continue;

                    case DbType.Binary:
                        _sqlrcur.inputBindBlob(param.ParameterName, (Byte[])param.Value, (UInt32)((Byte[])param.Value).Length);
                        continue;

                    case DbType.Boolean:
                        _sqlrcur.inputBind(param.ParameterName, (Convert.ToBoolean(param.Value) == true) ? 1 : 0);
                        continue;

                    case DbType.Currency:
                    case DbType.Decimal:
                    case DbType.Single:
                    case DbType.Double:
                    case DbType.VarNumeric:
                        _sqlrcur.inputBind(param.ParameterName, Convert.ToDouble(param.Value), 0, 0);
                        continue;

                    case DbType.Byte:
                    case DbType.Int16:
                    case DbType.Int32:
                    case DbType.Int64:
                    case DbType.SByte:
                    case DbType.UInt16:
                    case DbType.UInt32:
                    case DbType.UInt64:
                        _sqlrcur.inputBind(param.ParameterName, Convert.ToInt64(param.Value));
                        continue;

                    case DbType.Object:
                    case DbType.Xml:
                        _sqlrcur.inputBind(param.ParameterName, Convert.ToString(param.Value));
                        continue;
                    }
                }
                else if (param.Direction == ParameterDirection.Output)
                {
                    switch (param.SQLRelayType)
                    {
                    case SQLRelayType.Clob:
                        _sqlrcur.defineOutputBindClob(param.ParameterName);
                        continue;

                    case SQLRelayType.Blob:
                        _sqlrcur.defineOutputBindBlob(param.ParameterName);
                        continue;

                    case SQLRelayType.Cursor:
                        _sqlrcur.defineOutputBindCursor(param.ParameterName);
                        continue;
                    }

                    switch (param.DbType)
                    {
                    case DbType.AnsiString:
                    case DbType.AnsiStringFixedLength:
                    case DbType.String:
                    case DbType.StringFixedLength:
                    case DbType.Time:
                    case DbType.Guid:
                        _sqlrcur.defineOutputBindString(param.ParameterName, param.Size);
                        continue;

                    case DbType.Date:
                    case DbType.DateTime:
                    case DbType.DateTime2:
                    case DbType.DateTimeOffset:
                        _sqlrcur.defineOutputBindDate(param.ParameterName);
                        continue;

                    case DbType.Binary:
                        _sqlrcur.defineOutputBindBlob(param.ParameterName);
                        continue;

                    case DbType.Boolean:
                        _sqlrcur.defineOutputBindInteger(param.ParameterName);
                        continue;

                    case DbType.Currency:
                    case DbType.Decimal:
                    case DbType.Single:
                    case DbType.Double:
                    case DbType.VarNumeric:
                        _sqlrcur.defineOutputBindDouble(param.ParameterName);
                        continue;

                    case DbType.Byte:
                    case DbType.Int16:
                    case DbType.Int32:
                    case DbType.Int64:
                    case DbType.SByte:
                    case DbType.UInt16:
                    case DbType.UInt32:
                    case DbType.UInt64:
                        _sqlrcur.defineOutputBindInteger(param.ParameterName);
                        continue;

                    case DbType.Object:
                    case DbType.Xml:
                        _sqlrcur.defineOutputBindString(param.ParameterName, param.Size);
                        continue;
                    }
                }
                else if (param.Direction == ParameterDirection.InputOutput)
                {
                    // FIXME: SQL Relay doesn't currently support in/out parameters
                    throw new NotSupportedException();
                }
            }
        }