public IJoinedQueryBuilder <TEntity, T> InnerJoin <T>(string alias) { string typeName = typeof(T).Name; QueryStringBuilder.Append($" INNER JOIN {StringToolkit.PascalToUnderscore(typeName)} {alias} "); return(new JoinedQueryBuilder <TEntity, T>(this)); }
public ISelectQueryBuilder <TEntity> Select <TEntity>(params Expression <Func <TEntity, object> >[] columns) where TEntity : class { string columnStr; if (columns.Length == 0) { columnStr = "*"; } else { string[] clmCpy = new string[columns.Length]; for (int i = 0; i < columns.Length; i++) { clmCpy[i] = $"{ExpressionEvaluator.BuildOrderByQueryString(columns[i], false).Replace("ORDER BY", "")}" .Trim(); } columnStr = string.Join(", ", clmCpy) .Replace("[", "(") .Replace("]", ")"); } QueryStringBuilder.Append($"SELECT {columnStr} " + $"FROM {StringToolkit.PascalToUnderscore(typeof(TEntity).Name)}"); return(new SelectQueryBuilder <TEntity>(this)); }
public Task Remove <T>(T item) where T : class { string queryStr = $"DELETE FROM {StringToolkit.PascalToUnderscore(typeof(T).Name)} " + $"WHERE {ObjectEvaluator.ToWhereString<T>(item)}"; return(QueryBuilder.ExecuteQueryAsync <T>(queryStr)); }
public IInsertQueryBuilder <TEntity> InsertInto <TEntity>() where TEntity : class { QueryStringBuilder.Append($"INSERT INTO " + $"{StringToolkit.PascalToUnderscore(typeof(TEntity).Name)} " /* + $"{PropertyToolkit.BuildInsertString(PropertyToolkit.GetInsertProperties<TEntity>())}"*/); return(new InsertQueryBuilder <TEntity>(this)); }
protected void RefactorAlias(LambdaExpression predicate) { ParameterExpression[] parameters = ExpressionEvaluator.GetAlias(predicate).ToArray(); IDictionary <Type, string> aliasMap = ExpressionEvaluator.GetAliasArray(parameters); foreach (KeyValuePair <Type, string> alias in aliasMap) { Regex rg = new Regex($" {StringToolkit.PascalToUnderscore(alias.Key.Name)} [a-z_]*"); // already has alias string currentQueryValue = this.ToString(); MatchCollection matches = rg.Matches(currentQueryValue); if (matches.Count != 0) { foreach (Match m in matches) { QueryStringBuilder.Replace(m.Value, $" {StringToolkit.PascalToUnderscore(alias.Key.Name)} {alias.Value} "); } } else { rg = new Regex($" {StringToolkit.PascalToUnderscore(alias.Key.Name)}$"); matches = rg.Matches(currentQueryValue); foreach (Match m in matches) { QueryStringBuilder.Replace(m.Value, $" {StringToolkit.PascalToUnderscore(alias.Key.Name)} {alias.Value} "); } } } QueryStringBuilder.Replace(" ", " "); }
public static bool Put(DicomPatientData person) { string key = person.PatientKey; bool ok = true; using (var outStream = new MemoryStream()) { Serializer.Serialize <DicomPatientData>(outStream, person); ok = dbClientDicomPatients.Update(key, outStream.ToArray()); } if (ok) { dbClientUpdates1.InsertAutoIncrement(DB_DICOMPATIENTS, StringToolkit.GetBytes(key)); byte[] byteGps = dbClientGpsFiles.Get(key); if ((byteGps == null) || (byteGps.Length == 0)) { // it doesn't exist, insert it PatientGPSFileList gps = new PatientGPSFileList { EntryTimestamp = DateTime.Now.Ticks }; using (var outStream = new MemoryStream()) { Serializer.Serialize <PatientGPSFileList>(outStream, gps); ok &= dbClientGpsFiles.Create(key, outStream.ToArray()); } if (ok) { dbClientUpdates1.InsertAutoIncrement(DB_GPSFILES, StringToolkit.GetBytes(key)); } } return(ok); } return(false); }
public void RemoveRange <T>(IEnumerable <T> items) where T : class { string queryStr = $"DELETE FROM {StringToolkit.PascalToUnderscore(typeof(T).Name)} " + $"WHERE {ObjectEvaluator.ToWhereString<T>(items)}"; QueryBuilder.ExecuteQuery <T>(queryStr); }
public async Task <bool> Contains <T>(T item) where T : class { string whereStr = $"WHERE {ObjectEvaluator.ToWhereString<T>(item)}"; string queryStr = $"SELECT * " + $"FROM {StringToolkit.PascalToUnderscore(typeof(T).Name)} " + $"{whereStr}"; return((await QueryBuilder.ExecuteQueryAsync <T>(queryStr)).Any()); }
public Task Set <T>(T oldValue, T newValue) where T : class { string setStr = $"SET {ObjectEvaluator.ToWhereString<T>(newValue).Replace(" AND ", ", \n")}"; string whereStr = $"WHERE {ObjectEvaluator.ToWhereString<T>(oldValue)}"; string queryStr = $"UPDATE {StringToolkit.PascalToUnderscore(typeof(T).Name)} " + $"{setStr} {whereStr}"; return(QueryBuilder.ExecuteNonQueryAsync(queryStr)); }
public ISelectQueryBuilder <TEntity> SelectCount <TEntity>(Expression <Func <TEntity, object> > columns = null) where TEntity : class { QueryStringBuilder.Append("SELECT COUNT(") .Append((columns == null ? "*" : $"{StringToolkit.PascalToUnderscore(((columns.Body as BinaryExpression).Right as MemberExpression).Member.Name)}")) .Append(")") .Append($" FROM {StringToolkit.PascalToUnderscore(typeof(TEntity).Name)}"); return(new SelectQueryBuilder <TEntity>(this)); }
public virtual async Task <T> FindByKey <T>(Expression <Func <T, object> > key, object value) where T : class { string leftHandSide = ExpressionEvaluator.BuildOrderByQueryString(key, false) .Replace("ORDER BY ", ""); string conditionStr = $"WHERE {leftHandSide} = {value}"; string queryStr = $"SELECT * " + $"FROM {StringToolkit.PascalToUnderscore(typeof(T).Name)} " + $"WHERE {conditionStr} " + $"LIMIT 1"; return((await QueryBuilder.ExecuteQueryAsync <T>(queryStr)).FirstOrDefault()); }
public static bool Put(Patient person) { string key = person.GetFallbackKey().ToUpper(); bool ok = true; byte[] bytePatient = dbClientPatients.Get(key); if ((bytePatient == null) || (bytePatient.Length == 0)) { // it doesn't exist, insert it using (var outStream = new MemoryStream()) { Serializer.Serialize <Patient>(outStream, person); ok = dbClientPatients.Create(key, outStream.ToArray()); } if (ok) { dbClientUpdates1.InsertAutoIncrement(DB_PATIENTS, StringToolkit.GetBytes(key)); return(ok); } } return(false); }
private void SynthesisDone(AsyncOperation asyncOperation) { UnityWebRequestAsyncOperation async = asyncOperation as UnityWebRequestAsyncOperation; if (async != null) { if (!async.webRequest.isNetworkError && !async.webRequest.isHttpError) { File.WriteAllBytes(_saveFullPath, async.webRequest.downloadHandler.data); AssetDatabase.Refresh(); Selection.activeObject = AssetDatabase.LoadAssetAtPath(StringToolkit.Concat("Assets", _savePath, "/", _saveName, ".", _format.ToString()), typeof(AudioClip)); } else { Log.Error("合成语音失败:" + async.webRequest.responseCode + " " + async.webRequest.error); } async.webRequest.Dispose(); } else { Log.Error("合成语音失败:错误的请求操作!"); } _isSynthesis = false; }
private void ThdProc() { switch (currentitem) { case 0: this.Dispatcher.BeginInvoke(() => Now.Text = UVEngine.Resources.UVEngine.str); while (true) { string[] str; for (int i = 0; i < 100; i++) { StringToolkit.CutParam(tocut, ',', out str); //str=stn.CutParam(tocut, ','); } this.Dispatcher.BeginInvoke(() => { res.charcount++; res.totalcount++; TestItem_Char.Text = res.charcount.ToString(); CurrentProgress.Value = Timer.GetCurrentTime().TotalSeconds / 5.0f * 100; }); } case 1: this.Dispatcher.BeginInvoke(() => Now.Text = UVEngine.Resources.UVEngine.integer); while (true) { for (int i = 0; i < 10000; i++) { int temp1 = int.Parse("10235"); int temp2 = int.Parse("-2903"); Int64 temp3 = Int64.Parse("-130140"); UInt64 temp4 = UInt64.Parse("239951"); } this.Dispatcher.BeginInvoke(() => { res.intcount++; res.totalcount++; TestItem_Int.Text = res.intcount.ToString(); CurrentProgress.Value = Timer.GetCurrentTime().TotalSeconds / 5.0f * 100; }); } case 2: this.Dispatcher.BeginInvoke(() => Now.Text = UVEngine.Resources.UVEngine.flo); while (true) { for (int i = 0; i < 10000; i++) { float temp1 = float.Parse("102.35"); float temp2 = float.Parse("-29.03"); Double temp3 = Double.Parse("-1301.40"); Double temp4 = Double.Parse("239.951"); } this.Dispatcher.BeginInvoke(() => { res.floatcount++; res.totalcount++; TestItem_Float.Text = res.floatcount.ToString(); CurrentProgress.Value = Timer.GetCurrentTime().TotalSeconds / 5.0f * 100; }); } case 3: this.Dispatcher.BeginInvoke(() => Now.Text = UVEngine.Resources.UVEngine.disk); isfs = new IsolatedStorageFileStream("bench", FileMode.Create, isf); while (true) { for (int i = 0; i < 1048576; i++) { isfs.WriteByte(0); } this.Dispatcher.BeginInvoke(() => { res.diskcount++; res.totalcount++; TestItem_Disk.Text = res.diskcount.ToString(); CurrentProgress.Value = Timer.GetCurrentTime().TotalSeconds / 5.0f * 100; }); } } }
public IUpdateQueryBuilder <TEntity> Update <TEntity>() where TEntity : class { QueryStringBuilder.Append($"UPDATE {StringToolkit.PascalToUnderscore(typeof(TEntity).Name)}"); return(new UpdateQueryBuilder <TEntity>(this)); }
public IDeleteQueryBuilder <TEntity> DeleteFrom <TEntity>() where TEntity : class { QueryStringBuilder.Append($"DELETE FROM " + $"{StringToolkit.PascalToUnderscore(typeof(TEntity).Name)}"); return(new DeleteQueryBuilder <TEntity>(this)); }