Exemple #1
0
 public VirtuosoCommand(string cmdText, VirtuosoConnection connection, VirtuosoTransaction transaction)
 {
     Debug.WriteLineIf(CLI.FnTrace.Enabled, "VirtuosoCommand.ctor()");
     this.commandText = cmdText;
     this.connection  = connection;
     this.transaction = transaction;
     this.parameters  = new VirtuosoParameterCollection(this);
 }
		private void Dispose (bool disposing)
		{
			if (disposing)
			{
				if (buffer != null)
					buffer.Dispose ();
			}
			parameters = null;
			offset = null;
			length = null;
			buffer = null;
		}
Exemple #3
0
        public void SetParameters(VirtuosoParameterCollection parameters)
        {
            this.parameters = parameters;
            if (parameters == null)
            {
                parameterValues = new object[0];
                return;
            }

            parameterValues = new object[parameters.Count];
            for (int i = 0; i < parameters.Count; i++)
            {
                VirtuosoParameter param = (VirtuosoParameter)parameters[i];
                Debug.WriteLineIf(Switch.Enabled, "  param: " + param.paramName);

                object value = null;
                if (param.Direction == ParameterDirection.Input ||
                    param.Direction == ParameterDirection.InputOutput)
                {
                    value = param.Value;
                    if (param.bufferType == null)
                    {
                        if (param.paramType != null)
                        {
                            param.bufferType = param.paramType.bufferType;
                        }
                        else if (value == null || Convert.IsDBNull(value))
                        {
                            param.bufferType = VirtuosoParameter.defaultType.bufferType;
                        }
                        else
                        {
                            param.bufferType = BufferTypes.InferBufferType(value);
                        }
                        if (param.bufferType == null)
                        {
                            throw new InvalidOperationException("Cannot infer parameter type");
                        }
                    }
                    value = param.bufferType.ConvertValue(param.Value);
                }
                Debug.WriteLineIf(Switch.Enabled, "  value: " + param.Value);
                if (value is System.String)
                {
                    BoxTag tag = (param.DbType == DbType.AnsiString ? BoxTag.DV_STRING : BoxTag.DV_WIDE);
                    parameterValues[i] = ExplicitString.CreateExplicitString((String)value, tag, connection);
                }
                else
                {
                    parameterValues[i] = value;
                }
            }
        }
Exemple #4
0
 public void SetParameters(VirtuosoParameterCollection parameters)
 {
     if (parameterData != null)
     {
         parameterData.Dispose();
         parameterData = null;
     }
     if (parameters != null && parameters.Count > 0)
     {
         parameterData = new ParameterData(parameters);
         parameterData.SetParameters((VirtuosoConnection)outerCommand.Connection, hstmt);
     }
 }
Exemple #5
0
        public void GetProcedureColumns(string text)
        {
            VirtuosoParameterCollection p = new VirtuosoParameterCollection(null);

            p.Add("p1", connection.OuterConnection.Database);
            p.Add("p2", "%");
            p.Add("p3", text);
            p.Add("p4", "%");
            p.Add("p5", 1);              // TODO: take casemode from the connection.
            p.Add("p6", 1);
            SetParameters(p);
            Execute("DB.DBA.SQL_PROCEDURE_COLUMNS (?, ?, ?, ?, ?, ?)");
        }
 private void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (buffer != null)
         {
             buffer.Dispose();
         }
     }
     parameters = null;
     offset     = null;
     length     = null;
     buffer     = null;
 }
Exemple #7
0
        private long rdfMakeObj(object box, string rtype, string lang)
        {
            long ro_id = 0;
            VirtuosoParameterCollection p0 = new VirtuosoParameterCollection(null);

            p0.Add("box", box);
            p0.Add("type", rtype);
            p0.Add("lang", lang);

            ManagedCommand cmd0 = new ManagedCommand(connection);

            cmd0.SetParameters(p0);
            try
            {
                cmd0.Execute("DB.DBA.RDF_MAKE_OBJ_OF_TYPEDSQLVAL (?, ?, ?)");
            }
            finally
            {
                cmd0.CloseCursor(true);
                cmd0.Dispose();
            }

            VirtuosoParameterCollection p1 = new VirtuosoParameterCollection(null);

            p1.Add("box", box);

            ManagedCommand cmd1 = new ManagedCommand(connection);

            cmd1.SetParameters(p1);
            try
            {
                cmd1.Execute("select rdf_box_ro_id (?)");
                while (cmd1.Fetch())
                {
                    object data = cmd1.GetColumnData(0, cmd1.GetColumnMetaData());
                    if (data != null)
                    {
                        ro_id = (long)data;
                    }
                }
            }
            finally
            {
                cmd1.CloseCursor(true);
                cmd1.Dispose();
            }
            return(ro_id);
        }
        public override void SetCurrentCatalog(string name)
        {
            VirtuosoParameterCollection p = new VirtuosoParameterCollection(null);

            p.Add("name", name);

            ManagedCommand cmd = new ManagedCommand(this);

            cmd.SetParameters(p);
            try
            {
                cmd.Execute("set_qualifier(?)");
            }
            finally
            {
                cmd.CloseCursor(true);
                cmd.Dispose();
            }
        }
Exemple #9
0
        // Reorders the parameter collection so that the order of named
        // parameters in the collection matches their order in the SQL
        // command.
        internal VirtuosoParameterCollection handleNamedParams(string sql, VirtuosoParameterCollection _parameters)
        {
            string paramPattern = @"@\w+";
            Regex  paramRegEx   = new Regex(paramPattern);
            Match  match        = paramRegEx.Match(sql);

            // If statement doesn't contain any named parameters
            if (!match.Success)
            {
                return(_parameters);
            }

            VirtuosoParameterCollection newParameters = new VirtuosoParameterCollection(this);

            while (match.Success)
            {
                string paramName = String.Copy(match.Value);

                if (_parameters.IndexOf(paramName) >= 0)
                {
                    newParameters.Add(_parameters[_parameters.IndexOf(paramName)]);
                }
                else
                {
                    // Seems param name saved in parameter
                    // collection may or may not have a
                    // leading @
                    string paramNameWithoutPrefix = String.Copy(paramName.Substring(1));
                    if (_parameters.IndexOf(paramNameWithoutPrefix) >= 0)
                    {
                        newParameters.Add(_parameters[_parameters.IndexOf(paramNameWithoutPrefix)]);
                    }
                }

                match = match.NextMatch();
            }

            return(newParameters);
        }
		// Reorders the parameter collection so that the order of named
		// parameters in the collection matches their order in the SQL 
		// command.
		internal VirtuosoParameterCollection handleNamedParams (string sql, VirtuosoParameterCollection _parameters)
		{
			string paramPattern = @"@\w+";
			Regex paramRegEx =  new Regex(paramPattern);
			Match match = paramRegEx.Match(sql);

			// If statement doesn't contain any named parameters
			if (!match.Success)
				return _parameters;

			VirtuosoParameterCollection newParameters = new VirtuosoParameterCollection (this);

			while(match.Success)
			{ 
				string paramName = String.Copy(match.Value);

				if (_parameters.IndexOf (paramName) >= 0)
					newParameters.Add (_parameters[_parameters.IndexOf (paramName)]);
				else
				{
					// Seems param name saved in parameter 
					// collection may or may not have a 
					// leading @
					string paramNameWithoutPrefix = String.Copy(paramName.Substring(1));
					if (_parameters.IndexOf (paramNameWithoutPrefix) >= 0)
					newParameters.Add (_parameters[_parameters.IndexOf (paramNameWithoutPrefix)]);
				}

		 		match = match.NextMatch();
			}
   
			return newParameters;
		}
 internal ParameterData(VirtuosoParameterCollection parameters)
 {
     this.parameters = parameters;
     Initialize();
 }
Exemple #12
0
        public VirtuosoDataReader ExecuteReader(CommandBehavior behavior)
#endif
        {
            /*
             * ExecuteReader should retrieve results from the data source
             * and return a DataReader that allows the user to process
             * the results.
             */
            Debug.WriteLineIf(CLI.FnTrace.Enabled, "VirtuosoCommand.ExecuteReader()");

            // There must be a valid and open connection.
            if (connection == null || connection.State != ConnectionState.Open)
            {
                throw new InvalidOperationException("Connection must be valid and open");
            }

            VirtuosoConnection.permission.Demand();

            CheckState();

            if (innerCommand == null)
            {
                innerCommand = connection.innerConnection.CreateInnerCommand(this);
            }
            innerCommand.SetTimeout(timeout);
            innerCommand.SetCommandBehavior(behavior);

            bool   schemaOnly = SchemaOnlyDataReader(behavior);
            string text       = GetCommandText();
            bool   isSparql   = text.TrimStart(null).StartsWith("sparql", StringComparison.OrdinalIgnoreCase);

            if (schemaOnly)
            {
                if (!isPrepared)
                {
                    if (!isSparql)
                    {
                        text = replaceNamedParams(text);
                    }
                    innerCommand.Prepare(text);
                }
            }
            else
            {
                if (!isSparql && parameters != null && parameters.Count > 0)
                {
                    VirtuosoParameterCollection _parameters = handleNamedParams(text, parameters);
                    Debug.Assert(_parameters.Count == parameters.Count, "Count mismatch in reordered parameter array");
                    text = replaceNamedParams(text);
                }
                innerCommand.SetParameters(parameters);
                if (!isPrepared)
                {
                    try
                    {
                        isExecuting = true;
                        innerCommand.Execute(text);
                        if (executeSecondaryStmt)
                        {
                            innerCommand.CloseCursor(false);
                            innerCommand.Execute(secondaryStmt);
                        }
                    }
                    finally
                    {
                        isExecuting = false;
                    }
                }
                else
                {
                    try
                    {
                        isExecuting = true;
                        innerCommand.Execute();
                        if (executeSecondaryStmt)
                        {
                            innerCommand.CloseCursor(false);
                            innerCommand.Execute(secondaryStmt);
                        }
                    }
                    finally
                    {
                        isExecuting = false;
                    }
                }
                isExecuted = true;
            }

            VirtuosoDataReader reader = new VirtuosoDataReader(connection, innerCommand, this, behavior, schemaOnly);

            dataReaderWeakRef = new WeakReference(reader);
            isFetching        = true;
            return(reader);
        }
		internal ParameterData (VirtuosoParameterCollection parameters)
		{
			this.parameters = parameters;
			Initialize ();
		}
        private void InsertRow(int id)
        {
            object i, si, d, r, n, year, month, day, dt, tm, dtm, str, bin;

            if (id == 0)
            {
                i = si = d = r = n = year = month = day = dt = tm = dtm = str = bin = DBNull.Value;
            }
            else
            {
                i     = id + 1000;
                si    = (short)(id + 2000);
                d     = id * 1000.0001;
                r     = (float)(id * 100.001);
                n     = (decimal)id * 10000001;
                year  = 1990 + id;
                month = (id - 1) % 12 + 1;
                day   = (id - 1) % DateTime.DaysInMonth((int)year, (int)month) + 1;
                dt    = new DateTime((int)year, (int)month, (int)day);
                tm    = new TimeSpan(id % 24, id % 60, id % 60);
                dtm   = new DateTime((int)year, (int)month, (int)day, id % 24, id % 60, id % 60);

                int    length = id % 128;
                char[] chars  = new char[length];
                byte[] bytes  = new byte[length];
                for (int count = 0; count < length; count++)
                {
                    chars[count] = (char)('a' + (id + count) % 26 - 1);
                    bytes[count] = (byte)(id + count);
                }
                str = new String(chars);
                bin = bytes;
            }

            VirtuosoCommand insert = connection.CreateCommand();

            insert.CommandText =
                "insert into foo "
                + "(id, i, si, d, r, n, dt, tm, dtm, c, vc, lvc, nc, nvc, lnvc, b, vb, lvb) "
                + "values "
                + "(?,  ?,  ?, ?, ?, ?,  ?,  ?,   ?, ?,  ?,   ?,  ?,   ?,    ?, ?,  ?,   ?)";

            VirtuosoParameterCollection parameters = insert.Parameters;

            VirtuosoParameter idParam = insert.CreateParameter();

            idParam.ParameterName = "id";
            idParam.DbType        = DbType.Int32;
            idParam.Value         = id;
            parameters.Add(idParam);

            VirtuosoParameter iParam = insert.CreateParameter();

            iParam.ParameterName = "i";
            iParam.DbType        = DbType.Int32;
            iParam.Value         = i;
            parameters.Add(iParam);

            VirtuosoParameter siParam = insert.CreateParameter();

            siParam.ParameterName = "si";
            siParam.DbType        = DbType.Int16;
            siParam.Value         = si;
            parameters.Add(siParam);

            VirtuosoParameter dParam = insert.CreateParameter();

            dParam.ParameterName = "d";
            dParam.DbType        = DbType.Double;
            dParam.Value         = d;
            parameters.Add(dParam);

            VirtuosoParameter rParam = insert.CreateParameter();

            rParam.ParameterName = "r";
            rParam.DbType        = DbType.Single;
            rParam.Value         = r;
            parameters.Add(rParam);

            VirtuosoParameter nParam = insert.CreateParameter();

            nParam.ParameterName = "n";
            nParam.DbType        = DbType.Decimal;
            nParam.Value         = n;
            parameters.Add(nParam);

            VirtuosoParameter dtParam = insert.CreateParameter();

            dtParam.ParameterName = "dt";
            dtParam.DbType        = DbType.Date;
            dtParam.Value         = dt;
            parameters.Add(dtParam);

            VirtuosoParameter tmParam = insert.CreateParameter();

            tmParam.ParameterName = "tm";
            tmParam.DbType        = DbType.Time;
            tmParam.Value         = tm;
            parameters.Add(tmParam);

            VirtuosoParameter dtmParam = insert.CreateParameter();

            dtmParam.ParameterName = "dtm";
            dtmParam.DbType        = DbType.DateTime;
            dtmParam.Value         = dtm;
            parameters.Add(dtmParam);

            VirtuosoParameter cParam = insert.CreateParameter();

            cParam.ParameterName = "c";
            cParam.DbType        = DbType.AnsiStringFixedLength;
            cParam.Value         = str;
            parameters.Add(cParam);

            VirtuosoParameter vcParam = insert.CreateParameter();

            vcParam.ParameterName = "vc";
            vcParam.DbType        = DbType.AnsiString;
            vcParam.Value         = str;
            parameters.Add(vcParam);

            VirtuosoParameter lvcParam = insert.CreateParameter();

            lvcParam.ParameterName = "lvc";
            lvcParam.DbType        = DbType.AnsiString;
            lvcParam.Value         = str;
            parameters.Add(lvcParam);

            VirtuosoParameter ncParam = insert.CreateParameter();

            ncParam.ParameterName = "nc";
            ncParam.DbType        = DbType.StringFixedLength;
            ncParam.Value         = str;
            parameters.Add(ncParam);

            VirtuosoParameter nvcParam = insert.CreateParameter();

            nvcParam.ParameterName = "nvc";
            nvcParam.DbType        = DbType.String;
            nvcParam.Value         = str;
            parameters.Add(nvcParam);

            VirtuosoParameter lnvcParam = insert.CreateParameter();

            lnvcParam.ParameterName = "lnvc";
            lnvcParam.DbType        = DbType.String;
            lnvcParam.Value         = str;
            parameters.Add(lnvcParam);

            VirtuosoParameter bParam = insert.CreateParameter();

            bParam.ParameterName = "b";
            bParam.DbType        = DbType.Binary;
            bParam.Value         = bin;
            parameters.Add(bParam);

            VirtuosoParameter vbParam = insert.CreateParameter();

            vbParam.ParameterName = "vb";
            vbParam.DbType        = DbType.Binary;
            vbParam.Value         = bin;
            parameters.Add(vbParam);

            VirtuosoParameter lvbParam = insert.CreateParameter();

            lvbParam.ParameterName = "lvb";
            lvbParam.DbType        = DbType.Binary;
            lvbParam.Value         = bin;
            parameters.Add(lvbParam);

            try
            {
                insert.ExecuteNonQuery();
            }
            finally
            {
                insert.Dispose();
                insert = null;
            }

            DataRow row = checkTable.NewRow();

            row["id"]   = id;
            row["i"]    = i;
            row["si"]   = si;
            row["d"]    = d;
            row["r"]    = r;
            row["n"]    = n;
            row["dt"]   = dt;
            row["tm"]   = tm;
            row["dtm"]  = dtm;
            row["c"]    = str;
            row["vc"]   = str;
            row["lvc"]  = str;
            row["nc"]   = str;
            row["nvc"]  = str;
            row["lnvc"] = str;
            row["b"]    = bin;
            row["vb"]   = bin;
            row["lvb"]  = bin;
            checkTable.Rows.Add(row);
        }
		public override void SetCurrentCatalog (string name)
		{
			VirtuosoParameterCollection p = new VirtuosoParameterCollection (null);
			p.Add ("name", name);

			ManagedCommand cmd = new ManagedCommand (this);
			cmd.SetParameters (p);
			try
			{
				cmd.Execute ("set_qualifier(?)");
			}
			finally
			{
				cmd.CloseCursor (true);
				cmd.Dispose ();
			}
		}
		public void SetParameters (VirtuosoParameterCollection parameters)
		{
			this.parameters = parameters;
			if (parameters == null)
			{
				parameterValues = new object[0];
				return;
			}

			parameterValues = new object[parameters.Count];
			for (int i = 0; i < parameters.Count; i++)
			{
				VirtuosoParameter param = (VirtuosoParameter) parameters[i];
				Debug.WriteLineIf (Switch.Enabled, "  param: " + param.paramName);

				object value = null;
				if (param.Direction == ParameterDirection.Input
					|| param.Direction == ParameterDirection.InputOutput)
				{
					value = param.Value;
					if (param.bufferType == null)
					{
						if (param.paramType != null)
							param.bufferType = param.paramType.bufferType;
						else if (value == null || Convert.IsDBNull (value))
							param.bufferType = VirtuosoParameter.defaultType.bufferType;
						else
							param.bufferType = BufferTypes.InferBufferType (value);
						if (param.bufferType == null)
							throw new InvalidOperationException ("Cannot infer parameter type");
					}
					value = param.bufferType.ConvertValue (param.Value);
				}
				Debug.WriteLineIf (Switch.Enabled, "  value: " + param.Value);
				if (value is System.String)
				{
				    BoxTag tag = (param.DbType == DbType.AnsiString ? BoxTag.DV_STRING : BoxTag.DV_WIDE);
				    parameterValues[i] = ExplicitString.CreateExplicitString((String)value, tag, connection);
				}
				else
				    parameterValues[i] = value;
			}
		}
        private void InsertRow(int id)
        {
            object c, nc, b;

            if (id == 0)
            {
                c = nc = b = DBNull.Value;
            }
            else
            {
                int    length = 1 << (id - 1);
                char[] chars  = new char[length];
                byte[] bytes  = new byte[length];
                for (int i = 0; i < length; i++)
                {
                    chars[i] = (char)(' ' + i % (127 - ' '));
                    bytes[i] = (byte)(i % 256);
                }
                c = nc = new String(chars);
                b = bytes;
            }

            VirtuosoCommand insert = connection.CreateCommand();

            insert.CommandText =
                "insert into foo "
                + "(id, c, nc, b) "
                + "values "
                + "(?,  ?,  ?, ?)";

            VirtuosoParameterCollection parameters = insert.Parameters;

            VirtuosoParameter idParam = insert.CreateParameter();

            idParam.ParameterName = "id";
            idParam.DbType        = DbType.Int32;
            idParam.Value         = id;
            parameters.Add(idParam);

            VirtuosoParameter cParam = insert.CreateParameter();

            cParam.ParameterName = "c";
            cParam.DbType        = DbType.AnsiString;
            cParam.Value         = c;
            parameters.Add(cParam);

            VirtuosoParameter ncParam = insert.CreateParameter();

            ncParam.ParameterName = "nc";
            ncParam.DbType        = DbType.String;
            ncParam.Value         = nc;
            parameters.Add(ncParam);

            VirtuosoParameter bParam = insert.CreateParameter();

            bParam.ParameterName = "b";
            bParam.DbType        = DbType.Binary;
            bParam.Value         = b;
            parameters.Add(bParam);

            try
            {
                insert.ExecuteNonQuery();
            }
            finally
            {
                insert.Dispose();
                insert = null;
            }

            DataRow row = checkTable.NewRow();

            row["id"] = id;
            row["c"]  = c;
            row["nc"] = nc;
            row["b"]  = b;
            checkTable.Rows.Add(row);
        }
      private long rdfMakeObj (object box, string rtype, string lang)
      {
	long ro_id = 0;
	VirtuosoParameterCollection p0 = new VirtuosoParameterCollection (null);
        p0.Add("box", box);
	p0.Add("type", rtype);
        p0.Add("lang", lang);

	ManagedCommand cmd0 = new ManagedCommand (connection);
	cmd0.SetParameters (p0);
	try
	{
		cmd0.Execute ("DB.DBA.RDF_MAKE_OBJ_OF_TYPEDSQLVAL (?, ?, ?)");
	}
	finally
	{
		cmd0.CloseCursor (true);
		cmd0.Dispose ();
	}

	VirtuosoParameterCollection p1 = new VirtuosoParameterCollection (null);
        p1.Add("box", box);

	ManagedCommand cmd1 = new ManagedCommand (connection);
	cmd1.SetParameters (p1);
	try
	{
		cmd1.Execute ("select rdf_box_ro_id (?)");
                while(cmd1.Fetch())
                {
		    object data = cmd1.GetColumnData (0, cmd1.GetColumnMetaData ());
		    if (data != null)
			  ro_id = (long) data;
                }
	}
	finally
	{
		cmd1.CloseCursor (true);
		cmd1.Dispose ();
	}
	return ro_id;
      }
		public void GetProcedureColumns (string text)
		{
			VirtuosoParameterCollection p = new VirtuosoParameterCollection (null);
			p.Add ("p1", connection.OuterConnection.Database);
			p.Add ("p2", "%");
			p.Add ("p3", text);
			p.Add ("p4", "%");
			p.Add ("p5", 1); // TODO: take casemode from the connection.
			p.Add ("p6", 1);
			SetParameters (p);
			Execute ("DB.DBA.SQL_PROCEDURE_COLUMNS (?, ?, ?, ?, ?, ?)");
		}
		public VirtuosoCommand (string cmdText, VirtuosoConnection connection, VirtuosoTransaction transaction)
		{
			Debug.WriteLineIf (CLI.FnTrace.Enabled, "VirtuosoCommand.ctor()");
			this.commandText = cmdText;
			this.connection = connection;
			this.transaction = transaction;
			this.parameters = new VirtuosoParameterCollection (this);
		}
		public void SetParameters (VirtuosoParameterCollection parameters)
		{
			if (parameterData != null)
			{
				parameterData.Dispose ();
				parameterData = null;
			}
			if (parameters != null && parameters.Count > 0)
			{
				parameterData = new ParameterData (parameters);
				parameterData.SetParameters ((VirtuosoConnection) outerCommand.Connection, hstmt);
			}
		}