/// <summary> ///+/- blocking /// </summary> /// <param name="nextAction"></param> public void Execute(bool execReader, Action nextAction = null) { _execState = QueryExecState.Exec; _queryUsedMode = execReader ? QueryUseMode.ExecReader : QueryUseMode.ExecNonQuery; //------------------- //blocking method*** //wait until execute finish //------------------- if (nextAction != null) { //not block here if (_prepareContext != null) { ExecutePrepareQuery_A(nextAction); } else { ExecuteNonPrepare_A(nextAction); } } else { //block _conn.InitWait(); if (_prepareContext != null) { ExecutePrepareQuery_A(_conn.UnWait); } else { ExecuteNonPrepare_A(_conn.UnWait); } _conn.Wait(); } }
/// <summary> /// +/- blocking /// </summary> /// <param name="nextAction"></param> public void Prepare(Action nextAction = null) { _execState = QueryExecState.Prepare; _queryUsedMode = QueryUseMode.Prepare; if (_cmdParams == null) { throw new Exception("Sql cmdParams can not null."); } //------------------- //blocking method*** //wait until execute finish //------------------- //prepare sql query _sqlParserMx.UsePrepareResponseParser(); _prepareContext = null; //------------------------------------------------------------- _writer.Reset(); ComPrepareStatementPacket.Write( _writer, _sqlStrTemplate.BindValues(_cmdParams, true)); //------------------------------------------------------------- if (nextAction != null) { //not block here SendAndRecv_A(_writer.ToArray(), nextAction); } else { //blocking _conn.InitWait(); SendAndRecv_A(_writer.ToArray(), _conn.UnWait); _conn.Wait(); } }
/// <summary> ///+/- blocking /// </summary> /// <param name="nextAction"></param> public void Execute(bool execReader, Action nextAction = null) { _execState = QueryExecState.Exec; _queryUsedMode = execReader ? QueryUseMode.ExecReader : QueryUseMode.ExecNonQuery; //------------------- //blocking method*** //wait until execute finish //------------------- if (nextAction != null) { //not block here if (_prepareContext != null) { ExecutePrepareQuery_A(nextAction); } else { if (!execReader) { //execute non query, ExecuteNonPrepare_A(() => { Close(nextAction); }); } else { ExecuteNonPrepare_A(nextAction); } } } else { //block _conn.InitWait(); if (_prepareContext != null) { ExecutePrepareQuery_A(_conn.UnWait); } else { ExecuteNonPrepare_A(_conn.UnWait); } if (!_conn.Wait()) { //TODO: handle wait-timeout _execState = QueryExecState.Terminated; } else { if (!execReader && _prepareContext == null) { //execute non query Close(null); } } } }
void ClosePrepareStmt_A(Action nextAction) { //for prepare only if (_prepareContext != null) { _sqlParserMx.UseResultParser(); _writer.Reset(); _execState = QueryExecState.Closed; ComStmtClosePacket.Write(_writer, _prepareContext.statementId); //when close, not wait for recv SendPacket_A(_writer.ToArray(), nextAction); } }
/// <summary> /// +/- blocking /// </summary> /// <param name="nextAction"></param> public void Close(Action nextAction = null) { //------------------------------------------------- switch (_execState) { //can close twice without error case QueryExecState.Terminated: return; //*** case QueryExecState.Closed: nextAction?.Invoke(); return; //*** case QueryExecState.Closing: #if DEBUG throw new Exception("conn is closing ..."); #else return; #endif } //first *** _execState = QueryExecState.Closing; //------------------------------------------------- if (_conn != null && _conn.WaitingTerminated) { //something err if (nextAction != null) { } return; } if (nextAction == null) { //blocking*** _sqlParserMx.UseFlushMode(true); //wait where //TODO: review here *** tight loop while (!_recvComplete) { //wait if (_conn.WaitingTerminated) { return;//don't do the rest } //TODO: review here *** tight loop System.Threading.Thread.Sleep(0); } ; _sqlParserMx.UseFlushMode(false); //switch back// //blocking if (_prepareContext != null) { _conn.InitWait(); ClosePrepareStmt_A(_conn.UnWait); if (!_conn.Wait()) { //handle wait timeout _execState = QueryExecState.Terminated; _conn.BindingQuery = null;//release _conn = null; return; } } _execState = QueryExecState.Closed; _conn.BindingQuery = null;//release _conn = null; } else { //non blocking*** if (!_recvComplete) { _sqlParserMx.UseFlushMode(true); MonitorWhenRecvComplete(() => { _sqlParserMx.UseFlushMode(false); if (_prepareContext != null) { ClosePrepareStmt_A(() => { _execState = QueryExecState.Closed; _conn.BindingQuery = null;//release _conn = null; nextAction(); }); } else { _execState = QueryExecState.Closed; _conn.BindingQuery = null;//release _conn = null; nextAction(); } }); } else { if (_prepareContext != null) { ClosePrepareStmt_A(() => { _execState = QueryExecState.Closed; _conn.BindingQuery = null;//release _conn = null; nextAction(); }); } else { _execState = QueryExecState.Closed; _conn.BindingQuery = null;//release _conn = null; nextAction(); } } } }
/// <summary> /// +/- blocking /// </summary> /// <param name="nextAction"></param> public void Close(Action nextAction = null) { //------------------------------------------------- switch (_execState) { //can close twice without error case QueryExecState.Closed: if (nextAction != null) { nextAction(); } return; //*** case QueryExecState.Closing: throw new Exception("conn is closing ..."); } //first *** _execState = QueryExecState.Closing; //------------------------------------------------- if (nextAction == null) { //blocking _sqlParserMx.UseFlushMode(true); //wait where //TODO: review here *** tight loop while (!_recvComplete) { ; } _sqlParserMx.UseFlushMode(false); //switch back// //blocking if (_prepareContext != null) { _conn.InitWait(); ClosePrepareStmt_A(_conn.UnWait); _conn.Wait(); } _execState = QueryExecState.Closed; } else { //non blocking if (!_recvComplete) { _sqlParserMx.UseFlushMode(true); MonitorWhenRecvComplete(() => { _sqlParserMx.UseFlushMode(false); if (_prepareContext != null) { ClosePrepareStmt_A(nextAction); } else { _execState = QueryExecState.Closed; nextAction(); } }); } else { if (_prepareContext != null) { ClosePrepareStmt_A(nextAction); } else { _execState = QueryExecState.Closed; nextAction(); } } } }
/// <summary> /// +/- blocking /// </summary> /// <param name="nextAction"></param> public void Close(Action nextAction = null) { //------------------------------------------------- switch (_execState) { //can close twice without error case QueryExecState.Closed: if (nextAction != null) { nextAction(); } return; //*** case QueryExecState.Closing: throw new Exception("conn is closing ..."); } //first *** _execState = QueryExecState.Closing; //------------------------------------------------- if (nextAction == null) { //blocking _sqlParserMx.UseFlushMode(true); //wait where //TODO: review here *** tight loop while (!_recvComplete) ; _sqlParserMx.UseFlushMode(false); //switch back// //blocking if (_prepareContext != null) { _conn.InitWait(); ClosePrepareStmt_A(_conn.UnWait); _conn.Wait(); } _execState = QueryExecState.Closed; } else { //non blocking if (!_recvComplete) { _sqlParserMx.UseFlushMode(true); MonitorWhenRecvComplete(() => { _sqlParserMx.UseFlushMode(false); if (_prepareContext != null) { ClosePrepareStmt_A(nextAction); } else { _execState = QueryExecState.Closed; nextAction(); } }); } else { if (_prepareContext != null) { ClosePrepareStmt_A(nextAction); } else { _execState = QueryExecState.Closed; nextAction(); } } } }
/// <summary> ///+/- blocking /// </summary> /// <param name="nextAction"></param> public void Execute(bool execReader, Action nextAction = null) { _execState = QueryExecState.Exec; _queryUsedMode = execReader ? QueryUseMode.ExecReader : QueryUseMode.ExecNoneQuery; //------------------- //blocking method*** //wait until execute finish //------------------- if (nextAction != null) { //not block here if (_prepareContext != null) { ExecutePrepareQuery_A(nextAction); } else { ExecuteNonPrepare_A(nextAction); } } else { //block _conn.InitWait(); if (_prepareContext != null) { ExecutePrepareQuery_A(_conn.UnWait); } else { ExecuteNonPrepare_A(_conn.UnWait); } _conn.Wait(); } }