Exemplo n.º 1
0
		public void GetValuesTest()
		{
			BdpTransaction transaction = Connection.BeginTransaction();
						
			BdpCommand command = new BdpCommand("select * from TEST", Connection, transaction);
			
			Console.WriteLine();
			Console.WriteLine("DataReader - Read Method - Test");
			
			IDataReader reader = command.ExecuteReader();
			while (reader.Read())
			{
				object[] values = new object[reader.FieldCount];
				reader.GetValues(values);

				for (int i = 0; i < values.Length; i++)
				{
					Console.Write(values[i] + "\t");					
				}
			
				Console.WriteLine();
			}

			reader.Close();
			transaction.Rollback();	
			command.Dispose();
		}
        public void GetSchemaTableWithExpressionFieldTest()
        {
            BdpTransaction transaction = Connection.BeginTransaction();
            BdpCommand     command     = new BdpCommand("select TEST.*, 0 AS VALOR from TEST", Connection, transaction);

            BdpDataReader reader = command.ExecuteReader(CommandBehavior.SchemaOnly);

            DataTable schema = reader.GetSchemaTable();

            Console.WriteLine();
            Console.WriteLine("DataReader - GetSchemaTable Method- Test");

            DataRow[] currRows = schema.Select(null, null, DataViewRowState.CurrentRows);

            foreach (DataColumn myCol in schema.Columns)
            {
                Console.Write("{0}\t\t", myCol.ColumnName);
            }

            Console.WriteLine();

            foreach (DataRow myRow in currRows)
            {
                foreach (DataColumn myCol in schema.Columns)
                {
                    Console.Write("{0}\t\t", myRow[myCol]);
                }

                Console.WriteLine();
            }

            reader.Close();
            transaction.Rollback();
            command.Dispose();
        }
        public void IndexerByIndexTest()
        {
            BdpTransaction transaction = Connection.BeginTransaction();

            BdpCommand command = new BdpCommand("select * from TEST", Connection, transaction);

            Console.WriteLine();
            Console.WriteLine("DataReader - Read Method - Test");

            IDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                for (int i = 0; i < reader.FieldCount; i++)
                {
                    Console.Write(reader[i] + "\t");
                }

                Console.WriteLine();
            }

            reader.Close();
            transaction.Rollback();
            command.Dispose();
        }
Exemplo n.º 4
0
        public void NamedParametersReuseTest()
        {
            string sql = "select * from test where int_field >= @lang and int_field <= @lang";

            BdpCommand command = new BdpCommand(sql, this.Connection);

            command.Parameters.Add("@lang", BdpType.Int32).Value = 10;

            BdpDataReader reader = command.ExecuteReader();

            int count    = 0;
            int intValue = 0;

            while (reader.Read())
            {
                if (count == 0)
                {
                    intValue = reader.GetInt32(0);
                }
                count++;
            }

            Assert.AreEqual(1, count, "Invalid number of records fetched.");
            Assert.AreEqual(10, intValue, "Invalid record fetched.");

            reader.Close();
            command.Close();
        }
Exemplo n.º 5
0
        public void ExecuteReaderTest()
        {
            BdpCommand command = Connection.CreateCommand();

            command.CommandText = "select * from TEST";

            int    rows = 0;                // Holds number of rows;
            object rowNum;                  // Holds row number fetch from DB

            BdpDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {                               // Check INT field for proper value.
                rowNum = reader["INT_FIELD"];
                Assert.IsTrue((int)rowNum == rows, "Invalid row number");
                rows++;
            }

            reader.Close();

            Assert.IsTrue(Connection.State == ConnectionState.Open,
                          "Connection is not open");

            command.Close();
        }
        public void GetValuesTest()
        {
            BdpTransaction transaction = Connection.BeginTransaction();

            BdpCommand command = new BdpCommand("select * from TEST", Connection, transaction);

            Console.WriteLine();
            Console.WriteLine("DataReader - Read Method - Test");

            IDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                object[] values = new object[reader.FieldCount];
                reader.GetValues(values);

                for (int i = 0; i < values.Length; i++)
                {
                    Console.Write(values[i] + "\t");
                }

                Console.WriteLine();
            }

            reader.Close();
            transaction.Rollback();
            command.Dispose();
        }
        public void RecordAffectedTest()
        {
            string sql = "insert into test (int_field) values (100000);";

            BdpCommand command = new BdpCommand(sql, this.Connection);

            BdpDataReader reader = command.ExecuteReader();

            reader.Close();

            Assert.AreEqual(1, reader.RecordsAffected, "RecordsAffected value is incorrect");
        }
Exemplo n.º 8
0
        public void ExecuteReaderWithBehaviorTest()
        {
            BdpCommand command = new BdpCommand("select * from TEST", Connection);

            BdpDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);

            reader.Close();

            Assert.IsTrue(Connection.State == ConnectionState.Closed,
                          "Connection was not closed");

            command.Close();                // Check to make sure no exceptions are raised
        }
        public void GetCharsLengthTest()
        {
            string sql = "select clob_field from TEST where int_field = ?";

            BdpCommand command = new BdpCommand(sql, this.Connection);

            command.Parameters.Add("@int_field", BdpType.Int32).Value = 50;

            BdpDataReader reader = command.ExecuteReader();

            reader.Read();

            long length = reader.GetChars(0, 0, null, 0, 0);

            reader.Close();

            Assert.AreEqual(14, length, "Incorrect clob length");
        }
        public void NextResultTest()
        {
            string querys = "select * from TEST order by INT_FIELD asc;" +
                            "select * from TEST order by INT_FIELD desc;";

            BdpTransaction transaction = Connection.BeginTransaction();
            BdpCommand     command     = new BdpCommand(querys, Connection, transaction);

            BdpDataReader reader = command.ExecuteReader();

            Console.WriteLine();
            Console.WriteLine("DataReader - NextResult Method - Test ( First Result )");

            while (reader.Read())
            {
                for (int i = 0; i < reader.FieldCount; i++)
                {
                    Console.Write(reader.GetValue(i) + "\t");
                }

                Console.WriteLine();
            }

            if (reader.NextResult())
            {
                Console.WriteLine("DataReader - NextResult Method - Test ( Second Result )");

                while (reader.Read())
                {
                    for (int i = 0; i < reader.FieldCount; i++)
                    {
                        Console.Write(reader.GetValue(i) + "\t");
                    }

                    Console.WriteLine();
                }
            }

            reader.Close();
            transaction.Rollback();
            command.Dispose();
        }
Exemplo n.º 11
0
//      RPH - Changed parameter names to "?".  Parameters are substituted in order.
//		[Ignore("Named parameters are not support in the Borland Data Provider")]
        public void NamedParametersTest()
        {
            BdpCommand command = Connection.CreateCommand();

//			command.CommandText = "select CHAR_FIELD from TEST where INT_FIELD = @int_field or CHAR_FIELD = @char_field";
            command.CommandText = "select CHAR_FIELD from TEST where INT_FIELD = ? or CHAR_FIELD = ?";

            command.Parameters.Add("@int_field", 2);
            command.Parameters.Add("@char_field", "TWO");

            BdpDataReader reader = command.ExecuteReader();

            int count = 0;

            while (reader.Read())
            {
                count++;
            }

            Assert.AreEqual(1, count, "Invalid number of records fetched.");

            reader.Close();
            command.Close();
        }
Exemplo n.º 12
0
		public void ReadTest()
		{
			BdpTransaction transaction = Connection.BeginTransaction();
						
			BdpCommand command = new BdpCommand("select * from TEST", Connection, transaction);
			
			Console.WriteLine();
			Console.WriteLine("DataReader - Read Method - Test");
			
			IDataReader reader = command.ExecuteReader();
			while (reader.Read())
			{
				for(int i = 0; i < reader.FieldCount; i++)
				{
					Console.Write(reader.GetValue(i) + "\t");
				}
			
				Console.WriteLine();
			}

			reader.Close();
			command.Dispose();
			transaction.Rollback();
		}
Exemplo n.º 13
0
		public void GetSchemaTableWithExpressionFieldTest()
		{
			BdpTransaction transaction	= Connection.BeginTransaction();
			BdpCommand	  command		= new BdpCommand("select TEST.*, 0 AS VALOR from TEST", Connection, transaction);
	
			BdpDataReader reader = command.ExecuteReader(CommandBehavior.SchemaOnly);		
		
			DataTable schema = reader.GetSchemaTable();
			
			Console.WriteLine();
			Console.WriteLine("DataReader - GetSchemaTable Method- Test");

			DataRow[] currRows = schema.Select(null, null, DataViewRowState.CurrentRows);

			foreach (DataColumn myCol in schema.Columns)
			{
				Console.Write("{0}\t\t", myCol.ColumnName);
			}

			Console.WriteLine();
			
			foreach (DataRow myRow in currRows)
			{
				foreach (DataColumn myCol in schema.Columns)
				{
					Console.Write("{0}\t\t", myRow[myCol]);
				}
				
				Console.WriteLine();
			}
			
			reader.Close();
			transaction.Rollback();
			command.Dispose();
		}
Exemplo n.º 14
0
		public void RecordAffectedTest()
		{
			string sql = "insert into test (int_field) values (100000);";

			BdpCommand command = new BdpCommand(sql, this.Connection);

			BdpDataReader reader = command.ExecuteReader();
			reader.Close();

			Assert.AreEqual(1, reader.RecordsAffected, "RecordsAffected value is incorrect");
		}
Exemplo n.º 15
0
		public void GetCharsLengthTest()
		{
			string sql = "select clob_field from TEST where int_field = ?";

			BdpCommand command = new BdpCommand(sql, this.Connection);
			command.Parameters.Add("@int_field", BdpType.Int32).Value = 50;

			BdpDataReader reader = command.ExecuteReader();

			reader.Read();

			long length = reader.GetChars(0, 0, null, 0, 0);

			reader.Close();

			Assert.AreEqual(14, length, "Incorrect clob length");
		}
Exemplo n.º 16
0
        public void PrepareTest()
        {
            try
            {
                // Drop the table
                BdpCommand drop = new BdpCommand("drop table PrepareTest", Connection);
                drop.ExecuteNonQuery();
                drop.Close();
            }
            catch
            {
            }

            // Create a new test table
            BdpCommand create = new BdpCommand("create table PrepareTest(test_field varchar(20));", Connection);

            create.ExecuteNonQuery();
            create.Close();

            // Insert data using a prepared statement
            BdpCommand command = new BdpCommand(
                "INSERT INTO PrepareTest (test_field) VALUES (?);",
                Connection);

            command.Parameters.Add("@test_field", BdpType.String).Value = DBNull.Value;
            command.Prepare();

            for (int i = 0; i < 5; i++)
            {
                if (i < 1)
                {
                    command.Parameters[0].Value = DBNull.Value;
                }
                else
                {
                    command.Parameters[0].Value = i.ToString();
                }
                command.ExecuteNonQuery();
            }

            command.Close();

            try
            {
                // Check that data is correct
                BdpCommand    select = new BdpCommand("select * from PrepareTest", Connection);
                BdpDataReader reader = select.ExecuteReader();
                int           count  = 0;
                while (reader.Read())
                {
                    if (count == 0)
                    {
                        Assert.AreEqual(DBNull.Value, reader[0], "Invalid value.");
                    }
                    else
                    {
                        Assert.AreEqual(count.ToString(), reader.GetString(0).Trim(), "Invalid value.");
                    }

                    count++;
                }
                reader.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                // Drop table
                BdpCommand drop = new BdpCommand("drop table PrepareTest", Connection);
                drop.ExecuteNonQuery();
                drop.Close();
            }
        }
Exemplo n.º 17
0
		public void ExecuteReaderWithBehaviorTest()
		{
			BdpCommand command = new BdpCommand("select * from TEST", Connection);

			BdpDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
			reader.Close();

			Assert.IsTrue(Connection.State == ConnectionState.Closed,
			  "Connection was not closed");

			command.Close();    // Check to make sure no exceptions are raised
		}
Exemplo n.º 18
0
		public void NamedParametersReuseTest()
		{
			string sql = "select * from test where int_field >= @lang and int_field <= @lang";

			BdpCommand command = new BdpCommand(sql, this.Connection);
			command.Parameters.Add("@lang", BdpType.Int32).Value = 10;

			BdpDataReader reader = command.ExecuteReader();

			int count		= 0;
			int intValue	= 0;

			while (reader.Read())
			{
				if (count == 0)
				{
					intValue = reader.GetInt32(0);
				}
				count++;
			}

			Assert.AreEqual(1, count, "Invalid number of records fetched.");
			Assert.AreEqual(10, intValue, "Invalid record fetched.");

			reader.Close();
			command.Close();
		}
Exemplo n.º 19
0
		public void PrepareTest()
        {
            try
            {
                // Drop the table
                BdpCommand drop = new BdpCommand("drop table PrepareTest", Connection);
                drop.ExecuteNonQuery();
                drop.Close();
            }
            catch
            {
            }

            // Create a new test table
			BdpCommand create = new BdpCommand("create table PrepareTest(test_field varchar(20));", Connection);
			create.ExecuteNonQuery();
            create.Close();
		
			// Insert data using a prepared statement
			BdpCommand command = new BdpCommand(
				"INSERT INTO PrepareTest (test_field) VALUES (?);",
				Connection);
			
			command.Parameters.Add("@test_field", BdpType.String).Value = DBNull.Value;
			command.Prepare();

			for (int i = 0; i < 5; i++) 
			{
				if (i < 1)
				{
					command.Parameters[0].Value = DBNull.Value;
				}
				else
				{
					command.Parameters[0].Value = i.ToString();
				}
				command.ExecuteNonQuery();
			}

            command.Close();

			try
			{
				// Check that data is correct
				BdpCommand select = new BdpCommand("select * from PrepareTest", Connection);
				BdpDataReader reader = select.ExecuteReader();
				int count = 0;
				while (reader.Read())
				{
					if (count == 0)
					{
						Assert.AreEqual(DBNull.Value, reader[0], "Invalid value.");
					}
					else
					{
						Assert.AreEqual(count.ToString(), reader.GetString(0).Trim(), "Invalid value.");
					}

					count++;
				}
				reader.Close();
			}
			catch (Exception ex)
			{
				throw ex;
			}
			finally
			{
				// Drop table
				BdpCommand drop = new BdpCommand("drop table PrepareTest", Connection);
				drop.ExecuteNonQuery();
				drop.Close();
			}
		}
Exemplo n.º 20
0
		public void NextResultTest()
		{
			string querys = "select * from TEST order by INT_FIELD asc;" +
							"select * from TEST order by INT_FIELD desc;";

			BdpTransaction	transaction = Connection.BeginTransaction();
			BdpCommand		command		= new BdpCommand(querys, Connection, transaction);
	
			BdpDataReader reader = command.ExecuteReader();		

			Console.WriteLine();
			Console.WriteLine("DataReader - NextResult Method - Test ( First Result )");

			while (reader.Read())
			{
				for(int i = 0; i < reader.FieldCount; i++)
				{
					Console.Write(reader.GetValue(i) + "\t");					
				}
			
				Console.WriteLine();
			}

			if(reader.NextResult())
			{
				Console.WriteLine("DataReader - NextResult Method - Test ( Second Result )");
		
				while (reader.Read())
				{
					for(int i = 0; i < reader.FieldCount; i++)
					{
						Console.Write(reader.GetValue(i) + "\t");					
					}
				
					Console.WriteLine();
				}
			}

			reader.Close();
			transaction.Rollback();
			command.Dispose();
		}