/// <summary> /// Builds the update sql. /// </summary> /// <param name="updateSql">The update sql.</param> /// <returns>An ISqlResult.</returns> protected virtual ISqlResult BuildUpdateSql(UpdateSql updateSql) { var query = updateSql.WhereQuery; var result = new ParmsSqlResult(); var whereSqlResult = query != null?BuildQuery(query) : new ParmsSqlResult(); var tableName = TableUtlis.GetTableName(updateSql.Table); var doc = updateSql.UpdateObj.As <IRecord>(); var sql = $"update {_dbProvider.FormatFieldName(tableName)} set "; var fieldList = new List <string>(); var parms = new List <IDbDataParameter>(whereSqlResult.Parameters); foreach (var item in doc.Keys.ToList()) { var fieldStr = string.Empty; if (_dbOption.IsUseParamers) { var param = _dbProvider.GetDbDataParameter(); param.ParameterName = $"{_dbProvider.GetParamsSymbol()}{item}"; param.Value = doc[item]; fieldStr = $"{_dbProvider.FormatFieldName(item)}={param.ParameterName}"; parms.Add(param); } else { fieldStr = $"{_dbProvider.FormatFieldName(item)}={_dbProvider.GetObjectType(doc[item])}"; } fieldList.Add(fieldStr); } sql = $"{sql}{fieldList.Join(",")} {whereSqlResult.SQL}"; result.SQL = sql; result.Parameters.AddRange(parms); return(result); }
/// <summary> /// Builds the sql result. /// </summary> /// <param name="sql">The sql.</param> /// <returns>An ISqlResult.</returns> public ISqlResult BuildSqlResult(ISql sql) { return(sql switch { IQuery query => BuildQuery(query), IfSql ifSql => BuilderIfSql(ifSql), StringSql stringSql => BuilderStringSql(stringSql), ExistSql existSql => BuilderExist(existSql), CountDatabaseSql countDatabaseSql => BuildCountForDatabase(countDatabaseSql), DeleteDatabaseSql deleteDatabaseSql => BuildDeleteDatabase(deleteDatabaseSql), AllTableNamesSql allTableNamesSql => BuildAllTableName(allTableNamesSql), CreateDatabaseSql createDatabaseSql => BuildCreateDatabase(createDatabaseSql), AllDatabaseSql allDatabaseSql => BuildAllDatabase(allDatabaseSql), CreateTableSql createTableSql => BuildCreateTable(createTableSql), CountTableSql countTableSql => BuildTableCount(countTableSql), UpdateTableNameSql updateTableNameSql => BuildUpdateTableName(updateTableNameSql), DeleteTableSql deleteTableSql => BuildDeleteTable(deleteTableSql), ColumsNamesSql columsNamesSql => BuildColumnNames(columsNamesSql), CountColumsSql countColumsSql => BuildColumnsCount(countColumsSql), RenameColumnSql renameColumnSql => BuildRenameColumnsName(renameColumnSql), UpdateColumnsSql updateColumnsSql => BuildUpdateColumns(updateColumnsSql), AddColumnsSql addColumnsSql => BuildAddColumns(addColumnsSql), DeleteColumsSql deleteColumsSql => BuildDeleteColumn(deleteColumsSql), CreateIndexSql createIndexSql => BuildCreateIndex(createIndexSql), DeleteIndexSql deleteIndexSql => BuildDeleteIndex(deleteIndexSql), CountIndexSql countIndexSql => BuildIndexCount(countIndexSql), RenameIndexSql renameIndexSql => RenameIndexSql(renameIndexSql), DeleteSql deleteSql => BuildDeleteSql(deleteSql), InsertSql insertSql => BuildInsertSql(insertSql), UpdateSql updateSql => BuildUpdateSql(updateSql), _ => new ParmsSqlResult() });