private string GetSqlUpdateField(TSQL _tsql, ref SqlCommand _sqlCommand) { string _return = ""; for (int _index = 0; _index < _tsql.Fields.Count; _index++) { Field _field = _tsql.Fields[_index]; _return += (_index > 0 ? "," : ""); if (_field.AsName != "_ThisIsCustomField_") { _return += "[" + _field.Name.Replace(".", "].[") + "]=@" + _field.Name.Replace(".", "_"); if (_field.DbType == SqlDbType.Variant) { _sqlCommand.Parameters.AddWithValue("@" + _field.Name.Replace(".", "_"), _field.Value); } else { SqlParameter _sqlParameter = _sqlCommand.Parameters.AddWithValue("@" + _field.Name.Replace(".", "_"), _field.DbType); _sqlParameter.Value = _field.Value; } } else { _return += _field.Name; } } return(_return); }
private string GetSqlInsertField(TSQL _tsql) { string _return = ""; for (int _index = 0; _index < _tsql.Fields.Count; _index++) { Field _field = _tsql.Fields[_index]; _return += (_index > 0 ? "," : ""); _return += "[" + _field.Name.Replace(".", "].[") + "]"; } return(_return); }
private string GetSqlTable(TSQL _tsql, ref SqlCommand _sqlCommand) { string _return = ""; if (_tsql.Type == TSQLType.Select) { for (int _index = 0; _index < _tsql.Tables.Count; _index++) { Table _table = _tsql.Tables[_index]; if (_index > 0) { switch (_table.Relation) { case TableRelation.Inner: _return += " INNER JOIN "; _return += GetSqlTableNameString(_table) + " ON " + GetSqlWhere(_table.Conditions, ref _sqlCommand); break; case TableRelation.LeftOuter: _return += " LEFT OUTER JOIN "; _return += GetSqlTableNameString(_table) + " ON " + GetSqlWhere(_table.Conditions, ref _sqlCommand); break; case TableRelation.RightOuter: _return += " RIGHT OUTER JOIN "; _return += GetSqlTableNameString(_table) + " ON " + GetSqlWhere(_table.Conditions, ref _sqlCommand); break; case TableRelation.FullOuter: _return += " FULL OUTER JOIN "; _return += GetSqlTableNameString(_table) + " ON " + GetSqlWhere(_table.Conditions, ref _sqlCommand); break; case TableRelation.Cross: _return += " CROSS JOIN "; _return += GetSqlTableNameString(_table); break; } } else { _return += GetSqlTableNameString(_table); } } } else { Table _table = _tsql.Tables[0]; _return += "[" + _table.Name.Replace(".", "].[") + "]"; } return(_return); }
private string GetSqlInsertValue(TSQL _tsql, ref SqlCommand _sqlCommand) { string _return = ""; for (int _index = 0; _index < _tsql.Fields.Count; _index++) { Field _field = _tsql.Fields[_index]; _return += (_index > 0 ? "," : ""); _return += "@" + _field.Name.Replace(".", "_"); _sqlCommand.Parameters.AddWithValue("@" + _field.Name.Replace(".", "_"), _field.Value); } return(_return); }
private string GetSqlSelectField(TSQL _tsql) { string _return = ""; for (int _index = 0; _index < _tsql.Fields.Count; _index++) { Field _field = _tsql.Fields[_index]; _return += (_index > 0 ? "," : ""); if (_field.AsName != "_ThisIsCustomField_") { _return += "[" + _field.Name.Replace(".", "].[") + "]" + (_field.AsName != "" ? " AS [" + _field.AsName + "]" : ""); } else { _return += _field.Name; } } return(_return); }
private string GetSqlOutput(TSQL _tsql) { if (_tsql.Outputs.Count == 0) { return(""); } string _output = " OUTPUT"; for (int i = 0; i < _tsql.Outputs.Count; i++) { _output += i == 0 ? " " : ","; switch (_tsql.Outputs[i].Type) { case OutputType.Inserted: _output += "INSERTED."; break; case OutputType.Deleted: _output += "DELETED."; break; } _output += "[" + _tsql.Outputs[i].Name + "]"; } return(_output); }
private string GetSqlGroupBy(TSQL _tsql) { string _return = ""; for (int _index = 0; _index < _tsql.Groups.Count; _index++) { if (_index > 0) { _return += ","; } switch (_tsql.Groups[_index].GroupType) { case GroupType.Field: _return += "[" + _tsql.Groups[_index].FieldName.Replace(".", "].[") + "]"; break; case GroupType.Value: _return += _tsql.Groups[_index].FieldName; break; } } return(_return); }
private string GetSqlHaving(TSQL _tsql, ref SqlCommand _sqlCommand) { return(GetSqlWhere(_tsql.Havings, ref _sqlCommand)); }