예제 #1
0
파일: libodbc.cs 프로젝트: nlhepler/mono
		internal static extern OdbcReturn SQLGetConnectAttr (
			IntPtr ConnectionHandle,
			OdbcConnectionAttribute Attribute,
			out int value,
			int BufferLength,
			out int StringLength);
예제 #2
0
파일: libodbc.cs 프로젝트: nlhepler/mono
		internal static extern OdbcReturn SQLSetConnectAttr (
			IntPtr ConnectionHandle,
			OdbcConnectionAttribute Attribute,
			IntPtr Value,
			int Length);
예제 #3
0
 internal static extern OdbcReturn SQLGetConnectAttr(
     IntPtr ConnectionHandle,
     OdbcConnectionAttribute Attribute,
     out int value,
     int BufferLength,
     out int StringLength);
예제 #4
0
 internal static extern OdbcReturn SQLSetConnectAttr(
     IntPtr ConnectionHandle,
     OdbcConnectionAttribute Attribute,
     IntPtr Value,
     int Length);
예제 #5
0
 internal static extern OdbcReturnCode SQLSetConnectAttr(OdbcConnectionHandle connectionHandle, OdbcConnectionAttribute attribute, int value, int valueLengthShouldBeZero);
예제 #6
0
 internal static extern OdbcReturnCode SQLSetConnectAttrW(IntPtr connectionHandle, OdbcConnectionAttribute attribute, [In, MarshalAs(UnmanagedType.LPWStr)] string value, int stringLength);
예제 #7
0
 internal static extern OdbcReturnCode SQLGetConnectAttr(IntPtr connectionHandle, OdbcConnectionAttribute attribute, out int value, int valueLengthShouldBeZero, int valueLengthNeededShouldBeZero);
예제 #8
0
 internal static extern OdbcReturnCode SQLGetConnectAttrW(IntPtr connectionHandle, OdbcConnectionAttribute attribute, StringBuilder valueBuffer, int bufferLength, out int bufferLengthNeeded);
예제 #9
0
        internal static void SetStringConnectionAttribute(OdbcConnectionAttribute attribute, string value)
        {
            if (value == null) throw new ArgumentNullException("value");

            var result = NativeMethods.SQLSetConnectAttrW(Constants.IntPtrZero, attribute, value, value.Length * 2);

            if ((result != OdbcReturnCode.Success) && (result != OdbcReturnCode.SuccessWithInfo))
            {
                var ex = new Exception(string.Format("Unable to set ODBC connection attribute '{0:G}'.", attribute));

                throw ex;
            }
        }
예제 #10
0
        internal static void SetIntConnectionAttribute(OdbcConnectionHandle connectionHandle, OdbcConnectionAttribute attribute, int value)
        {
            if (connectionHandle == null) throw new ArgumentNullException("connectionHandle");

            var result = NativeMethods.SQLSetConnectAttr(connectionHandle, attribute, value, 0);

            if ((result != OdbcReturnCode.Success) && (result != OdbcReturnCode.SuccessWithInfo))
            {
                var ex = GetException(connectionHandle, string.Format("Unable to set ODBC connection attribute '{0:G}'.", attribute));

                throw ex;
            }
        }
예제 #11
0
        internal static void SetIntConnectionAttribute(OdbcConnectionAttribute attribute, int value)
        {
            var result = NativeMethods.SQLSetConnectAttr(Constants.IntPtrZero, attribute, value, 0);

            if ((result != OdbcReturnCode.Success) && (result != OdbcReturnCode.SuccessWithInfo))
            {
                var ex = new Exception(string.Format("Unable to set ODBC connection attribute '{0:G}'.", attribute));

                throw ex;
            }
        }
예제 #12
0
        internal static string GetStringConnectionAttribute(OdbcConnectionAttribute attribute)
        {
            int bufferLengthNeeded;
            var buffer = new StringBuilder(256);
            var result = NativeMethods.SQLGetConnectAttrW(Constants.IntPtrZero, attribute, buffer, buffer.Capacity * 2, out bufferLengthNeeded);

            if (result == OdbcReturnCode.SuccessWithInfo)
            {
                var neededCapacity = ((bufferLengthNeeded / 2) + 1);

                if (buffer.Capacity < neededCapacity)
                {
                    buffer.Capacity = neededCapacity;
                    result = NativeMethods.SQLGetConnectAttrW(Constants.IntPtrZero, attribute, buffer, buffer.Capacity * 2, out bufferLengthNeeded);
                }
            }

            if ((result != OdbcReturnCode.Success) && (result != OdbcReturnCode.SuccessWithInfo))
            {
                var ex = new Exception(string.Format("Unable to get ODBC connection attribute '{0:G}'.", attribute));

                throw ex;
            }

               return buffer.ToString();
        }
예제 #13
0
        internal OdbcTransaction(OdbcConnection conn, IsolationLevel isolationlevel)
        {
            // Set Auto-commit (102) to false
            SetAutoCommit(conn, false);
            // Handle isolation level
            OdbcIsolationLevel      lev  = OdbcIsolationLevel.ReadCommitted;
            OdbcConnectionAttribute attr = OdbcConnectionAttribute.TransactionIsolation;

            switch (isolationlevel)
            {
            case IsolationLevel.ReadUncommitted:
                lev = OdbcIsolationLevel.ReadUncommitted;
                break;

            case IsolationLevel.ReadCommitted:
                lev = OdbcIsolationLevel.ReadCommitted;
                break;

            case IsolationLevel.RepeatableRead:
                lev = OdbcIsolationLevel.RepeatableRead;
                break;

            case IsolationLevel.Serializable:
                lev = OdbcIsolationLevel.Serializable;
                break;

            case IsolationLevel.Snapshot:
                // badly broken on MS:
                // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=305736
                lev = OdbcIsolationLevel.Snapshot;

                // SQL_ATTR_TXN_ISOLATION can be used to set all other isolation
                // levels except for SQL_TXN_SS_SNAPSHOT. If you want to use snapshot
                // isolation, you must set SQL_TXN_SS_SNAPSHOT through
                // SQL_COPT_SS_TXN_ISOLATION. However, you can retrieve the
                // isolation level by using either SQL_ATTR_TXN_ISOLATION or
                // SQL_COPT_SS_TXN_ISOLATION.
                // Source:
                // http://msdn2.microsoft.com/en-us/library/ms131709.aspx
                attr = OdbcConnectionAttribute.CoptTransactionIsolation;
                break;

            case IsolationLevel.Unspecified:
                // when isolationlevel is not specified, then use
                // default isolation level of the driver and
                // lazy initialize it in the IsolationLevel property
                break;

            case IsolationLevel.Chaos:
                throw new ArgumentOutOfRangeException("IsolationLevel",
                                                      string.Format(CultureInfo.CurrentCulture,
                                                                    "The IsolationLevel enumeration " +
                                                                    "value, {0}, is not supported by " +
                                                                    "the .Net Framework Odbc Data " +
                                                                    "Provider.", (int)isolationlevel));

            default:
                throw new ArgumentOutOfRangeException("IsolationLevel",
                                                      string.Format(CultureInfo.CurrentCulture,
                                                                    "The IsolationLevel enumeration value, {0}, is invalid.",
                                                                    (int)isolationlevel));
            }

            // only change isolation level if it was explictly set
            if (isolationlevel != IsolationLevel.Unspecified)
            {
                // mbd: Getting the return code of the second call to SQLSetConnectAttr is missing from original code!
                OdbcReturn ret = libodbc.SQLSetConnectAttr(conn.hDbc,
                                                           attr, (IntPtr)lev, 0);
                if (ret != OdbcReturn.Success && ret != OdbcReturn.SuccessWithInfo)
                {
                    throw conn.CreateOdbcException(OdbcHandleType.Dbc, conn.hDbc);
                }
            }
            this.isolationlevel = isolationlevel;
            connection          = conn;
            isOpen = true;
        }