public ReaderStatus ReadToArray <TElement>(ReaderState state, Func <TElement> constructor, ReaderCallback <ReaderState, RawProtobufValue, char, TElement> callback, out BrowserMove <TElement> browserMove) { var firstIndex = state.FieldIndex; browserMove = (int index, out TElement element) => { // Read next field header if required so we know whether it's still part of the same array or not if (index > 0) { state.ReadHeader(); // Different field index (or end of stream) was met, stop enumeration if (firstIndex != state.FieldIndex) { element = default; return(BrowserState.Success); } } // Read field and continue enumeration if we're still reading elements sharing the same field index element = constructor(); return(callback(this, state, ref element) != ReaderStatus.Failed ? BrowserState.Continue : BrowserState.Failure); }; return(ReaderStatus.Succeeded); }
private void GetData(string fetch, ReaderCallback readCallback) { SqlDataReader reader = null; SqlCommand command = null; int counter = 1; try { connection.Open(); command = new SqlCommand(fetch); command.Connection = connection; reader = command.ExecuteReader(); readCallback.Invoke(reader, counter); // callback to handle the record } catch (Exception ex) { SQL_msg.ShowMessageBox(ex.Message); } finally { if (reader != null) reader.Close(); if (connection.State == ConnectionState.Open) connection.Close(); } }
static void DoDatabaseCall(ParameterisedQuery query, string sql, bool createDB, DataTable results, ReaderCallback callback, params object[] args) { BindParams(query, args); string connString = Backend.ConnectionString; Exception e = null; for (int i = 0; i < 10; i++) { try { if (callback != null) { query.ExecuteReader(sql, connString, callback); } else if (results == null) { query.Execute(sql, connString, createDB); } else { query.Fill(sql, connString, results); } query.ClearParams(); return; } catch (Exception ex) { e = ex; // try yet again } } File.AppendAllText("MySQL_error.log", DateTime.Now + " " + sql + "\r\n"); Server.ErrorLog(e); }
private void GetData(string fetch, ReaderCallback readCallback) { SqlDataReader reader = null; SqlCommand command = null; int counter = 1; try { connection.Open(); command = new SqlCommand(fetch); command.Connection = connection; reader = command.ExecuteReader(); readCallback.Invoke(reader, counter); // callback to handle the record } catch (Exception ex) { SQL_msg.ShowMessageBox(ex.Message); } finally { if (reader != null) { reader.Close(); } if (connection.State == ConnectionState.Open) { connection.Close(); } } }
public static void ReadList(XmlReader reader, ICollection <string> endNodes, ReaderCallback callback) { ReadList(reader, endNodes, delegate(ReadCallbackData data) { return(callback()); }); }
internal static object Do(string sql, bool createDB, object arg, ReaderCallback callback, params object[] args) { Exception e = null; for (int i = 0; i < 10; i++) { try { if (callback != null) { arg = SqlQuery.Iterate(sql, args, arg, callback); } else { SqlQuery.Execute(sql, args, createDB); } return(arg); } catch (Exception ex) { e = ex; // try yet again } } try { File.AppendAllText("MySQL_error.log", DateTime.Now + " " + sql + "\r\n"); } catch { } Logger.LogError(e); return(arg); }
internal static object Do(string sql, bool createDB, object arg, ReaderCallback callback, params object[] args) { Exception e = null; for (int i = 0; i < 10; i++) { try { if (callback != null) { arg = SqlQuery.Iterate(sql, args, arg, callback); } else { SqlQuery.Execute(sql, args, createDB); } return(arg); } catch (Exception ex) { e = ex; // try yet again } } Logger.LogError("Error executing SQL statement: " + sql, e); return(arg); }
public TreeDecoder(IReader <TState, TNative, TKey> reader, Func <TEntity> constructor, ReaderCallback <TState, TNative, TKey, TEntity> callback) { this.callback = callback; this.constructor = constructor; this.reader = reader; }
public ReaderStatus ReadToArray <TElement>(ReaderState state, Func <TElement> constructor, ReaderCallback <ReaderState, string, char, TElement> callback, out BrowserMove <TElement> browserMove) { browserMove = default; return(ReaderStatus.Ignored); }
/// <summary> Iterates over read rows for the given table. </summary> /// <param name="modifier"> Optional SQL to filter which rows are read, /// return rows in a certain order, etc.</param> public static object ReadRows(string table, string columns, object arg, ReaderCallback callback, string modifier = "", params object[] args) { ValidateName(table); string sql = Backend.ReadRowsSql(table, columns, modifier); return(Iterate(sql, arg, callback, args)); }
static void MatchMulti(string name, string columns, object arg, ReaderCallback callback) { string suffix = Database.Backend.CaselessLikeSuffix; Database.ReadRows("Players", columns, arg, callback, "WHERE Name LIKE @0 ESCAPE '#' LIMIT 101" + suffix, "%" + name.Replace("_", "#_") + "%"); }
/// <summary> /// 读取数据库 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="query"></param> /// <param name="callback"></param> /// <param name="args"></param> /// <returns></returns> public async Task <T> ReadAsync <T>(string query, ReaderCallback callback, params object[] args) { using (var cmd = CreateCommand(query, null, args)) { using (var result = await cmd.ExecuteReaderAsync()) { return((T)callback(result)); } } }
/// <summary> /// 同步读取数据库 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="query"></param> /// <param name="callback"></param> /// <param name="args"></param> /// <returns></returns> public T Read <T>(string query, ReaderCallback callback, params object[] args) { using (var cmd = CreateCommand(query, null, args)) { using (var result = cmd.ExecuteReader()) { return((T)callback(result)); } } }
private void GetData_ByRecord(string fetch, ReaderCallback readCallback) { GetData(fetch, (reader, counter) => { while (reader.Read()) { readCallback.Invoke(reader, counter); // callback to handle the record counter++; } }); }
/// <summary> Iterates over read rows for the given table. </summary> /// <remarks> modifier is optional SQL which can be used to read only certain rows, /// return rows in a certain order, etc.</remarks> public virtual object ReadRows(string table, string columns, object arg, ReaderCallback callback, string modifier = "", params object[] args) { ValidateTable(table); string sql = "SELECT " + columns + " FROM `" + table + "`"; if (modifier.Length > 0) { sql += " " + modifier; } return(Database.Iterate(sql, arg, callback, args)); }
static void OldReadRows(string table, string columns, object arg, ReaderCallback callback) { using (SQLiteConnection conn = new OldSQLiteConnection()) { conn.Open(); if (!OldTableUsed(conn, table)) { return; } string sql = SQLiteBackend.Instance.ReadRowsSql(table, columns, ""); using (SQLiteCommand cmd = new SQLiteCommand(sql, conn)) { using (IDataReader r = cmd.ExecuteReader()) { while (r.Read()) { callback(r, arg); } } } } }
public void ExecuteReader(string query, string connString, ReaderCallback callback) { using (IDbConnection conn = CreateConnection(connString)) { conn.Open(); if (MultipleSchema) { conn.ChangeDatabase(Server.MySQLDatabaseName); } using (IDbCommand cmd = CreateCommand(query, conn)) { FillParams(cmd); using (IDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { callback(reader); } } } conn.Close(); } }
/// <summary> Excecutes an SQL query, invoking a callback on the returned rows one by one. </summary> public object Iterate(string sql, object[] parameters, object arg, ReaderCallback callback) { using (IDbConnection conn = CreateConnection()) { conn.Open(); if (MultipleSchema) { conn.ChangeDatabase(Server.Config.MySQLDatabaseName); } using (IDbCommand cmd = CreateCommand(sql, conn)) { FillParams(cmd, parameters); using (IDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { arg = callback(reader, arg); } } } conn.Close(); } return(arg); }
//public static void Start(int i, Action callback){}//start id i storyboard, load in graph... public static void Start(int i, ReaderCallback _callback) { instance.curNode = null; instance.callback = _callback; //LoadGraph("default.asset"); LoadGraph("data.dat"); //events.onTextPhase (new ReaderTextData("we have a text phase!")); instance.curNode = instance.curGraph.startNode; if (instance.curNode == null) { Debug.LogError("Error curNode instance is null"); } if (instance.curGraph == null) { Debug.LogError("Error curGraph is null"); } if (instance.curGraph.startNode == null) { Debug.LogError("Error startNode is null"); } if (instance.events == null) { Debug.LogError("Error events is null"); } if (instance.events.onStarted == null) { Debug.LogError("Error events.onStarted is null"); } Continue(); //After everything is done return and do a callback; //callback (); }
private void ExecuteSQLQuery(string query, ReaderCallback readerCallback) { using (var connection = new SqliteConnection($"Data Source={m_fileName}")) { connection.Open(); SqliteDataReader reader; using (var command = connection.CreateCommand()) { command.CommandText = query; reader = command.ExecuteReader(); } if (readerCallback != null) { readerCallback(reader); } reader.Close(); connection.Close(); } }
private BrowserMove <TElement> ReadToArrayFromArray <TElement>(ReaderState state, Func <TElement> constructor, ReaderCallback <ReaderState, JSONValue, int, TElement> callback) { state.Read(); return((int index, out TElement current) => { state.PullIgnored(); if (state.Current == ']') { state.Read(); current = default; return BrowserState.Success; } // Read comma separator if any if (index > 0) { if (!state.PullExpected(',')) { current = default; return BrowserState.Failure; } state.PullIgnored(); } // Read array value current = constructor(); return callback(this, state, ref current) != ReaderStatus.Failed ? BrowserState.Continue : BrowserState.Failure; }); }
public static void ReadList(XmlReader reader, string endNode, ReaderCallback callback) { ReadList(reader, new string[] { endNode }, callback); }
public void enableReaderMode(Activity activity, ReaderCallback callback, int flags, Bundle extras) { }
public ReaderStatus ReadToArray <TElement>(ReaderState state, Func <TElement> constructor, ReaderCallback <ReaderState, JSONValue, int, TElement> callback, out BrowserMove <TElement> browserMove) { state.PullIgnored(); switch (state.Current) { case '[': browserMove = this.ReadToArrayFromArray(state, constructor, callback); return(ReaderStatus.Succeeded); case '{': if (this.readObjectValuesAsArray) { browserMove = this.ReadToArrayFromObjectValues(state, constructor, callback); return(ReaderStatus.Succeeded); } goto default; case 'n': browserMove = default; return(Reader.ExpectKeywordNull(state) ? ReaderStatus.Ignored : ReaderStatus.Failed); default: // Accept any scalar value as an array of one element if (this.readScalarAsOneElementArray) { browserMove = (int index, out TElement current) => { if (index > 0) { current = default; return(BrowserState.Success); } current = constructor(); return(callback(this, state, ref current) != ReaderStatus.Failed ? BrowserState.Continue : BrowserState.Failure); }; return(ReaderStatus.Succeeded); } // Ignore array when not supported by current descriptor else { browserMove = (int index, out TElement current) => { current = default; return(BrowserState.Success); }; return(this.Skip(state) ? ReaderStatus.Succeeded : ReaderStatus.Failed); } } }
public static void ExecuteReader(string sql, ReaderCallback callback, params object[] args) { ParameterisedQuery query = Backend.CreateParameterised(); DoDatabaseCall(query, sql, false, null, callback, args); }
private BrowserMove <TElement> ReadToArrayFromObjectValues <TElement>(ReaderState state, Func <TElement> constructor, ReaderCallback <ReaderState, JSONValue, int, TElement> callback) { state.Read(); return((int index, out TElement current) => { state.PullIgnored(); if (state.Current == '}') { state.Read(); current = default; return BrowserState.Success; } // Read comma separator if any if (index > 0) { if (!state.PullExpected(',')) { current = default; return BrowserState.Failure; } state.PullIgnored(); } if (!state.PullExpected('"')) { current = default; return BrowserState.Failure; } // Read and move to object key while (state.Current != '"') { if (!state.PullCharacter(out _)) { state.Error("invalid character in object key"); current = default; return BrowserState.Failure; } } state.Read(); // Read object separator state.PullIgnored(); if (!state.PullExpected(':')) { current = default; return BrowserState.Failure; } // Read object value state.PullIgnored(); // Read array value current = constructor(); return callback(this, state, ref current) != ReaderStatus.Failed ? BrowserState.Continue : BrowserState.Failure; }); }
private void Call_SelectCustomerInfoLogin(string email_address, string password, int qid, string responser_id, string reset_guid, string newpwd, string flag, ReaderCallback callback) { DbConnection connection = null; try { connection = _dbLayer.GetConnection(); DbCommand sp = null; IDataReader reader = null; try { sp = connection.CreateCommand(); sp.CommandText = "select_customerinfo_login"; sp.CommandType = CommandType.StoredProcedure; _dbLayer.AddParameter(sp, "@email", ParameterDirection.Input, DbType.String, email_address); if (password != null) _dbLayer.AddParameter(sp, "@pwd", ParameterDirection.Input, DbType.String, password); if (!string.IsNullOrEmpty(responser_id)) _dbLayer.AddParameter(sp, "@rid", ParameterDirection.Input, DbType.String, responser_id); if (newpwd != null) _dbLayer.AddParameter(sp, "@newpwd", ParameterDirection.Input, DbType.String, newpwd); if (reset_guid != null) _dbLayer.AddParameter(sp, "@resetguid", ParameterDirection.Input, DbType.String, reset_guid); if (!string.IsNullOrEmpty(flag)) _dbLayer.AddParameter(sp, "@flag", ParameterDirection.Input, DbType.String, flag); _dbLayer.AddParameter(sp, "@questionnaire_id", ParameterDirection.Input, DbType.Int32, qid); _dbLayer.AddReturnParameter(sp); reader = sp.ExecuteReader(); if (reader.Read()) { callback(reader); } else { int err = _dbLayer.GetReturnValue(sp); Trace.WriteLine(string.Format("ResponseDao.Call_SelectCustomerInfoLogin({0}, {1}, {2}, {4}) returned {4}", email_address, password, qid, responser_id, err)); } } catch (DbException e) { Trace.WriteLine(string.Format("ResponseDao.Call_SelectCustomerInfoLogin({0}, {1}, {2}, {4}): {4}", email_address, password, qid, responser_id, e.Message)); } finally { if (reader != null && !reader.IsClosed) { reader.Close(); } if (sp != null) { sp.Dispose(); } } } catch (DbException e) { Trace.WriteLine(string.Format("ResponseDao.Call_SelectCustomerInfoLogin({0}, {1}, {2}, {4}): {4}", email_address, password, qid, responser_id, e.Message)); } finally { if (connection != null) { _dbLayer.ReturnConnection(connection); } else { _dbLayer.ReturnConnection(connection, true); } } }
public static void ReadList (XmlReader reader, ICollection<string> endNodes, ReaderCallback callback) { ReadList (reader, endNodes, delegate(ReadCallbackData data) { return callback (); }); }
public static void ReadList (XmlReader reader, string endNode, ReaderCallback callback) { ReadList (reader, new string[] { endNode }, callback); }
public ReaderStatus ReadToArray <TElement>(ReaderState state, Func <TElement> constructor, ReaderCallback <ReaderState, ProtobufValue, int, TElement> callback, out BrowserMove <TElement> browserMove) { throw new NotImplementedException(); }
/// <summary> /// Common code for GetCustomerByRID and GetCustomerByCID /// </summary> /// <param name="cid"></param> /// <param name="rid"></param> /// <param name="callback"></param> /// <returns></returns> private PersonalResponseDto Call_Select_Customer(string cid, string rid, ReaderCallback callback) { PersonalResponseDto retval = new PersonalResponseDto(); DbConnection connection = null; try { connection = _dbLayer.GetConnection(); DbCommand sp = null; IDataReader reader = null; try { sp = connection.CreateCommand(); sp.CommandText = "select_customer"; sp.CommandType = CommandType.StoredProcedure; if (!string.IsNullOrEmpty(cid)) _dbLayer.AddParameter(sp, "@customer_id", ParameterDirection.Input, DbType.String, cid); if (!string.IsNullOrEmpty(rid)) _dbLayer.AddParameter(sp, "@responser_id", ParameterDirection.Input, DbType.String, rid); _dbLayer.AddReturnParameter(sp); reader = sp.ExecuteReader(); if (reader.Read()) { callback(reader); } else { int err = _dbLayer.GetReturnValue(sp); Trace.WriteLine("ResponseDao.Call_Select_Customer(" + cid + ", " + rid + ") returned " + err); } } catch (DbException e) { Trace.WriteLine("ResponseDao.GetCustomer(" + cid + ", " + rid + "): " + e.Message); } finally { if (reader != null && !reader.IsClosed) { reader.Close(); } if (sp != null) { sp.Dispose(); } } } catch (DbException e) { Trace.WriteLine("ResponseDao.GetCustomer(" + cid + ", " + rid + "): " + e.Message); } finally { if (connection != null) { _dbLayer.ReturnConnection(connection); } else { _dbLayer.ReturnConnection(connection, true); } } return retval; }
/// <summary> Executes an SQL query, invoking callback function on each returned row. </summary> public static object Iterate(string sql, object arg, ReaderCallback callback, params object[] args) { return(Do(sql, false, arg, callback, args)); }
private void ExecuteSQLQuery(string query, ReaderCallback readerCallback) { using (var connection = new SqliteConnection($"Data Source={m_fileName}")) { connection.Open(); SqliteDataReader reader; using (var command = connection.CreateCommand()) { command.CommandText = query; reader = command.ExecuteReader(); } if (readerCallback != null) readerCallback(reader); reader.Close(); connection.Close(); } }