コード例 #1
0
        public ExcelWorksheet(string sheet, OdbcConnection conn)
        {
            //this.BeginInit();

            OdbcDataAdapter conncmd;
            using (DataTable table = new DataTable())
            {
                using (OdbcCommandBuilder bldr = new OdbcCommandBuilder())
                {
                    using (conncmd = new OdbcDataAdapter("SELECT * FROM " + bldr.QuoteIdentifier(sheet, conn), conn))
                    {
                        conncmd.Fill(table);
                    }
                }

                this.Load(table);
            }

            //this.EndInit();
        }
コード例 #2
0
		[Test] // QuoteIdentifier (String, OdbcConnection)
		public void QuoteIdentifier2 ()
		{
			OdbcCommandBuilder cb;
			OdbcConnection conn = (OdbcConnection) ConnectionManager.Singleton.Connection;
			ConnectionManager.Singleton.OpenConnection ();

			string quote_char = ConnectionManager.Singleton.Engine.QuoteCharacter;

			try {
				cb = new OdbcCommandBuilder ();
				Assert.AreEqual (quote_char + "mono" + quote_char, cb.QuoteIdentifier ("mono", conn), "#A1");
				Assert.AreEqual (quote_char + "Z" + quote_char, cb.QuoteIdentifier ("Z", conn), "#A2");
				Assert.AreEqual (quote_char + "abc" + quote_char, cb.QuoteIdentifier ("abc", conn), "#A3");
				Assert.AreEqual (quote_char + quote_char, cb.QuoteIdentifier (string.Empty, conn), "#A4");
				Assert.AreEqual (quote_char + " " + quote_char, cb.QuoteIdentifier (" ", conn), "#A5");
				Assert.AreEqual (quote_char + "\r" + quote_char, cb.QuoteIdentifier ("\r", conn), "#A6");
				cb.QuoteSuffix = "def";
				Assert.AreEqual (quote_char + "mono" + quote_char, cb.QuoteIdentifier ("mono", conn), "#A7");
				Assert.AreEqual (quote_char + "Z" + quote_char, cb.QuoteIdentifier ("Z", conn), "#A8");
				Assert.AreEqual (quote_char + "abc" + quote_char, cb.QuoteIdentifier ("abc", conn), "#A9");
				Assert.AreEqual (quote_char + quote_char, cb.QuoteIdentifier (string.Empty, conn), "#A10");
				Assert.AreEqual (quote_char + " " + quote_char, cb.QuoteIdentifier (" ", conn), "#A11");
				Assert.AreEqual (quote_char + "\r" + quote_char, cb.QuoteIdentifier ("\r", conn), "#A12");

				cb = new OdbcCommandBuilder ();
				cb.QuotePrefix = "abc";
				Assert.AreEqual ("abcmono", cb.QuoteIdentifier ("mono", conn), "#B1");
				Assert.AreEqual ("abcZ", cb.QuoteIdentifier ("Z", conn), "#B2");
				Assert.AreEqual ("abcabc", cb.QuoteIdentifier ("abc", conn), "#B3");
				Assert.AreEqual ("abc", cb.QuoteIdentifier (string.Empty, conn), "#B4");
				Assert.AreEqual ("abc ", cb.QuoteIdentifier (" ", conn), "#B5");
				Assert.AreEqual ("abc\r", cb.QuoteIdentifier ("\r", conn), "#B6");
				cb.QuoteSuffix = "def";
				Assert.AreEqual ("abcmonodef", cb.QuoteIdentifier ("mono", conn), "#B7");
				Assert.AreEqual ("abcZdef", cb.QuoteIdentifier ("Z", conn), "#B8");
				Assert.AreEqual ("abcabcdef", cb.QuoteIdentifier ("abc", conn), "#B9");
				Assert.AreEqual ("abcdef", cb.QuoteIdentifier (string.Empty, conn), "#B10");
				Assert.AreEqual ("abc def", cb.QuoteIdentifier (" ", conn), "#B11");
				Assert.AreEqual ("abc\rdef", cb.QuoteIdentifier ("\r", conn), "#B12");

				cb.QuotePrefix = string.Empty;

				cb = new OdbcCommandBuilder ();
				cb.QuotePrefix = "X";
				Assert.AreEqual ("Xmono", cb.QuoteIdentifier ("mono", conn), "#D1");
				Assert.AreEqual ("XZ", cb.QuoteIdentifier ("Z", conn), "#D2");
				Assert.AreEqual ("XX", cb.QuoteIdentifier ("X", conn), "#D3");
				Assert.AreEqual ("X", cb.QuoteIdentifier (string.Empty, conn), "#D4");
				Assert.AreEqual ("X ", cb.QuoteIdentifier (" ", conn), "#D5");
				Assert.AreEqual ("X\r", cb.QuoteIdentifier ("\r", conn), "#D6");
				cb.QuoteSuffix = " ";
				Assert.AreEqual ("Xmono ", cb.QuoteIdentifier ("mono", conn), "#D7");
				Assert.AreEqual ("XZ ", cb.QuoteIdentifier ("Z", conn), "#D8");
				Assert.AreEqual ("XX ", cb.QuoteIdentifier ("X", conn), "#D9");
				Assert.AreEqual ("X ", cb.QuoteIdentifier (string.Empty, conn), "#D10");
				Assert.AreEqual ("X   ", cb.QuoteIdentifier (" ", conn), "#D11");
				Assert.AreEqual ("X\r ", cb.QuoteIdentifier ("\r", conn), "#D12");

				cb = new OdbcCommandBuilder ();
				cb.QuotePrefix = " ";
				Assert.AreEqual ("mono", cb.QuoteIdentifier ("mono", conn), "#E1");
				Assert.AreEqual ("Z", cb.QuoteIdentifier ("Z", conn), "#E2");
				Assert.AreEqual ("abc", cb.QuoteIdentifier ("abc", conn), "#E3");
				Assert.AreEqual (string.Empty, cb.QuoteIdentifier (string.Empty, conn), "#E4");
				Assert.AreEqual (" ", cb.QuoteIdentifier (" ", conn), "#E5");
				Assert.AreEqual ("\r", cb.QuoteIdentifier ("\r", conn), "#E6");
				cb.QuoteSuffix = "def";
				Assert.AreEqual ("mono", cb.QuoteIdentifier ("mono", conn), "#E7");
				Assert.AreEqual ("Z", cb.QuoteIdentifier ("Z", conn), "#E8");
				Assert.AreEqual ("abc", cb.QuoteIdentifier ("abc", conn), "#E9");
				Assert.AreEqual (string.Empty, cb.QuoteIdentifier (string.Empty, conn), "#E10");
				Assert.AreEqual (" ", cb.QuoteIdentifier (" ", conn), "#E11");
				Assert.AreEqual ("\r", cb.QuoteIdentifier ("\r", conn), "#E12");
			} finally {
				ConnectionManager.Singleton.CloseConnection ();
			}
		}
コード例 #3
0
        private void LoadMarksSheet(string filename, OdbcConnection conn)
        {
            OdbcDataAdapter conncmd;
            using (DataTable table = new DataTable())
            {
                using (OdbcCommandBuilder bldr = new OdbcCommandBuilder())
                {
                    using (conncmd = new OdbcDataAdapter("SELECT * FROM " + bldr.QuoteIdentifier("Marks", conn), conn))
                    {
                        conncmd.Fill(table);
                    }
                }

                if (table.Columns.Contains("Name"))
                {
                    LoadDataTable(filename, table);
                }
            }
        }
コード例 #4
0
		[Test] // QuoteIdentifier (String, OdbcConnection)
		public void QuoteIdentifier2_Connection_Closed ()
		{
			OdbcCommandBuilder cb;
			OdbcConnection conn = new OdbcConnection ();

			cb = new OdbcCommandBuilder ();
			try {
				cb.QuoteIdentifier ("mono", conn);
				Assert.Fail ("#A1");
			} catch (InvalidOperationException ex) {
				// QuoteIdentifier requires an open and available
				// Connection. The connection's current state is
				// closed
				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
				Assert.IsNull (ex.InnerException, "#A3");
				Assert.IsNotNull (ex.Message, "#A4");
			}

			cb = new OdbcCommandBuilder ();
			cb.QuotePrefix = "abc";
			Assert.AreEqual ("abcmono", cb.QuoteIdentifier ("mono", conn), "#B1");
			Assert.AreEqual ("abcZ", cb.QuoteIdentifier ("Z", conn), "#B2");
			Assert.AreEqual ("abcabc", cb.QuoteIdentifier ("abc", conn), "#B3");
			Assert.AreEqual ("abc", cb.QuoteIdentifier (string.Empty, conn), "#B4");
			Assert.AreEqual ("abc ", cb.QuoteIdentifier (" ", conn), "#B5");
			Assert.AreEqual ("abc\r", cb.QuoteIdentifier ("\r", conn), "#B6");
			cb.QuoteSuffix = "def";
			Assert.AreEqual ("abcmonodef", cb.QuoteIdentifier ("mono", conn), "#B7");
			Assert.AreEqual ("abcZdef", cb.QuoteIdentifier ("Z", conn), "#B8");
			Assert.AreEqual ("abcabcdef", cb.QuoteIdentifier ("abc", conn), "#B9");
			Assert.AreEqual ("abcdef", cb.QuoteIdentifier (string.Empty, conn), "#B10");
			Assert.AreEqual ("abc def", cb.QuoteIdentifier (" ", conn), "#B11");
			Assert.AreEqual ("abc\rdef", cb.QuoteIdentifier ("\r", conn), "#B12");

			cb.QuotePrefix = string.Empty;
			try {
				cb.QuoteIdentifier ("mono");
				Assert.Fail ("#C1");
			} catch (InvalidOperationException ex) {
				// QuoteIdentifier requires an open and available
				// Connection. The connection's current state is
				// closed
				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#C2");
				Assert.IsNull (ex.InnerException, "#C3");
				Assert.IsNotNull (ex.Message, "#C4");
			}

			cb = new OdbcCommandBuilder ();
			cb.QuotePrefix = "X";
			Assert.AreEqual ("Xmono", cb.QuoteIdentifier ("mono"), "#D1");
			Assert.AreEqual ("XZ", cb.QuoteIdentifier ("Z"), "#D2");
			Assert.AreEqual ("XX", cb.QuoteIdentifier ("X"), "#D3");
			Assert.AreEqual ("X", cb.QuoteIdentifier (string.Empty, conn), "#D4");
			Assert.AreEqual ("X ", cb.QuoteIdentifier (" ", conn), "#D5");
			Assert.AreEqual ("X\r", cb.QuoteIdentifier ("\r", conn), "#D6");
			cb.QuoteSuffix = " ";
			Assert.AreEqual ("Xmono ", cb.QuoteIdentifier ("mono"), "#D7");
			Assert.AreEqual ("XZ ", cb.QuoteIdentifier ("Z"), "#D8");
			Assert.AreEqual ("XX ", cb.QuoteIdentifier ("X"), "#D9");
			Assert.AreEqual ("X ", cb.QuoteIdentifier (string.Empty, conn), "#D10");
			Assert.AreEqual ("X   ", cb.QuoteIdentifier (" ", conn), "#D11");
			Assert.AreEqual ("X\r ", cb.QuoteIdentifier ("\r", conn), "#D12");

			cb = new OdbcCommandBuilder ();
			cb.QuotePrefix = " ";
			Assert.AreEqual ("mono", cb.QuoteIdentifier ("mono", conn), "#E1");
			Assert.AreEqual ("Z", cb.QuoteIdentifier ("Z", conn), "#E2");
			Assert.AreEqual ("abc", cb.QuoteIdentifier ("abc", conn), "#E3");
			Assert.AreEqual (string.Empty, cb.QuoteIdentifier (string.Empty, conn), "#E4");
			Assert.AreEqual (" ", cb.QuoteIdentifier (" ", conn), "#E5");
			Assert.AreEqual ("\r", cb.QuoteIdentifier ("\r", conn), "#E6");
			cb.QuoteSuffix = "def";
			Assert.AreEqual ("mono", cb.QuoteIdentifier ("mono", conn), "#E7");
			Assert.AreEqual ("Z", cb.QuoteIdentifier ("Z", conn), "#E8");
			Assert.AreEqual ("abc", cb.QuoteIdentifier ("abc", conn), "#E9");
			Assert.AreEqual (string.Empty, cb.QuoteIdentifier (string.Empty, conn), "#E10");
			Assert.AreEqual (" ", cb.QuoteIdentifier (" ", conn), "#E11");
			Assert.AreEqual ("\r", cb.QuoteIdentifier ("\r", conn), "#E12");
		}
コード例 #5
0
		[Test] // QuoteIdentifier (String)
		public void QuoteIdentifier1_UnquotedIdentifier_Null ()
		{
			OdbcCommandBuilder cb = new OdbcCommandBuilder ();
			try {
				cb.QuoteIdentifier ((string) null);
				Assert.Fail ("#1");
			} catch (ArgumentNullException ex) {
				Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
				Assert.IsNull (ex.InnerException, "#3");
				Assert.IsNotNull (ex.Message, "#4");
				Assert.AreEqual ("unquotedIdentifier", ex.ParamName, "#5");
			}
		}
コード例 #6
0
		[Test] // QuoteIdentifier (String)
		public void QuoteIdentifier1_QuotePrefix_Empty ()
		{
			OdbcCommandBuilder cb = new OdbcCommandBuilder ();
			try {
				cb.QuoteIdentifier ("mono");
				Assert.Fail ("#1");
			} catch (InvalidOperationException ex) {
				// QuoteIdentifier requires open connection when
				// the quote prefix has not been set
				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
				Assert.IsNull (ex.InnerException, "#3");
				Assert.IsNotNull (ex.Message, "#4");
			}
		}
コード例 #7
0
		[Test] // QuoteIdentifier (String)
		public void QuoteIdentifier1 ()
		{
			OdbcCommandBuilder cb;
		
			cb = new OdbcCommandBuilder ();
			cb.QuotePrefix = "aBc";
			Assert.AreEqual ("aBcmoAbCno", cb.QuoteIdentifier ("moAbCno"), "#A1");
			Assert.AreEqual ("aBc", cb.QuoteIdentifier (string.Empty), "#A2");
			Assert.AreEqual ("aBcZ", cb.QuoteIdentifier ("Z"), "#A3");
			Assert.AreEqual ("aBcabc", cb.QuoteIdentifier ("abc"), "#A4");
			cb.QuoteSuffix = "deF";
			Assert.AreEqual ("aBcmodEfnodeF", cb.QuoteIdentifier ("modEfno"), "#A5");
			Assert.AreEqual ("aBcdeF", cb.QuoteIdentifier (string.Empty), "#A6");
			Assert.AreEqual ("aBcZdeF", cb.QuoteIdentifier ("Z"), "#A7");
			Assert.AreEqual ("aBcabcdeF", cb.QuoteIdentifier ("abc"), "#A8");

			cb = new OdbcCommandBuilder ();
			cb.QuotePrefix = "X";
			Assert.AreEqual ("XmoXno", cb.QuoteIdentifier ("moXno"), "#B1");
			Assert.AreEqual ("X", cb.QuoteIdentifier (string.Empty), "#B2");
			Assert.AreEqual ("XZ", cb.QuoteIdentifier ("Z"), "#B3");
			Assert.AreEqual ("XX", cb.QuoteIdentifier ("X"), "#B4");
			cb.QuoteSuffix = " ";
			Assert.AreEqual ("Xmo  no ", cb.QuoteIdentifier ("mo no"), "#B5");
			Assert.AreEqual ("X ", cb.QuoteIdentifier (string.Empty), "#B6");
			Assert.AreEqual ("XZ ", cb.QuoteIdentifier ("Z"), "#B7");
			Assert.AreEqual ("X   ", cb.QuoteIdentifier (" "), "#B8");

			cb = new OdbcCommandBuilder ();
			cb.QuotePrefix = " ";
			Assert.AreEqual ("mono", cb.QuoteIdentifier ("mono"), "#C1");
			Assert.AreEqual (string.Empty, cb.QuoteIdentifier (string.Empty), "#C2");
			Assert.AreEqual ("Z", cb.QuoteIdentifier ("Z"), "#C3");
			cb.QuoteSuffix = "dEf";
			Assert.AreEqual ("modefno", cb.QuoteIdentifier ("modefno"), "#C4");
			Assert.AreEqual (string.Empty, cb.QuoteIdentifier (string.Empty), "#C5");
			Assert.AreEqual ("Z", cb.QuoteIdentifier ("Z"), "#C6");

			cb = new OdbcCommandBuilder ();
			cb.QuotePrefix = "  ";
			Assert.AreEqual ("  mono", cb.QuoteIdentifier ("mono"), "#D1");
			Assert.AreEqual ("  ", cb.QuoteIdentifier (string.Empty), "#D2");
			Assert.AreEqual ("  Z", cb.QuoteIdentifier ("Z"), "#D3");
			cb.QuoteSuffix = "dEf";
			Assert.AreEqual ("  moDeFnodEf", cb.QuoteIdentifier ("moDeFno"), "#D4");
			Assert.AreEqual ("  modEfdEfnodEf", cb.QuoteIdentifier ("modEfno"), "#D5");
			Assert.AreEqual ("  dEf", cb.QuoteIdentifier (string.Empty), "#D6");
			Assert.AreEqual ("  ZdEf", cb.QuoteIdentifier ("Z"), "#D7");
		}