public RowsetBase Execute(ICRUDQueryExecutionContext context, Query query, bool oneRow = false) { var ctx = (MySQLCRUDQueryExecutionContext)context; var target = ctx.DataStore.TargetName; using (var cmd = ctx.Connection.CreateCommand()) { cmd.CommandText = m_Source.StatementSource; PopulateParameters(cmd, query); cmd.Transaction = ctx.Transaction; MySqlDataReader reader = null; try { reader = oneRow ? cmd.ExecuteReader(CommandBehavior.SingleRow) : cmd.ExecuteReader(); GeneratorUtils.LogCommand(ctx.DataStore.LogLevel, "queryhandler-ok", cmd, null); } catch (Exception error) { GeneratorUtils.LogCommand(ctx.DataStore.LogLevel, "queryhandler-error", cmd, error); throw; } using (reader) return(PopulateRowset(ctx, reader, target, query, m_Source, oneRow)); } //using command }
public int ExecuteWithoutFetch(ICRUDQueryExecutionContext context, Query query) { var ctx = (MySQLCRUDQueryExecutionContext)context; using (var cmd = ctx.Connection.CreateCommand()) { cmd.CommandText = m_Source.StatementSource; PopulateParameters(cmd, query); cmd.Transaction = ctx.Transaction; try { var affected = cmd.ExecuteNonQuery(); GeneratorUtils.LogCommand(ctx.DataStore.LogLevel, "queryhandler-ok", cmd, null); return(affected); } catch (Exception error) { GeneratorUtils.LogCommand(ctx.DataStore.LogLevel, "queryhandler-error", cmd, error); throw; } } //using command }
public override RowsetBase Execute(ICRUDQueryExecutionContext context, Query query, bool oneRow = false) { var ctx = (MongoDBCRUDQueryExecutionContext)context; Connector.Collection collection; var qry = MakeQuery(ctx.Database, query, out collection ); Schema schema = null; if (query.ResultRowType!=null) schema = Schema.GetForTypedRow(query.ResultRowType); Rowset result = null; if (schema!=null) result = new Rowset(schema); var skipCount = query["SKIP_COUNT"].AsInt(0); using(var cursor = collection.Find(qry, skipCount, oneRow ? 1: 0)) foreach(var doc in cursor) { if (schema==null) { schema = m_Store.Converter.InferSchemaFromBSONDocument(doc); result = new Rowset(schema); } var row = Row.MakeRow(schema, query.ResultRowType); m_Store.Converter.BSONDocumentToRow(doc, row, m_Store.TargetName); result.Add( row ); } return result; }
public override Cursor OpenCursor(ICRUDQueryExecutionContext context, Query query) { var ctx = (MongoDbCRUDQueryExecutionContext)context; Connector.Collection collection; var qry = MakeQuery(ctx.Database, query, Source, out collection); Schema schema = null; var dtp = query.ResultDocType; if (dtp != null && typeof(TypedDoc).IsAssignableFrom(dtp)) { schema = Schema.GetForTypedDoc(query.ResultDocType); } var p = query[QUERY_PARAM_SKIP_COUNT]; var skipCount = p != null?p.Value.AsInt(0) : 0; p = query[QUERY_PARAM_FETCH_BY]; var fetchBy = p != null?p.Value.AsInt(0) : 0; var mcursor = collection.Find(qry, skipCount, fetchBy); var enumerable = enumOpenCursor(schema, query, mcursor); return(new MongoDbCursor(mcursor, enumerable)); }
public override int ExecuteWithoutFetch(ICRUDQueryExecutionContext context, Query query) { var ctx = (MongoDbCRUDQueryExecutionContext)context; var qry = MakeQuery(query, Source); return(ctx.Database.RunCommand(qry) != null ? 1 : 0); }
public override RowsetBase Execute(ICRUDQueryExecutionContext context, Query query, bool oneRow = false) { var ctx = (MongoDbCRUDQueryExecutionContext)context; Connector.Collection collection; var qry = MakeQuery(ctx.Database, query, Source, out collection); Schema schema = null; var dtp = query.ResultDocType; if (dtp != null && typeof(TypedDoc).IsAssignableFrom(dtp)) { schema = Schema.GetForTypedDoc(query.ResultDocType); } Rowset result = null; if (schema != null) { result = new Rowset(schema); } var p = query[QUERY_PARAM_SKIP_COUNT]; var skipCount = p != null?p.Value.AsInt(0) : 0; p = query[QUERY_PARAM_FETCH_BY]; var fetchBy = p != null?p.Value.AsInt(0) : 0; p = query[QUERY_PARAM_FETCH_LIMIT]; var fetchLimit = p != null?p.Value.AsInt(-1) : -1; using (var cursor = collection.Find(qry, skipCount, oneRow ? 1: fetchBy)) foreach (var doc in cursor) { if (schema == null) { schema = Store.Converter.InferSchemaFromBSONDocument(doc); result = new Rowset(schema); } var row = Doc.MakeDoc(schema, query.ResultDocType); Store.Converter.BSONDocumentToDataDoc(doc, row, Store.TargetName); result.Add(row); if (fetchLimit > 0 && result.Count >= fetchLimit) { break; } } return(result); }
public override Schema GetSchema(ICRUDQueryExecutionContext context, Query query) { var ctx = (MongoDBCRUDQueryExecutionContext)context; Connector.Collection collection; var qry = MakeQuery(ctx.Database, query, out collection ); var doc = collection.FindOne(qry); if (doc==null) return null; return m_Store.Converter.InferSchemaFromBSONDocument(doc); }
public override Schema GetSchema(ICRUDQueryExecutionContext context, Query query) { var ctx = (MongoDbCRUDQueryExecutionContext)context; Connector.Collection collection; var qry = MakeQuery(ctx.Database, query, Source, out collection); var doc = collection.FindOne(qry); if (doc == null) { return(null); } return(Store.Converter.InferSchemaFromBSONDocument(doc)); }
public async override Task <RowsetBase> ExecuteAsync(ICRUDQueryExecutionContext context, Query query, bool oneRow = false) { await Task.Delay(100); var result = new Rowset(Schema.GetForTypedDoc <Patient>()); var p = query.FindParamByName("Msg")?.Value.AsString(); result.Insert(new Patient { First_Name = "Jack", Last_Name = "Nice", Address1 = p }); result.Insert(new Patient { First_Name = "Mary", Last_Name = "Dice", Address1 = p }); return(result); }
public Cursor OpenCursor(ICRUDQueryExecutionContext context, Query query) { var ctx = (MySQLCRUDQueryExecutionContext)context; var target = ctx.DataStore.TargetName; Schema.FieldDef[] toLoad; Schema schema = null; MySqlDataReader reader = null; var cmd = ctx.Connection.CreateCommand(); try { cmd.CommandText = m_Source.StatementSource; PopulateParameters(cmd, query); cmd.Transaction = ctx.Transaction; try { reader = cmd.ExecuteReader(); GeneratorUtils.LogCommand(ctx.DataStore.LogLevel, "queryhandler-ok", cmd, null); } catch (Exception error) { GeneratorUtils.LogCommand(ctx.DataStore.LogLevel, "queryhandler-error", cmd, error); throw; } schema = GetSchemaForQuery(target, query, reader, m_Source, out toLoad); } catch { if (reader != null) { reader.Dispose(); } cmd.Dispose(); throw; } var enumerable = execEnumerable(ctx, cmd, reader, schema, toLoad, query); return(new MySQLCursor(ctx, cmd, reader, enumerable)); }
public override RowsetBase Execute(ICRUDQueryExecutionContext context, Query query, bool oneRow = false) { var ctx = (MongoDBCRUDQueryExecutionContext)context; NFX.DataAccess.MongoDB.Connector.Collection collection; var qry = MakeQuery(ctx.Database, query, out collection); var rrow = new TResult(); var sw = Stopwatch.StartNew(); rrow.Count = collection.Count(qry);//Performs server-side count over query rrow.Interval = sw.Elapsed; var result = new Rowset(Schema.GetForTypedRow(typeof(TResult))); result.Add(rrow); return result; }
public override RowsetBase Execute(ICRUDQueryExecutionContext context, Query query, bool oneRow = false) { var ctx = (MongoDBCRUDQueryExecutionContext)context; Connector.Collection collection; var qry = MakeQuery(ctx.Database, query, out collection ); Schema schema = null; var rtp = query.ResultRowType; if (rtp!=null && typeof(TypedRow).IsAssignableFrom(rtp)) schema = Schema.GetForTypedRow(query.ResultRowType); Rowset result = null; if (schema!=null) result = new Rowset(schema); var p = query[QUERY_PARAM_SKIP_COUNT]; var skipCount = p!=null ? p.Value.AsInt(0) : 0; p = query[QUERY_PARAM_FETCH_BY]; var fetchBy = p!=null ? p.Value.AsInt(0) : 0; p = query[QUERY_PARAM_FETCH_LIMIT]; var fetchLimit = p!=null ? p.Value.AsInt(-1) : -1; using(var cursor = collection.Find(qry, skipCount, oneRow ? 1: fetchBy)) foreach(var doc in cursor) { if (schema==null) { schema = m_Store.Converter.InferSchemaFromBSONDocument(doc); result = new Rowset(schema); } var row = Row.MakeRow(schema, query.ResultRowType); m_Store.Converter.BSONDocumentToRow(doc, row, m_Store.TargetName); result.Add( row ); if (fetchLimit>0 && result.Count>=fetchLimit) break; } return result; }
public override RowsetBase Execute(ICRUDQueryExecutionContext context, Query query, bool oneRow = false) { var ctx = (MongoDBCRUDQueryExecutionContext)context; Connector.Collection collection; var qry = MakeQuery(ctx.Database, query, out collection); Schema schema = null; var rtp = query.ResultRowType; if (rtp != null && typeof(TypedRow).IsAssignableFrom(rtp)) { schema = Schema.GetForTypedRow(query.ResultRowType); } Rowset result = null; if (schema != null) { result = new Rowset(schema); } var skipCount = query["SKIP_COUNT"].AsInt(0); using (var cursor = collection.Find(qry, skipCount, oneRow ? 1: 0)) foreach (var doc in cursor) { if (schema == null) { schema = m_Store.Converter.InferSchemaFromBSONDocument(doc); result = new Rowset(schema); } var row = Row.MakeRow(schema, query.ResultRowType); m_Store.Converter.BSONDocumentToRow(doc, row, m_Store.TargetName); result.Add(row); } return(result); }
public override RowsetBase Execute(ICRUDQueryExecutionContext context, Query query, bool oneRow = false) { var ctx = (MongoDbCRUDQueryExecutionContext)context; Azos.Data.Access.MongoDb.Connector.Collection collection; var qry = MakeQuery(ctx.Database, query, Source, out collection); var rrow = new TResult(); var sw = Stopwatch.StartNew(); rrow.Count = collection.Count(qry);//Performs server-side count over query rrow.Interval = sw.Elapsed; var result = new Rowset(Schema.GetForTypedDoc(typeof(TResult))); result.Add(rrow); return(result); }
public Schema GetSchema(ICRUDQueryExecutionContext context, Query query) { var ctx = (MySQLCRUDQueryExecutionContext)context; var target = ctx.DataStore.TargetName; using (var cmd = ctx.Connection.CreateCommand()) { cmd.CommandText = m_Source.StatementSource; PopulateParameters(cmd, query); cmd.Transaction = ctx.Transaction; MySqlDataReader reader = null; try { reader = cmd.ExecuteReader(CommandBehavior.SchemaOnly); GeneratorUtils.LogCommand(ctx.DataStore.LogLevel, "queryhandler-ok", cmd, null); } catch(Exception error) { GeneratorUtils.LogCommand(ctx.DataStore.LogLevel, "queryhandler-error", cmd, error); throw; } using (reader) { Schema.FieldDef[] toLoad; return getSchema(target, query, reader, out toLoad); }//using reader }//using command }
public Schema GetSchema(ICRUDQueryExecutionContext context, Query query) { var ctx = (MySQLCRUDQueryExecutionContext)context; var target = ctx.DataStore.TargetName; using (var cmd = ctx.Connection.CreateCommand()) { cmd.CommandText = m_Source.StatementSource; PopulateParameters(cmd, query); cmd.Transaction = ctx.Transaction; MySqlDataReader reader = null; try { reader = cmd.ExecuteReader(CommandBehavior.SchemaOnly); GeneratorUtils.LogCommand(ctx.DataStore.LogLevel, "queryhandler-ok", cmd, null); } catch (Exception error) { GeneratorUtils.LogCommand(ctx.DataStore.LogLevel, "queryhandler-error", cmd, error); throw; } using (reader) { Schema.FieldDef[] toLoad; return(GetSchemaForQuery(target, query, reader, m_Source, out toLoad)); } //using reader } //using command }
public Task<Cursor> OpenCursorAsync(ICRUDQueryExecutionContext context, Query query) { return TaskUtils.AsCompletedTask( () => this.OpenCursor(context, query)); }
public override Schema GetSchema(ICRUDQueryExecutionContext context, Query query) { throw new NotImplementedException(); }
public virtual RowsetBase Execute(ICRUDQueryExecutionContext context, Query query, bool oneRow = false) { throw new NotImplementedException(); }
public Schema GetSchema(ICRUDQueryExecutionContext context, Query query) { return(m_Store.Map.GetCRUDSchemaForName(m_Source.OriginalSource)); }
/// <summary> /// Executes query that dows not return results. The implementation may be called by multiple threads and must be safe. /// Returns rows affected /// </summary> public abstract int ExecuteWithoutFetch(ICRUDQueryExecutionContext context, Query query);
public virtual Schema GetSchema(ICRUDQueryExecutionContext context, Query query) { throw new NotImplementedException(); }
public int ExecuteWithoutFetch(ICRUDQueryExecutionContext context, Query query) { var ctx = (MySQLCRUDQueryExecutionContext)context; using (var cmd = ctx.Connection.CreateCommand()) { cmd.CommandText = m_Source.StatementSource; PopulateParameters(cmd, query); cmd.Transaction = ctx.Transaction; try { var affected = cmd.ExecuteNonQuery(); GeneratorUtils.LogCommand(ctx.DataStore.LogLevel, "queryhandler-ok", cmd, null); return affected; } catch(Exception error) { GeneratorUtils.LogCommand(ctx.DataStore.LogLevel, "queryhandler-error", cmd, error); throw; } }//using command }
/// <summary> /// Executes query into Cursor. The implementation may be called by multiple threads and must be safe /// </summary> public abstract Cursor OpenCursor(ICRUDQueryExecutionContext context, Query query);
public Task<Cursor> OpenCursorAsync(ICRUDQueryExecutionContext context, Query query) { throw new NotSupportedException("Erl.OpenCursorAsync"); }
public Cursor OpenCursor(ICRUDQueryExecutionContext context, Query query) { var ctx = (MySQLCRUDQueryExecutionContext)context; var target = ctx.DataStore.TargetName; Schema.FieldDef[] toLoad; Schema schema = null; MySqlDataReader reader = null; var cmd = ctx.Connection.CreateCommand(); try { cmd.CommandText = m_Source.StatementSource; PopulateParameters(cmd, query); cmd.Transaction = ctx.Transaction; try { reader = cmd.ExecuteReader(); GeneratorUtils.LogCommand(ctx.DataStore.LogLevel, "queryhandler-ok", cmd, null); } catch(Exception error) { GeneratorUtils.LogCommand(ctx.DataStore.LogLevel, "queryhandler-error", cmd, error); throw; } schema = GetSchemaForQuery(target, query, reader, m_Source, out toLoad); } catch { if (reader!=null) reader.Dispose(); cmd.Dispose(); throw; } var enumerable = execEnumerable(ctx, cmd, reader, schema, toLoad, query); return new MySQLCursor( ctx, cmd, reader, enumerable ); }
public Cursor OpenCursor(ICRUDQueryExecutionContext context, Query query) { throw new NotSupportedException("Erl.OpenCursor"); }
//used for subscription public int ExecuteWithoutFetch(ICRUDQueryExecutionContext context, Query query) { var store = ((ErlCRUDQueryExecutionContext)context).DataStore; var mbox = ((ErlCRUDQueryExecutionContext)context).ErlMailBox; var ts = ((ErlCRUDQueryExecutionContext)context).SubscriptionTimestamp; if (!ts.HasValue) throw new ErlDataAccessException(StringConsts.ERL_DS_QUERY_TMSTAMP_CTX_ABSENT_ERROR); var parsed = prepareQuery(m_Source); var reqID = m_Store.NextRequestID; var bind = new ErlVarBind(); var wass = false; var wast = false; foreach(var erlVar in parsed.ArgVars) { var name = erlVar.Name.Value; if (erlVar.Name==ATOM_Subscriber && erlVar.ValueType==ErlTypeOrder.ErlPid) { bind.Add(ATOM_Subscriber, mbox.Self); wass = true; continue; } if (erlVar.Name==ATOM_Timestamp && erlVar.ValueType==ErlTypeOrder.ErlLong) { bind.Add(ATOM_Timestamp, new ErlLong(ts.Value.Microseconds)); wast = true; continue; } var clrPar = query[name]; if (clrPar==null) throw new ErlDataAccessException(StringConsts.ERL_DS_QUERY_PARAM_NOT_FOUND_ERROR.Args(parsed.Source, name)); bind.Add(erlVar, clrPar.Value); } if (!wass) throw new ErlDataAccessException(StringConsts.ERL_DS_QUERY_SUBSCR_NOT_FOUND_ERROR); if (!wast) throw new ErlDataAccessException(StringConsts.ERL_DS_QUERY_TMSTAMP_NOT_FOUND_ERROR); var request = parsed.ArgTerm.Subst(bind); var args = new ErlList { reqID.ToErlObject(), parsed.Module, parsed.Function, request }; var rawResp = store.ExecuteRPC(ErlDataStore.NFX_CRUD_MOD, ErlDataStore.NFX_SUBSCRIBE_FUN, args, null); var response = rawResp as ErlTuple; // {ReqID, {ok, SchemaID, [{row},{row}...]}} // {ReqID, {ReqID::int(), {error, Code::int(), Msg}}} if (response==null) throw new ErlDataAccessException(StringConsts.ERL_DS_INVALID_RESP_PROTOCOL_ERROR+"QryHndlr.Response==null"); bind = response.Match(EXECUTE_SUBSCRIBE_OK_PATTERN); checkForError(EXECUTE_SUBSCRIBE_ERROR_PATTERN, response, bind, reqID); //{ReqID::int(), ok} return 0; }
public RowsetBase Execute(ICRUDQueryExecutionContext context, Query query, bool oneRow = false) { var store = ((ErlCRUDQueryExecutionContext)context).DataStore; var mbox = ((ErlCRUDQueryExecutionContext)context).ErlMailBox; var parsed = prepareQuery(m_Source); var reqID = m_Store.NextRequestID; var bind = new ErlVarBind(); foreach (var erlVar in parsed.ArgVars) { var name = erlVar.Name.Value; var clrPar = query[name]; if (clrPar == null) { throw new ErlDataAccessException(StringConsts.ERL_DS_QUERY_PARAM_NOT_FOUND_ERROR.Args(parsed.Source, name)); } bind.Add(erlVar, clrPar.Value); } var request = parsed.ArgTerm.Subst(bind); var args = new ErlList { reqID.ToErlObject(), parsed.Module, parsed.Function, request }; var rawResp = store.ExecuteRPC(ErlDataStore.NFX_CRUD_MOD, ErlDataStore.NFX_RPC_FUN, args, mbox); var response = rawResp as ErlTuple; // {ReqID, {ok, SchemaID, [{row},{row}...]}} // {ReqID, {error, Reason}} if (response == null) { throw new ErlDataAccessException(StringConsts.ERL_DS_INVALID_RESP_PROTOCOL_ERROR + "QryHndlr.Response timeout"); } bind = response.Match(EXECUTE_OK_PATTERN); checkForError(EXECUTE_ERROR_PATTERN, response, bind, reqID); if (bind[ATOM_ReqID].ValueAsLong != reqID) { throw new ErlDataAccessException(StringConsts.ERL_DS_INVALID_RESP_PROTOCOL_ERROR + "QryHndlr.Response.ReqID mismatch"); } //{ReqID::int(), {ok, SchemaID::atom(), Rows::list()}} var schema = bind[ATOM_SchemaID].ValueAsString; var rows = bind[ATOM_Rows] as ErlList; //{ok, "tca_jaba", //[ // {tca_jaba, 1234, tav, "User is cool", true}, // {tca_jaba, 2344, zap, "Zaplya xochet pit", false}, // {tca_jaba, 8944, tav, "User is not good", false} //]}; return(m_Store.Map.ErlCRUDResponseToRowset(schema, rows, query.ResultRowType)); }
public override RowsetBase Execute(ICRUDQueryExecutionContext context, Query query, bool oneRow = false) { throw new NotImplementedException(); }
public RowsetBase Execute(ICRUDQueryExecutionContext context, Query query, bool oneRow = false) { var ctx = (MySQLCRUDQueryExecutionContext)context; var target = ctx.DataStore.TargetName; using (var cmd = ctx.Connection.CreateCommand()) { cmd.CommandText = m_Source.StatementSource; PopulateParameters(cmd, query); cmd.Transaction = ctx.Transaction; MySqlDataReader reader = null; try { reader = oneRow ? cmd.ExecuteReader(CommandBehavior.SingleRow) : cmd.ExecuteReader(); GeneratorUtils.LogCommand(ctx.DataStore.LogLevel, "queryhandler-ok", cmd, null); } catch(Exception error) { GeneratorUtils.LogCommand(ctx.DataStore.LogLevel, "queryhandler-error", cmd, error); throw; } using (reader) return PopulateRowset(ctx, reader, target, query, m_Source, oneRow); }//using command }
public override Cursor OpenCursor(ICRUDQueryExecutionContext context, Query query) { var ctx = (MongoDBCRUDQueryExecutionContext)context; Connector.Collection collection; var qry = MakeQuery(ctx.Database, query, out collection ); Schema schema = null; var rtp = query.ResultRowType; if (rtp!=null && typeof(TypedRow).IsAssignableFrom(rtp)) schema = Schema.GetForTypedRow(query.ResultRowType); var p = query[QUERY_PARAM_SKIP_COUNT]; var skipCount = p!=null ? p.Value.AsInt(0) : 0; p = query[QUERY_PARAM_FETCH_BY]; var fetchBy = p!=null ? p.Value.AsInt(0) : 0; var mcursor = collection.Find(qry, skipCount, fetchBy); var enumerable = enumOpenCursor(schema, query, mcursor); return new MongoDBCursor( mcursor, enumerable ); }
public override Cursor OpenCursor(ICRUDQueryExecutionContext context, Query query) { throw new NotImplementedException(); }
/// <summary> /// Executes query into Cursor. The implementation may be called by multiple threads and must be safe /// </summary> public abstract Task <Cursor> OpenCursorAsync(ICRUDQueryExecutionContext context, Query query);
public override int ExecuteWithoutFetch(ICRUDQueryExecutionContext context, Query query) { throw new NotImplementedException(); }
/// <summary> /// Executes query that dows not return results. The implementation may be called by multiple threads and must be safe. /// Returns rows affected /// </summary> public abstract Task <int> ExecuteWithoutFetchAsync(ICRUDQueryExecutionContext context, Query query);
public virtual int ExecuteWithoutFetch(ICRUDQueryExecutionContext context, Query query) { throw new NotImplementedException(); }
public virtual Task<Schema> GetSchemaAsync(ICRUDQueryExecutionContext context, Query query) { return TaskUtils.AsCompletedTask( () => this.GetSchema(context, query)); }
public RowsetBase Execute(ICRUDQueryExecutionContext context, Query query, bool oneRow = false) { var ctx = (MySQLCRUDQueryExecutionContext)context; var target = ctx.DataStore.TargetName; Rowset result = null; using (var cmd = ctx.Connection.CreateCommand()) { cmd.CommandText = m_Source.StatementSource; PopulateParameters(cmd, query); cmd.Transaction = ctx.Transaction; MySqlDataReader reader = null; try { reader = oneRow ? cmd.ExecuteReader(CommandBehavior.SingleRow) : cmd.ExecuteReader(); GeneratorUtils.LogCommand(ctx.DataStore.LogLevel, "queryhandler-ok", cmd, null); } catch(Exception error) { GeneratorUtils.LogCommand(ctx.DataStore.LogLevel, "queryhandler-error", cmd, error); throw; } using (reader) { Schema.FieldDef[] toLoad; Schema schema = getSchema(target, query, reader, out toLoad); result = new Rowset(schema); while(reader.Read()) { var row = Row.MakeRow(schema, query.ResultRowType); for (int i = 0; i < reader.FieldCount; i++) { var fdef = toLoad[i]; if (fdef==null) continue; var val = reader.GetValue(i); if (fdef.NonNullableType==typeof(bool)) row[fdef.Order] = val.AsNullableBool(); else row[fdef.Order] = val; } result.Add( row ); if (oneRow) break; } }//using reader }//using command return result; }
public virtual Task<RowsetBase> ExecuteAsync(ICRUDQueryExecutionContext context, Query query, bool oneRow = false) { return TaskUtils.AsCompletedTask( () => this.Execute(context, query, oneRow)); }
public Task <Cursor> OpenCursorAsync(ICRUDQueryExecutionContext context, Query query) { throw new NotSupportedException("Erl.OpenCursorAsync"); }
public virtual Task<int> ExecuteWithoutFetchAsync(ICRUDQueryExecutionContext context, Query query) { return TaskUtils.AsCompletedTask( () => this.ExecuteWithoutFetch(context, query)); }
public RowsetBase Execute(ICRUDQueryExecutionContext context, Query query, bool oneRow = false) { var store = ((ErlCRUDQueryExecutionContext)context).DataStore; var mbox = ((ErlCRUDQueryExecutionContext)context).ErlMailBox; var parsed = prepareQuery(m_Source); var reqID = m_Store.NextRequestID; var bind = new ErlVarBind(); foreach(var erlVar in parsed.ArgVars) { var name = erlVar.Name.Value; var clrPar = query[name]; if (clrPar==null) throw new ErlDataAccessException(StringConsts.ERL_DS_QUERY_PARAM_NOT_FOUND_ERROR.Args(parsed.Source, name)); bind.Add(erlVar, clrPar.Value); } var request = parsed.ArgTerm.Subst(bind); var args = new ErlList { reqID.ToErlObject(), parsed.Module, parsed.Function, request }; var rawResp = store.ExecuteRPC(ErlDataStore.NFX_CRUD_MOD, ErlDataStore.NFX_RPC_FUN, args, mbox); var response = rawResp as ErlTuple; // {ReqID, {ok, SchemaID, [{row},{row}...]}} // {ReqID, {error, Reason}} if (response==null) throw new ErlDataAccessException(StringConsts.ERL_DS_INVALID_RESPONSE_PROTOCOL_ERROR+"QryHndlr.Response timeout"); bind = response.Match(EXECUTE_OK_PATTERN); if (bind==null) { bind = response.Match(EXECUTE_ERROR_PATTERN); if (bind==null || bind[ATOM_ReqID].ValueAsLong != reqID) throw new ErlDataAccessException(StringConsts.ERL_DS_INVALID_RESPONSE_PROTOCOL_ERROR+"QryHndlr.Response wrong error"); throw new ErlDataAccessException("Remote error code {0}. Message: '{1}'".Args(bind[ATOM_Code], bind[ATOM_Msg])); } if (bind[ATOM_ReqID].ValueAsLong != reqID) throw new ErlDataAccessException(StringConsts.ERL_DS_INVALID_RESPONSE_PROTOCOL_ERROR+"QryHndlr.Response.ReqID mismatch"); //{ReqID::int(), {ok, SchemaID::atom(), Rows::list()}} var schema = bind[ATOM_SchemaID].ValueAsString; var rows = bind[ATOM_Rows] as ErlList; //{ok, "tca_jaba", //[ // {tca_jaba, 1234, tav, "User is cool", true}, // {tca_jaba, 2344, zap, "Zaplya xochet pit", false}, // {tca_jaba, 8944, tav, "User is not good", false} //]}; return m_Store.Map.ErlCRUDResponseToRowset(schema, rows, query.ResultRowType); }
public virtual Cursor OpenCursor(ICRUDQueryExecutionContext context, Query query) { throw new NotImplementedException(); }
/// <summary> /// Executes query without fetching any data but schema. The implementation may be called by multiple threads and must be safe /// </summary> public abstract Schema GetSchema(ICRUDQueryExecutionContext context, Query query);
/// <summary> /// Executes query without fetching any data but schema. The implementation may be called by multiple threads and must be safe /// </summary> public abstract Task <Schema> GetSchemaAsync(ICRUDQueryExecutionContext context, Query query);
/// <summary> /// Executes query. The implementation may be called by multiple threads and must be safe /// </summary> public abstract RowsetBase Execute(ICRUDQueryExecutionContext context, Query query, bool oneRow = false);
public override Task <Schema> GetSchemaAsync(ICRUDQueryExecutionContext context, Query query) { return(TaskUtils.AsCompletedTask(() => this.GetSchema(context, query))); }
/// <summary> /// Executes query. The implementation may be called by multiple threads and must be safe /// </summary> public abstract Task <RowsetBase> ExecuteAsync(ICRUDQueryExecutionContext context, Query query, bool oneRow = false);
public override Task <RowsetBase> ExecuteAsync(ICRUDQueryExecutionContext context, Query query, bool oneRow = false) { return(TaskUtils.AsCompletedTask(() => this.Execute(context, query, oneRow))); }
public override int ExecuteWithoutFetch(ICRUDQueryExecutionContext context, Query query) { var ctx = (MongoDBCRUDQueryExecutionContext)context; var qry = MakeQuery(query); return ctx.Database.RunCommand( qry ) != null ? 1 : 0; }
public override Task <Cursor> OpenCursorAsync(ICRUDQueryExecutionContext context, Query query) { return(TaskUtils.AsCompletedTask(() => this.OpenCursor(context, query))); }
//used for subscription public int ExecuteWithoutFetch(ICRUDQueryExecutionContext context, Query query) { var store = ((ErlCRUDQueryExecutionContext)context).DataStore; var mbox = ((ErlCRUDQueryExecutionContext)context).ErlMailBox; var ts = ((ErlCRUDQueryExecutionContext)context).SubscriptionTimestamp; if (!ts.HasValue) throw new ErlDataAccessException(StringConsts.ERL_DS_QUERY_TIMESTAMP_CTX_ABSENT_ERROR); var parsed = prepareQuery(m_Source); var reqID = m_Store.NextRequestID; var bind = new ErlVarBind(); var wass = false; var wast = false; foreach(var erlVar in parsed.ArgVars) { var name = erlVar.Name.Value; if (erlVar.Name==ATOM_Subscriber && erlVar.ValueType==ErlTypeOrder.ErlPid) { bind.Add(ATOM_Subscriber, mbox.Self); wass = true; continue; } if (erlVar.Name==ATOM_Timestamp && erlVar.ValueType==ErlTypeOrder.ErlLong) { bind.Add(ATOM_Timestamp, new ErlLong(ts.Value.Microseconds)); wast = true; continue; } var clrPar = query[name]; if (clrPar==null) throw new ErlDataAccessException(StringConsts.ERL_DS_QUERY_PARAM_NOT_FOUND_ERROR.Args(parsed.Source, name)); bind.Add(erlVar, clrPar.Value); } if (!wass) throw new ErlDataAccessException(StringConsts.ERL_DS_QUERY_SUBSCRIBER_NOT_FOUND_ERROR); if (!wast) throw new ErlDataAccessException(StringConsts.ERL_DS_QUERY_TIMESTAMP_NOT_FOUND_ERROR); var request = parsed.ArgTerm.Subst(bind); var args = new ErlList { reqID.ToErlObject(), parsed.Module, parsed.Function, request }; var rawResp = store.ExecuteRPC(ErlDataStore.NFX_CRUD_MOD, ErlDataStore.NFX_SUBSCRIBE_FUN, args, null); var response = rawResp as ErlTuple; // {ReqID, {ok, SchemaID, [{row},{row}...]}} // {ReqID, {ReqID::int(), {error, Code::int(), Msg}}} if (response==null) throw new ErlDataAccessException(StringConsts.ERL_DS_INVALID_RESPONSE_PROTOCOL_ERROR+"QryHndlr.Response==null"); bind = response.Match(EXECUTE_SUBSCRIBE_OK_PATTERN); if (bind==null) { bind = response.Match(EXECUTE_SUBSCRIBE_ERROR_PATTERN); if (bind==null || bind[ATOM_ReqID].ValueAsLong != reqID) throw new ErlDataAccessException(StringConsts.ERL_DS_INVALID_RESPONSE_PROTOCOL_ERROR+"QryHndlr.Response wrong error"); var ecode = bind[ATOM_Code].ValueAsInt; var emsg = bind[ATOM_Msg].ToString(); Exception error = new ErlDataAccessException("Remote error code {0}. Message: '{1}'".Args(ecode, emsg)); if (ecode==INVALID_SUBSCRIPTION_REQUEST_EXCEPTION) error = new NFX.DataAccess.CRUD.Subscriptions.InvalidSubscriptionRequestException(emsg, error); throw error; } if (bind[ATOM_ReqID].ValueAsLong != reqID) throw new ErlDataAccessException(StringConsts.ERL_DS_INVALID_RESPONSE_PROTOCOL_ERROR+"QryHndlr.Response.ReqID mismatch"); //{ReqID::int(), ok} return 0; }
public override Task <int> ExecuteWithoutFetchAsync(ICRUDQueryExecutionContext context, Query query) { return(TaskUtils.AsCompletedTask(() => this.ExecuteWithoutFetch(context, query))); }
public Schema GetSchema(ICRUDQueryExecutionContext context, Query query) { return m_Store.Map.GetCRUDSchemaForName(m_Source.OriginalSource); }