public override void SetTimeout(IGxConnectionManager connManager, IGxConnection connection, int handle)
        {
            GXLogging.Debug(log, "Set Lock Timeout to " + m_lockTimeout / 1000);
            IDbCommand cmd = GetCommand(connection, SetTimeoutSentence(m_lockTimeout), new GxParameterCollection());

            cmd.ExecuteNonQuery();
        }
        public override IDataReader GetDataReader(
            IGxConnectionManager connManager,
            IGxConnection con,
            GxParameterCollection parameters,
            string stmt, ushort fetchSize,
            bool forFirst, int handle,
            bool cached, SlidingTime expiration,
            bool hasNested,
            bool dynStmt)
        {
            IDataReader idatareader;

            if (NpgsqlAssembly.GetName().Version.Major == 1)
            {
                GXLogging.Debug(log, "ExecuteReader: client cursor=" + hasNested + ", handle '" + handle + "'" + ", hashcode " + this.GetHashCode());
                idatareader = new GxDataReader(connManager, this, con, parameters, stmt, fetchSize, forFirst, handle, cached, expiration, dynStmt);
            }
            else
            {
                if (!hasNested)                //Client Cursor
                {
                    GXLogging.Debug(log, "ExecuteReader: client cursor=" + hasNested + ", handle '" + handle + "'" + ", hashcode " + this.GetHashCode());
                    idatareader = new GxDataReader(connManager, this, con, parameters, stmt, fetchSize, forFirst, handle, cached, expiration, dynStmt);
                }
                else                 //Server Cursor
                {
                    GXLogging.Debug(log, "ExecuteReader: server cursor=" + hasNested + ", handle '" + handle + "'" + ", hashcode " + this.GetHashCode());
                    idatareader = new GxPostgresqlMemoryDataReader(connManager, this, con, parameters, stmt, fetchSize, forFirst, handle, cached, expiration, dynStmt);
                }
            }
            return(idatareader);
        }
Exemple #3
0
        public GxMySQLDataReader(IGxConnectionManager connManager, GxDataRecord dr, IGxConnection connection, GxParameterCollection parameters,
                                 string stmt, int fetchSize, bool forFirst, int handle, bool cached, SlidingTime expiration, bool dynStmt, bool preparedStmts)
        {
            this.parameters = parameters;
            this.stmt       = stmt;
            this.fetchSize  = fetchSize;
            this.cache      = connection.ConnectionCache;
            this.cached     = cached;
            this.handle     = handle;
            this.isForFirst = forFirst;
            _connManager    = connManager;
            this.m_dr       = dr;
            this.readBytes  = 0;
            this.dynStmt    = dynStmt;
            con             = _connManager.IncOpenHandles(handle, m_dr.DataSource);
            con.CurrentStmt = stmt;
            con.MonitorEnter();
            MySQLCommand cmd = (MySQLCommand)dr.GetCommand(con, stmt, parameters);

#if !NETCORE
            cmd.UsePreparedStatement = preparedStmts;
#endif
            reader = cmd.ExecuteReader();
            cache.SetAvailableCommand(stmt, false, dynStmt);
            open  = true;
            block = new GxArrayList(fetchSize);
            pos   = -1;
            if (cached)
            {
                key             = SqlUtil.GetKeyStmtValues(parameters, stmt, isForFirst);
                this.expiration = expiration;
            }
        }
        public override IDbCommand GetCommand(IGxConnection con, string stmt, GxParameterCollection parameters)
        {
            IDbCommand      cmd  = base.GetCommand(con, stmt, parameters);
            IServiceCommand iCmd = cmd as IServiceCommand;

            if (iCmd != null)
            {
                iCmd.CursorDef = m_CursorDef;
            }
            return(cmd);
        }
Exemple #5
0
        public void EndExecute(ICursor cursor, IGxConnection con)
        {
            if (con != null)
            {
                con.LastSQLStatementEnded = true;
            }

            DataStoreProviderInfo dsInfo = WMIDataStoreProviders.Instance().GetDataStoreProviderInfo(this.name);
            SentenceInfo          sInfo  = dsInfo.GetSentenceInfo(this.name + "_" + cursor.Id);
            long diff = DateTime.Now.Subtract(beginExecute).Ticks / TimeSpan.TicksPerMillisecond;

            sInfo.setTimeExecute(diff);
        }
Exemple #6
0
 public void BeginExecute(ICursor cursor, IGxConnection con)
 {
     if (con != null)
     {
         con.LastObject            = this.name;
         con.LastSQLStatementEnded = false;
         ServerUserInformation sui = (ServerUserInformation)GxConnectionManager.Instance.GetUserInformation(con.DataStore.Handle, con.DataStore.Id);
         if (sui != null)
         {
             sui.LastSQLStatement     = cursor.SQLStatement;
             sui.LastSQLStatementTime = DateTime.Now.ToString();
         }
     }
 }
Exemple #7
0
        public override IDbCommand GetCommand(IGxConnection con, string stmt, GxParameterCollection parameters, bool isCursor, bool forFirst, bool isRpc)
        {
            if (isRpc)
            {
                stmt = convertToMySqlCall(stmt, parameters);
            }
            MySQLCommand mysqlcmd = (MySQLCommand)base.GetCommand(con, stmt, parameters.Distinct());

            if (isCursor && !isRpc)
            {
                mysqlcmd.Prepare();
            }
            return(mysqlcmd);
        }
 public override string GetServerDateTimeStmt(IGxConnection connection)
 {
     if (string.IsNullOrEmpty(connection.DSVersion))             //>= 8.1
     {
         return("SELECT clock_timestamp()");
     }
     //clock_timestamp()	timestamp with time zone. Current date and time (changes during statement execution);
     else
     {
         return("SELECT CAST(timeofday() AS timestamp)");
     }
     //timeofday()	text	Current date and time (like clock_timestamp, but as a text string);
     //SELECT CURRENT_TIMESTAMP=> timestamp with time zone. Current date and time (start of current transaction); see Section 9.9.4
 }
        public override IDataReader GetDataReader(
            IGxConnectionManager connManager,
            IGxConnection con,
            GxParameterCollection parameters,
            string stmt, ushort fetchSize,
            bool forFirst, int handle,
            bool cached, SlidingTime expiration,
            bool hasNested,
            bool dynStmt)
        {
            IDataReader idatareader;

            idatareader = new GxDataReader(connManager, this, con, parameters, stmt, fetchSize, forFirst, handle, cached, expiration, dynStmt);
            return(idatareader);
        }
        public override IDataReader GetDataReader(
            IGxConnectionManager connManager,
            IGxConnection con,
            GxParameterCollection parameters,
            string stmt, ushort fetchSize,
            bool forFirst, int handle,
            bool cached, SlidingTime expiration,
            bool hasNested,
            bool dynStmt)
        {
            IDataReader idatareader;

            GXLogging.Debug(log, "ExecuteReader: client cursor=", () => hasNested + ", handle '" + handle + "'" + ", hashcode " + this.GetHashCode());
            idatareader = new GxDataReader(connManager, this, con, parameters, stmt, fetchSize, forFirst, handle, cached, expiration, dynStmt);
            return(idatareader);
        }
Exemple #11
0
        public override IDbCommand GetCommand(IGxConnection con, string stmt, GxParameterCollection parameters, bool isCursor, bool forFirst, bool isRpc)
        {
            if (isRpc)
            {
                stmt = convertToMySqlCall(stmt, parameters);
            }
            MySQLCommand mysqlcmd = (MySQLCommand)base.GetCommand(con, stmt, parameters);

            if (preparedStmts && isCursor && !isRpc)
            {
#if !NETCORE
                mysqlcmd.UsePreparedStatement = true;
#endif
                mysqlcmd.Prepare();
            }
            return(mysqlcmd);
        }
        public MemoryDataReader(IDataReader reader, IGxConnection connection, GxParameterCollection parameters,
                                string stmt, ushort fetchSize, bool isForFirst, bool withCached, SlidingTime expiration)
            : this()
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }
            if (reader.IsClosed)
            {
                throw new ArgumentException("Reader is closed");
            }

            DataTable schemaTab = reader.GetSchemaTable();

            if (schemaTab != null)
            {
                this._schemaDataTable = schemaTab.Clone();
            }


            string[] colnames = null;

            while (reader.Read())
            {
                if (colnames == null)
                {
                    colnames = new string[reader.FieldCount];
                    for (int fi = 0; fi < colnames.Length; fi++)
                    {
                        colnames[fi] = reader.GetName(fi);
                    }
                }

                this.AddRecord(reader, colnames);
            }
            this.cached = withCached;
            this.con    = connection;
            block       = new GxArrayList(fetchSize);
            if (cached)
            {
                this.key        = SqlUtil.GetKeyStmtValues(parameters, stmt, isForFirst);
                this.expiration = expiration;
            }
        }
Exemple #13
0
        public override IDataReader GetDataReader(
            IGxConnectionManager connManager,
            IGxConnection con,
            GxParameterCollection parameters,
            string stmt, ushort fetchSize,
            bool forFirst, int handle,
            bool cached, SlidingTime expiration,
            bool hasNested,
            bool dynStmt)
        {
            IDataReader idatareader;

#if !NETCORE
            GXLogging.Debug(log, "ExecuteReader: client cursor=" + hasNested + ", handle '" + handle + "'" + ", hashcode " + this.GetHashCode() + " PreparedStmt " + preparedStmts);
            if (preparedStmts)
            {
                idatareader = new GxMySQLCursorDataReader(connManager, this, con, parameters, stmt, fetchSize, forFirst, handle, cached, expiration, hasNested, dynStmt);
            }
            else
            {
                idatareader = new GxMySQLDataReader(connManager, this, con, parameters, stmt, fetchSize, forFirst, handle, cached, expiration, dynStmt, preparedStmts);
            }
#else
            if (!hasNested)//Client Cursor
            {
                GXLogging.Debug(log, "ExecuteReader: client cursor=" + hasNested + ", handle '" + handle + "'" + ", hashcode " + this.GetHashCode() + " PreparedStmt " + preparedStmts);
                if (preparedStmts)
                {
                    idatareader = new GxMySQLCursorDataReader(connManager, this, con, parameters, stmt, fetchSize, forFirst, handle, cached, expiration, hasNested, dynStmt);
                }
                else
                {
                    idatareader = new GxMySQLDataReader(connManager, this, con, parameters, stmt, fetchSize, forFirst, handle, cached, expiration, dynStmt, preparedStmts);
                }
            }
            else //Server Cursor
            {
                GXLogging.Debug(log, "ExecuteReader: server cursor=" + hasNested + ", handle '" + handle + "'" + ", hashcode " + this.GetHashCode());
                idatareader = new GxMySqlMemoryDataReader(connManager, this, con, parameters, stmt, fetchSize, forFirst, handle, cached, expiration, dynStmt);
            }
#endif
            return(idatareader);
        }
        public override bool ProcessError(int dbmsErrorCode, string emsg, GxErrorMask errMask, IGxConnection con, ref int status, ref bool retry, int retryCount)

        {
            GXLogging.Debug(log, "ProcessError: dbmsErrorCode=" + dbmsErrorCode + ", emsg '" + emsg + "'");
            if (emsg.IndexOf("42p01", StringComparison.OrdinalIgnoreCase) != -1)
            {
                if ((emsg.IndexOf(" vista ") != -1 || emsg.IndexOf(" view ") != -1) || (emsg.IndexOf(" tabla ") != -1 || emsg.IndexOf(" table ") != -1))
                {
                    //42p01 messages for views and tables are not captured
                    //dbmsErrorCode=5632, emsg 'error: 42p01: no existe la vista xxxx
                    //dbmsErrorCode=5632, error: 42p01: no existe la tabla â«ivafechafacturaâ»
                    return(false);
                }
            }

            if (                //duplicate key violates unique constraint //ERRO: 23505: duplicar chave viola a restrição de unicidade "nfe010_pkey"
                emsg.IndexOf("23505") != -1 ||
                (emsg.IndexOf("duplicate key") != -1 && emsg.IndexOf("unique") != -1) ||
                (emsg.IndexOf("duplicar chave") != -1 && emsg.IndexOf("unicidade") != -1)
                )
            {
                status = 1;                 // Duplicate key
                return(true);
            }
            else if
            (
                (emsg.IndexOf("42704") != -1)                         //42704 index "xxx" does not exist
                ||
                (emsg.IndexOf("42p01") != -1)                         //42P01	relation tableName does not exist //42P01: relação "nuc011" não existe
                ||
                (emsg.IndexOf("42P01") != -1)                         //42P01	relation tableName does not exist
                ||
                ((emsg.IndexOf("table") != -1 || emsg.IndexOf("relation") != -1 || emsg.IndexOf("sequence") != -1) && emsg.IndexOf("does not exist") != -1)
                ||
                (emsg.IndexOf("index") != -1 && (emsg.IndexOf("nonexistent") != -1 || emsg.IndexOf("does not exist") != -1))
                ||
                ((emsg.IndexOf("seqüência") != -1 || emsg.IndexOf("ã­ndice") != -1) && (emsg.IndexOf("nã£o existe") != -1))                        //ERRO: 42704: índice "iu_inuc002" não existe
            )
            {
                status = 105;
                return(true);
            }
            if (dbmsErrorCode == 16389 && emsg.IndexOf("42p06") >= 0)             //42p06: ya existe el esquema
            {
                return(true);
            }
            if (dbmsErrorCode == 5632 && emsg.IndexOf("42p06") >= 0)             //42p06: ya existe el esquema
            {
                return(true);
            }

            switch ((int)dbmsErrorCode)
            {
            case 100:
                status = 101;
                break;

            default:
                status = 999;
                return(false);
            }
            return(true);
        }
 public GxInformixDataReader(IGxConnectionManager connManager, GxDataRecord dr, IGxConnection connection, GxParameterCollection parameters,
                             string stmt, int fetchSize, bool forFirst, int handle, bool cached, SlidingTime expiration, bool dynStmt)
     : base(connManager, dr, connection, parameters, stmt, fetchSize, forFirst, handle, cached, expiration, dynStmt)
 {
 }
        public override bool ProcessError(int dbmsErrorCode, string emsg, GxErrorMask errMask, IGxConnection con, ref int status, ref bool retry, int retryCount)

        {
            switch (dbmsErrorCode)
            {
            case -243:                          // Locked
            case -244:                          // Locked
            case -245:                          // Locked
                retry = Retry(errMask, retryCount);
                if (retry)
                {
                    status = 110;                            // Locked - Retry
                }
                else
                {
                    status = 103;                            //Locked
                }
                return(retry);

            case -239:                          // Duplicated record
            case -268:                          // Duplicated record
            case -346:                          // Duplicated record
                status = 1;
                break;

            case -203:                          // File not found
            case -206:                          // File not found
            case -319:                          // File not found
            case -623:                          // File not found
                status = 105;
                break;

            case 50:                            // table or view does not exist
                if (!GxContext.isReorganization)
                {
                    status = 999;
                    return(false);
                }
                else
                {
                    status = 105;
                }
                break;

            case -691:                          // Parent key not found
                if ((errMask & GxErrorMask.GX_MASKFOREIGNKEY) == 0)
                {
                    status = 500;                                   // ForeignKeyError
                    return(false);
                }
                else
                {
                    status = 0;                                 // NoError
                }
                break;

            default:
                GXLogging.Warn(log, "ProcessError dbmsErrorCode:'" + dbmsErrorCode + "'" + emsg);
                status = 999;
                return(false);
            }
            return(true);
        }
 public override string GetServerDateTimeStmtMs(IGxConnection connection)
 {
     return("SELECT NOW(3)");
 }
 public override string GetServerDateTimeStmtMs(IGxConnection connection)
 {
     return("SELECT CURRENT YEAR TO FRACTION(3) FROM informix.SYSTABLES WHERE tabname = 'systables'");
 }
 public override string GetServerDateTimeStmt(IGxConnection connection)
 {
     throw new NotImplementedException();
 }
        public override bool ProcessError(int dbmsErrorCode, string emsg, GxErrorMask errMask, IGxConnection con, ref int status, ref bool retry, int retryCount)
        {
            switch (emsg)
            {
            case ServiceError.RecordNotFound:
            {
                status = Cursor.EOF;
                retry  = false;
                return(true);
            }

            case ServiceError.RecordAlreadyExists:
            {
                status = 1;
                retry  = false;
                return(true);
            }

            default:
            {
                if (con?.InternalConnection?.InternalConnection.GetType().Name == "FabricConnection")
                {
                    status = 1;
                    retry  = false;
                    return(true);
                }
                else
                {
                    // SAP
                    int idx = emsg.IndexOf("<code>SY/530</code>");
                    if (idx > 0 &&
                        (emsg.IndexOf("not found.</message>", idx) > 0 ||
                         emsg.IndexOf("missing.</message>", idx) > 0
                        ))
                    {                                     // in SAP an error is returned when record is not found
                        status = Cursor.EOF;
                        retry  = false;
                        return(true);
                    }
                }
                break;
            }
            }
            return(false);
        }
        public override bool ProcessError(int dbmsErrorCode, string emsg, GxErrorMask errMask, IGxConnection con, ref int status, ref bool retry, int retryCount)
        {
            GXLogging.Debug(log, "ProcessError: dbmsErrorCode=" + dbmsErrorCode + ", emsg '" + emsg + "'");
            switch (dbmsErrorCode)
            {
            case 2006:                                              //MySQL server has gone away
                if (con != null && m_FailedConnections < MAX_TRIES) //Retry if it is an Open operation.
                {
                    try
                    {
                        if (con.Opened)
                        {
                            con.Close();
                        }
                    }
                    catch { }
                    status = 104;                             // MySQL server has gone away.  Check your network documentation - Retry [Max Pool Size] times.
                    m_FailedConnections++;
                    con.Close();
                    retry = true;
                    GXLogging.Debug(log, "ProcessError: MySQL server has gone away, FailedConnections:" + m_FailedConnections);
                }
                else
                {
                    return(false);
                }
                break;

            case 1006:                     //Can't create database 'databaseName'
            case 1007:                     //Can't create database 'databaseName'. Database exists
                break;

            case 1205:                          // Locked
                retry = Retry(errMask, retryCount);
                if (retry)
                {
                    status = 110;                            // Locked - Retry
                }
                else
                {
                    status = 103;                            //Locked
                }
                return(retry);

            case 1062:                          // Duplicated record ER_DUP_ENTRY
                status = 1;
                break;

            case 1051:                          // File not found ER_BAD_TABLE_ERROR
            case 1091:                          // File not found ER_CANT_DROP_FIELD_OR_KEY
            //case 1146:		// File not found ER_NO_SUCH_TABLE  => Do not catch it, it must be caught by the Reorganization
            //case 1064:		// File not found ER_PARSE_ERROR => Do not catch it, it is thrown when there is a sintax error
            case 1025:                          // (Error on rename of) ER_CANT_DROP_FKEY
                status = 105;
                break;

            case 1146:
                if (!GxContext.isReorganization)
                {
                    status = 105;
                    return(false);
                }
                else
                {
                    status = 999;
                    return(false);
                }

            case 1216:                          //foreign key constraint fails
                if ((errMask & GxErrorMask.GX_MASKFOREIGNKEY) == 0)
                {
                    status = 500;                                   // ForeignKeyError
                    return(false);
                }
                break;

            default:
                status = 999;
                return(false);
            }
            return(true);
        }
        public GxMySQLDriverCSCursorDataReader(IGxConnectionManager connManager, GxDataRecord dr, IGxConnection connection, GxParameterCollection parameters,
                                               string stmt, int fetchSize, bool forFirst, int handle, bool cached, SlidingTime expiration, bool hasNested, bool dynStmt)
        {
            this.parameters = parameters;
            this.stmt       = stmt;
            this.fetchSize  = fetchSize;
            this.cache      = connection.ConnectionCache;
            this.cached     = cached;
            this.handle     = handle;
            this.isForFirst = forFirst;
            _connManager    = connManager;
            this.m_dr       = dr;
            this.readBytes  = 0;
            this.dynStmt    = dynStmt;
            con             = _connManager.IncOpenHandles(handle, m_dr.DataSource);
            con.CurrentStmt = stmt;
            con.MonitorEnter();
            GXLogging.Debug(log, "Open GxMySQLCursorDataReader handle:'" + handle);
            MySQLCommand cmd = (MySQLCommand)dr.GetCommand(con, stmt, parameters);

            cmd.ServerCursor = hasNested;
            cmd.FetchSize    = (uint)fetchSize;
            reader           = cmd.ExecuteReader();
            cache.SetAvailableCommand(stmt, false, dynStmt);
            open  = true;
            block = new GxArrayList(fetchSize);
            pos   = -1;
            if (cached)
            {
                key             = SqlUtil.GetKeyStmtValues(parameters, stmt, isForFirst);
                this.expiration = expiration;
            }
        }
        public override bool ProcessError(int dbmsErrorCode, string emsg, GxErrorMask errMask, IGxConnection con, ref int status, ref bool retry, int retryCount)

        {
            GXLogging.Debug(log, "ProcessError: dbmsErrorCode=" + dbmsErrorCode + ", emsg '" + emsg + "'");
            switch (dbmsErrorCode)
            {
            case 11:
                if (con != null && m_FailedConnections < MAX_TRIES)
                {
                    status = 104;                             // General network error.  Check your network documentation - Retry [Max Pool Size] times.
                    m_FailedConnections++;
                    con.Close();
                    retry = true;
                    GXLogging.Debug(log, "ProcessError: General network error, FailedConnections:" + m_FailedConnections);
                }
                else
                {
                    return(false);
                }
                break;

            case 903:                           // Locked
                retry = Retry(errMask, retryCount);
                if (retry)
                {
                    status = 110;                            // Locked - Retry
                }
                else
                {
                    status = 103;                            //Locked
                }
                return(retry);

            case 2601:                          // Duplicated record
            case 2627:                          // Duplicated record
            case 25016:                         //A duplicate value cannot be inserted into a unique index
                status = 1;
                break;

            case 3639:                          //sql ce specific
            //case 3631:		//sql ce specific The column cannot contain null values No deberia capturarse.
            case 3637:                          //"The specified index does not exist"
            case 3723:                          //sql ce specific The reference does not exist
            case 3638:                          //"The specified index was in use"
            //case 3647:	//"The specified table already exists" => Do not catch it, it must be caught by the Reorganization
            case 25060:                         //The reference does not exist (DROP de una constraint que no existe)
            case 3701:                          // File not found
            case 3703:                          // File not found
            case 3704:                          // File not found
            case 3731:                          // File not found
            case 4902:                          // File not found
            case 3727:                          // File not found
            case 3728:                          // File not found
                status = 105;
                break;

            case 503:                           // Parent key not found
            case 547:                           //conflicted with COLUMN FOREIGN KEY constraint
                if ((errMask & GxErrorMask.GX_MASKFOREIGNKEY) > 0)
                {
                    status = 500;                                   // ForeignKeyError
                }
                break;

            default:
                return(false);
            }
            return(true);
        }
 public override string GetServerDateTimeStmtMs(IGxConnection connection)
 {
     return(GetServerDateTimeStmt(connection));
 }
 public override string GetServerDateTimeStmt(IGxConnection connection)
 {
     return("SELECT date('now')");
 }
        public GxPostgresqlMemoryDataReader(IGxConnectionManager connManager, GxDataRecord dr, IGxConnection connection, GxParameterCollection parameters,
                                            string stmt, ushort fetchSize, bool forFirst, int handle, bool cached, SlidingTime expiration, bool dynStmt) : base(connManager, dr, connection, parameters,
                                                                                                                                                                stmt, fetchSize, forFirst, handle, cached, expiration, dynStmt)
        {
            MemoryDataReader memoryDataReader = new MemoryDataReader(reader, connection, parameters, stmt, fetchSize, forFirst, cached, expiration);

            Close();
            reader = memoryDataReader;
        }
 protected override IDbCommand GetCachedCommand(IGxConnection con, string stmt)
 {
     return(con.ConnectionCache.GetAvailablePreparedCommand(stmt));
 }
 internal void EndExecute(ICursor oCur, IGxConnection connection)
 {
     throw new NotImplementedException();
 }