예제 #1
0
        public static void Test_GetDiagField()
        {
            StringBuilder sb_length   = new StringBuilder(64);
            StringBuilder sb_diagInfo = new StringBuilder(64);

            //env
            st_odbc_env odbc_env = new st_odbc_env();

            st_diag_record record = new st_diag_record();

            record.number      = 1;
            record.sql_state   = "IM";
            record.native_code = 1;
            MarshalManage mb_record = new MarshalManage(record);

            st_diag diag = new st_diag();

            diag.record = mb_record.buffer;

            MarshalManage mb_diag = new MarshalManage(diag);

            odbc_env.diag = mb_diag.buffer;

            //statement
            st_odbc_statement statement = new st_odbc_statement();

            statement.current_tpl_pos = 1;
            st_diag_record record_s = new st_diag_record();

            record_s.number      = 1;
            record_s.sql_state   = "IM";
            record_s.native_code = 1;
            MarshalManage mb_record_s = new MarshalManage(record_s);

            st_diag diag_s = new st_diag();

            diag_s.record     = mb_record_s.buffer;
            diag_s.rec_number = 1;
            diag_s.retcode    = 2;
            MarshalManage mb_diag_s = new MarshalManage(diag_s);

            statement.diag = mb_diag_s.buffer;

            int res = 0;

            //SQL_DIAG_ROW_COUNT 3
            res = SQLGetDiagField_s(1, ref statement, 1, 3, sb_diagInfo, 16, sb_length);
            Assert.IsTrue(res == -1);

            //SQL_DIAG_CURSOR_ROW_COUNT -1249
            res = SQLGetDiagField_s(1, ref statement, 1, -1249, sb_diagInfo, 16, sb_length);
            Assert.IsTrue(res == -1);

            //SQL_DIAG_NUMBER 2
            res = SQLGetDiagField_s(1, ref statement, 1, 1, sb_diagInfo, 16, sb_length);
            Assert.IsTrue(sb_diagInfo.ToString()[0] == 2);

            //SQL_DIAG_RETURNCODE 1
            res = SQLGetDiagField_s(1, ref statement, 1, 2, sb_diagInfo, 16, sb_length);
            Assert.IsTrue(sb_diagInfo.ToString()[0] == 1);

            //SQL_DIAG_CLASS_ORIGIN 8
            res = SQLGetDiagField_s(1, ref statement, 1, 8, sb_diagInfo, 0, sb_length);
            Assert.IsTrue(sb_diagInfo.ToString()[0] == 1);

            //SQL_DIAG_COLUMN_NUMBER -1247
            res = SQLGetDiagField_s(1, ref statement, 1, -1247, sb_diagInfo, 16, sb_length);
            Assert.IsTrue(sb_diagInfo.ToString()[0] == 63);

            //SQL_DIAG_CONNECTION_NAME 10
            res = SQLGetDiagField_s(1, ref statement, 1, 10, sb_diagInfo, 16, sb_length);
            Assert.IsTrue(res == 0);
            res = SQLGetDiagField_s(1, ref statement, 1, 10, sb_diagInfo, 0, sb_length);

            //SQL_DIAG_MESSAGE_TEXT 6
            res = SQLGetDiagField_s(1, ref statement, 1, 6, sb_diagInfo, 16, sb_length);
            Assert.IsTrue(sb_diagInfo.ToString()[0] == 91);
            res = SQLGetDiagField_s(1, ref statement, 1, 6, sb_diagInfo, 0, sb_length);

            //SQL_DIAG_NATIVE 5
            res = SQLGetDiagField_s(1, ref statement, 1, 5, sb_diagInfo, 16, sb_length);
            Assert.IsTrue(sb_diagInfo.ToString()[0] == 1);

            //SQL_DIAG_ROW_NUMBER -1248
            res = SQLGetDiagField_s(1, ref statement, 1, -1248, sb_diagInfo, 16, sb_length);
            Assert.IsTrue(sb_diagInfo.ToString()[0] == 63);

            //SQL_DIAG_SERVER_NAME 11
            res = SQLGetDiagField_s(1, ref statement, 1, 11, sb_diagInfo, 0, sb_length);
            Assert.IsTrue(sb_diagInfo.ToString()[0] == 63);
        }
        public static void Test_GetDiagField()
        {
            StringBuilder sb_length = new StringBuilder(64);
            StringBuilder sb_diagInfo = new StringBuilder(64);
            
            //env
            st_odbc_env odbc_env = new st_odbc_env();

            st_diag_record record = new st_diag_record();
            record.number = 1;
            record.sql_state = "IM";
            record.native_code = 1;
            MarshalManage mb_record = new MarshalManage(record);

            st_diag diag = new st_diag();
            diag.record = mb_record.buffer;

            MarshalManage mb_diag = new MarshalManage(diag);
            odbc_env.diag = mb_diag.buffer;

            //statement
            st_odbc_statement statement = new st_odbc_statement();
            statement.current_tpl_pos = 1;
            st_diag_record record_s = new st_diag_record();
            record_s.number = 1;
            record_s.sql_state = "IM";
            record_s.native_code = 1;
            MarshalManage mb_record_s = new MarshalManage(record_s);

            st_diag diag_s = new st_diag();
            diag_s.record = mb_record_s.buffer;
            diag_s.rec_number = 1;
            diag_s.retcode = 2;
            MarshalManage mb_diag_s = new MarshalManage(diag_s);
            statement.diag = mb_diag_s.buffer;

            int res=0;
            //SQL_DIAG_ROW_COUNT 3         
            res = SQLGetDiagField_s(1, ref statement, 1, 3, sb_diagInfo, 16, sb_length);
            Assert.IsTrue(res == -1);

            //SQL_DIAG_CURSOR_ROW_COUNT -1249
            res = SQLGetDiagField_s(1, ref statement, 1, -1249, sb_diagInfo, 16, sb_length);
            Assert.IsTrue(res == -1);

            //SQL_DIAG_NUMBER 2
            res = SQLGetDiagField_s(1, ref statement, 1, 1, sb_diagInfo, 16, sb_length);
            Assert.IsTrue(sb_diagInfo.ToString()[0] == 2);

            //SQL_DIAG_RETURNCODE 1
            res = SQLGetDiagField_s(1, ref statement, 1,2, sb_diagInfo, 16, sb_length);
            Assert.IsTrue(sb_diagInfo.ToString()[0] == 1);

            //SQL_DIAG_CLASS_ORIGIN 8
            res = SQLGetDiagField_s(1, ref statement, 1, 8, sb_diagInfo, 0, sb_length);
            Assert.IsTrue(sb_diagInfo.ToString()[0] == 1);

            //SQL_DIAG_COLUMN_NUMBER -1247
            res = SQLGetDiagField_s(1, ref statement, 1, -1247, sb_diagInfo, 16, sb_length);
            Assert.IsTrue(sb_diagInfo.ToString()[0] == 63);

            //SQL_DIAG_CONNECTION_NAME 10
            res = SQLGetDiagField_s(1, ref statement, 1, 10, sb_diagInfo, 16, sb_length);
            Assert.IsTrue(res == 0);
            res = SQLGetDiagField_s(1, ref statement, 1, 10, sb_diagInfo, 0, sb_length);

            //SQL_DIAG_MESSAGE_TEXT 6
            res = SQLGetDiagField_s(1, ref statement, 1, 6, sb_diagInfo, 16, sb_length);
            Assert.IsTrue(sb_diagInfo.ToString()[0] == 91);
            res = SQLGetDiagField_s(1, ref statement, 1, 6, sb_diagInfo, 0, sb_length);

            //SQL_DIAG_NATIVE 5
            res = SQLGetDiagField_s(1, ref statement, 1, 5, sb_diagInfo, 16, sb_length);
            Assert.IsTrue(sb_diagInfo.ToString()[0] == 1);

            //SQL_DIAG_ROW_NUMBER -1248
            res = SQLGetDiagField_s(1, ref statement, 1, -1248, sb_diagInfo, 16, sb_length);
            Assert.IsTrue(sb_diagInfo.ToString()[0] == 63);

            //SQL_DIAG_SERVER_NAME 11
            res = SQLGetDiagField_s(1, ref statement, 1, 11, sb_diagInfo, 0, sb_length);
            Assert.IsTrue(sb_diagInfo.ToString()[0] == 63);
        }