Beispiel #1
0
 /// <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()
     });
Beispiel #2
0
        /// <summary>
        /// Builds the insert sql.
        /// </summary>
        /// <param name="insertSql">The insert sql.</param>
        /// <returns>An ISqlResult.</returns>
        protected virtual ISqlResult BuildInsertSql(InsertSql insertSql)
        {
            var result    = new ParmsSqlResult();
            var doc       = EntityUtil.AsTableRecord(insertSql.Table);
            var tableName = TableUtlis.GetTableName(insertSql.Table.GetType());
            var sql       = $"insert into {_dbProvider.FormatFieldName(tableName)}";
            var pams      = new List <IDbDataParameter>();
            var fields    = new List <string>();
            var valueList = new List <string>();

            foreach (var item in doc.Keys.ToList())
            {
                if (_dbOption.IsUseParamers)
                {
                    var param = _dbProvider.GetDbDataParameter();
                    param.ParameterName = Guid.NewGuid().ToString();
                    param.Value         = doc[item];
                    if (param.Value != null)
                    {
                        fields.Add($"{_dbProvider.FormatFieldName(item)}");
                        pams.Add(param);
                    }
                }
                else
                {
                    var t_value = _dbProvider.GetObjectType(doc[item]);
                    if (t_value != null)
                    {
                        valueList.Add(t_value);
                        fields.Add($"{_dbProvider.FormatFieldName(item)}");
                    }
                }
            }
            if (_dbOption.IsUseParamers)
            {
                sql = $"{sql}({fields.Join(",")}) values({pams.Join(",", t => t.ParameterName)})";
            }
            else
            {
                sql = $"{sql}({fields.Join(",")}) values({valueList.Join(",")})";
            }
            result.SQL = sql;
            result.Parameters.AddRange(pams);
            return(result);
        }