load(DrvConn conn) { MsgConn msg = conn.msg; bool isBlankDateNull = conn.isBlankDateNull; short count = msg.readShort(); AdvanRSMD rsmd = new AdvanRSMD(count, conn.trace); for (short col = 0; col < count; col++) { ProviderType sql_type = (ProviderType) msg.readShort(); short dbms_type = msg.readShort(); short length = msg.readShort(); byte precision = msg.readByte(); byte scale = msg.readByte(); byte flags = msg.readByte(); if (isBlankDateNull && sql_type == ProviderType.DateTime) { flags |= MSG_DSC_NULL; // return empty date as null } String name = msg.readString(); switch (sql_type) { case ProviderType.DateTime: if (dbms_type == 0) { dbms_type = DBMS_TYPE_IDATE; } break; case ProviderType.Interval: /* ** Intervals are not supported directly */ if (dbms_type == DBMS_TYPE_INTDS) { sql_type = ProviderType.IntervalDayToSecond; } else { sql_type = ProviderType.VarChar; } length = (short)((dbms_type == DBMS_TYPE_INTYM) ? 8 : 15); precision = scale = 0; break; } rsmd.desc[col].name = name; rsmd.desc[col].sql_type = sql_type; rsmd.desc[col].dbms_type = dbms_type; rsmd.desc[col].length = length; rsmd.desc[col].precision = precision; rsmd.desc[col].scale = scale; rsmd.desc[col].flags = flags; } return(rsmd); } // load
} // DrvObj /// <summary> /// Set the DrvConn server connection information. /// </summary> /// <param name="conn"></param> protected internal void set(DrvConn conn) { this.conn = conn; if (conn == null) { this.msg = null; this.trace = null; return; } this.msg = conn.msg; this.trace = conn.trace; }
reload(DrvConn conn) { MsgConn msg = conn.msg; bool isBlankDateNull = conn.isBlankDateNull; short new_count = msg.readShort(); short common = (short)System.Math.Min(new_count, count); if (new_count != count) { resize(new_count); } for (short col = 0; col < count; col++) { ProviderType sql_type = (ProviderType)msg.readShort(); short dbms_type = msg.readShort(); short length = msg.readShort(); byte precision = msg.readByte(); byte scale = msg.readByte(); byte flags = msg.readByte(); if (isBlankDateNull && sql_type == ProviderType.DateTime) { flags |= MSG_DSC_NULL; // return empty date as null } String name = msg.readString(); switch (sql_type) { case ProviderType.DateTime: if (dbms_type == 0) { dbms_type = DBMS_TYPE_IDATE; } break; case ProviderType.Interval: /* ** Intervals are not supported directly */ if (dbms_type == DBMS_TYPE_INTDS) { sql_type = ProviderType.IntervalDayToSecond; } else { sql_type = ProviderType.VarChar; } length = (short)((dbms_type == DBMS_TYPE_INTYM) ? 8 : 15); precision = scale = 0; break; } if (col < common && trace.enabled(5)) { if (sql_type != desc[col].sql_type) { trace.write(tr_id + ": reload[" + col + "] sql_type " + desc[col].sql_type + " => " + sql_type); } if (dbms_type != desc[col].dbms_type) { trace.write(tr_id + ": reload[" + col + "] dbms_type " + desc[col].dbms_type + " => " + dbms_type); } if (length != desc[col].length) { trace.write(tr_id + ": reload[" + col + "] length " + desc[col].length + " => " + length); } if (precision != desc[col].precision) { trace.write(tr_id + ": reload[" + col + "] precision " + desc[col].precision + " => " + precision); } if (scale != desc[col].scale) { trace.write(tr_id + ": reload[" + col + "] scale " + desc[col].scale + " => " + scale); } if (flags != desc[col].flags) { trace.write(tr_id + ": reload[" + col + "] flags " + desc[col].flags + " => " + flags); } } desc[col].name = name; desc[col].sql_type = sql_type; desc[col].dbms_type = dbms_type; desc[col].length = length; desc[col].precision = precision; desc[col].scale = scale; desc[col].flags = flags; } return; }
/* ** Name: connect ** ** Description: ** Establish a connection to the Data Access Server. If requested, ** the connection will enable the management of distributed ** transactions. ** ** Input: ** charset Character set/encoding for connection.. ** dtmc Distributed Transaction Management Connection? ** ** Output: ** None. ** ** Returns: ** void. ** ** History: ** 28-Mar-01 (gordy) ** Extracted from Driver. ** 18-Apr-01 (gordy) ** Added support for Distributed Transaction Management Connections. ** 31-Oct-02 (gordy) ** Adapted for generic GCF driver. ** 20-Dec-02 (gordy) ** Added charset parameter for connection character encoding. ** Inform messaging system of the negotiated protocol level. ** 6-jul-04 (gordy; ported by thoda04) ** Negotiate session mask. ** 1-Mar-07 (gordy, ported by thoda04) ** Dropped char_set parameter, don't default CharSet. */ private void connect( bool dtmc ) { byte[] msg_cp; int len; bool mask_received = false; /* ** Build DAM-ML protocol initialization parameters. */ len = 3; // Protocol len += (2 + session_mask.Length); // Session mask if ( dtmc ) len += 2; // DTMC msg_cp = new byte[ len ]; len = 0; msg_cp[len++] = MSG_P_PROTO; // Protocol msg_cp[len++] = (byte)1; msg_cp[len++] = MSG_PROTO_DFLT; msg_cp[len++] = MSG_P_MASK; // Session mask msg_cp[len++] = (byte)session_mask.Length; for( int i = 0; i < session_mask.Length; i++ ) msg_cp[len++] = session_mask[ i ]; if ( dtmc ) // DTMC { msg_cp[len++] = MSG_P_DTMC; msg_cp[len++] = (byte)0; } /* ** Establish a connection with the server. */ if ( trace.enabled( 2 ) ) trace.write( tr_id + ": Connecting to server: " + host ); msg = new MsgConn( host, ref msg_cp ); tr_id += "[" + msg.ConnID + "]"; // Add instance ID /* ** Process the DAM-ML protocol initialization result paramters */ try { for( int i = 0; i < msg_cp.Length - 1; ) { byte param_id = msg_cp[ i++ ]; byte param_len = msg_cp[ i++ ]; switch( param_id ) { case MSG_P_PROTO : if ( param_len != 1 || i >= msg_cp.Length ) { if ( trace.enabled( 1 ) ) trace.write( tr_id + ": Invalid PROTO param length: " + param_len + "," + (msg_cp.Length - i) ); throw SqlEx.get( ERR_GC4002_PROTOCOL_ERR ); } msg_protocol_level = msg_cp[ i++ ]; msg.ML_ProtocolLevel = msg_protocol_level; break; case MSG_P_DTMC : if ( param_len != 0 ) { if ( trace.enabled( 1 ) ) trace.write( tr_id + ": Invalid DTMC param length: " + param_len ); throw SqlEx.get( ERR_GC4002_PROTOCOL_ERR ); } is_dtmc = true; break; case MSG_P_MASK : /* ** Server must respond with matching mask ** or not at all. */ if ( param_len != session_mask.Length ) { if ( trace.enabled( 1 ) ) trace.write( tr_id + ": Invalid mask param length: " + param_len ); throw SqlEx.get( ERR_GC4002_PROTOCOL_ERR ); } /* ** Combine server session mask with ours. */ for( int j = 0; j < session_mask.Length; j++, i++ ) session_mask[ j ] ^= msg_cp[ i ]; mask_received = true; break; default : if ( trace.enabled( 1 ) ) trace.write(tr_id + ": Invalid param ID: " + param_id); throw SqlEx.get( ERR_GC4002_PROTOCOL_ERR ); } } /* ** Validate protocol. */ if (msg_protocol_level < MSG_PROTO_1 || msg_protocol_level > MSG_PROTO_DFLT ) { if ( trace.enabled( 1 ) ) trace.write( tr_id + ": Invalid MSG protocol: " + msg_protocol_level ); throw SqlEx.get( ERR_GC4002_PROTOCOL_ERR ); } /* ** Validate session mask. */ if ( ! mask_received ) session_mask = null; /* ** Validate DTMC environment. */ if ( is_dtmc ) { if ( ! dtmc ) // Should not happen. { if ( trace.enabled( 1 ) ) trace.write(tr_id + ": DTM connection not requested!"); throw SqlEx.get( ERR_GC4001_CONNECT_ERR ); } if ( msg_protocol_level < MSG_PROTO_2 ) { if ( trace.enabled( 1 ) ) trace.write( tr_id + ": 2PC not supported" ); throw SqlEx.get( ERR_GC4019_UNSUPPORTED ); } /* ** Autocommit is disabled for DTM connections. */ autoCommit = false; } else if ( dtmc ) { if ( trace.enabled( 1 ) ) trace.write(tr_id+": Could not establish DTM connection!"); throw SqlEx.get( ERR_GC4019_UNSUPPORTED ); } } catch( SqlEx ex ) { msg.close(); throw ex; } if ( trace.enabled( 2 ) ) { trace.write( tr_id + ": connected to server" ); if ( trace.enabled( 3 ) ) { trace.write( tr_id + ": messaging protocol initialized:" ); trace.write( " MSG protocol: " + msg_protocol_level ); if ( is_dtmc ) trace.write( " DTM Connection" ); if ( session_mask != null ) trace.write( " Session mask: " + session_mask.Length + " bytes" ); } } return; }
connect(bool dtmc) { byte[] msg_cp; int len; bool mask_received = false; /* ** Build DAM-ML protocol initialization parameters. */ len = 3; // Protocol len += (2 + session_mask.Length); // Session mask if (dtmc) { len += 2; // DTMC } msg_cp = new byte[len]; len = 0; msg_cp[len++] = MSG_P_PROTO; // Protocol msg_cp[len++] = (byte)1; msg_cp[len++] = MSG_PROTO_DFLT; msg_cp[len++] = MSG_P_MASK; // Session mask msg_cp[len++] = (byte)session_mask.Length; for (int i = 0; i < session_mask.Length; i++) { msg_cp[len++] = session_mask[i]; } if (dtmc) // DTMC { msg_cp[len++] = MSG_P_DTMC; msg_cp[len++] = (byte)0; } /* ** Establish a connection with the server. */ if (trace.enabled(2)) { trace.write(tr_id + ": Connecting to server: " + host); } msg = new MsgConn(host, ref msg_cp); tr_id += "[" + msg.ConnID + "]"; // Add instance ID /* ** Process the DAM-ML protocol initialization result paramters */ try { for (int i = 0; i < msg_cp.Length - 1;) { byte param_id = msg_cp[i++]; byte param_len = msg_cp[i++]; switch (param_id) { case MSG_P_PROTO: if (param_len != 1 || i >= msg_cp.Length) { if (trace.enabled(1)) { trace.write(tr_id + ": Invalid PROTO param length: " + param_len + "," + (msg_cp.Length - i)); } throw SqlEx.get(ERR_GC4002_PROTOCOL_ERR); } msg_protocol_level = msg_cp[i++]; msg.ML_ProtocolLevel = msg_protocol_level; break; case MSG_P_DTMC: if (param_len != 0) { if (trace.enabled(1)) { trace.write(tr_id + ": Invalid DTMC param length: " + param_len); } throw SqlEx.get(ERR_GC4002_PROTOCOL_ERR); } is_dtmc = true; break; case MSG_P_MASK: /* ** Server must respond with matching mask ** or not at all. */ if (param_len != session_mask.Length) { if (trace.enabled(1)) { trace.write(tr_id + ": Invalid mask param length: " + param_len); } throw SqlEx.get(ERR_GC4002_PROTOCOL_ERR); } /* ** Combine server session mask with ours. */ for (int j = 0; j < session_mask.Length; j++, i++) { session_mask[j] ^= msg_cp[i]; } mask_received = true; break; default: if (trace.enabled(1)) { trace.write(tr_id + ": Invalid param ID: " + param_id); } throw SqlEx.get(ERR_GC4002_PROTOCOL_ERR); } } /* ** Validate protocol. */ if (msg_protocol_level < MSG_PROTO_1 || msg_protocol_level > MSG_PROTO_DFLT) { if (trace.enabled(1)) { trace.write(tr_id + ": Invalid MSG protocol: " + msg_protocol_level); } throw SqlEx.get(ERR_GC4002_PROTOCOL_ERR); } /* ** Validate session mask. */ if (!mask_received) { session_mask = null; } /* ** Validate DTMC environment. */ if (is_dtmc) { if (!dtmc) // Should not happen. { if (trace.enabled(1)) { trace.write(tr_id + ": DTM connection not requested!"); } throw SqlEx.get(ERR_GC4001_CONNECT_ERR); } if (msg_protocol_level < MSG_PROTO_2) { if (trace.enabled(1)) { trace.write(tr_id + ": 2PC not supported"); } throw SqlEx.get(ERR_GC4019_UNSUPPORTED); } /* ** Autocommit is disabled for DTM connections. */ autoCommit = false; } else if (dtmc) { if (trace.enabled(1)) { trace.write(tr_id + ": Could not establish DTM connection!"); } throw SqlEx.get(ERR_GC4019_UNSUPPORTED); } } catch (SqlEx ex) { msg.close(); throw ex; } if (trace.enabled(2)) { trace.write(tr_id + ": connected to server"); if (trace.enabled(3)) { trace.write(tr_id + ": messaging protocol initialized:"); trace.write(" MSG protocol: " + msg_protocol_level); if (is_dtmc) { trace.write(" DTM Connection"); } if (session_mask != null) { trace.write(" Session mask: " + session_mask.Length + " bytes"); } } } return; } // connect