/// <summary> /// Converts table column data to function argument string. /// Does not incude function types. /// Sample: titles, authors, bookcount. /// </summary> public static string GenerateCSharpFunctionList(SqlTable sql_table, eIncludedFields includeTypes) { var sb = new StringBuilder(); bool first_flag = true; foreach (SqlColumn sql_column in sql_table.Columns.Values) { if (first_flag) { first_flag = false; } else { sb.Append(", "); } switch (includeTypes) { case eIncludedFields.All: sb.Append(ToCamelCase(sql_column.Name)); break; case eIncludedFields.NoIdentities: if (!sql_column.IsIdentity) { sb.Append(ToCamelCase(sql_column.Name)); } break; case eIncludedFields.PKOnly: if (sql_column.IsPk) { sb.Append(ToCamelCase(sql_column.Name)); } break; default: throw new Exception("eIncludedFields value " + includeTypes.ToString() + " is unrecognised.."); } } return(sb.ToString()); }
/// <summary> /// Converts table column data to function argument string. /// Does not incude function types. /// Sample: titles, authors, bookcount. /// </summary> public static string GenerateCSharpFunctionList(SqlTable sql_table, eIncludedFields include_types) { StringBuilder sb = new StringBuilder(); bool first_flag = true; foreach (SqlColumn sql_column in sql_table.Columns.Values) { if (first_flag) first_flag = false; else sb.Append(", "); switch (include_types) { case eIncludedFields.All: sb.Append(ToLocalCase(sql_column.Name)); break; case eIncludedFields.NoIdentities: if (!sql_column.IsIdentity) sb.Append(ToLocalCase(sql_column.Name)); break; case eIncludedFields.PKOnly: if (sql_column.IsPk) sb.Append(ToLocalCase(sql_column.Name)); break; default: throw new Exception("eIncludedFields value " + include_types.ToString() +" is unrecognised.."); } } return sb.ToString(); }
private static string GenerateSqlStoredProcParameters(SqlTable sql_table, eIncludedFields included_fields) { if (sql_table == null) throw new Exception("Cannot generate stored procedure parameters without a sql table."); #region Sample Output //( // @CountryID INT, // @CountryName VARCHAR(255) //) #endregion StringBuilder sb = new StringBuilder(); bool flag_first_value = true; int longest_column = GetLongestColumnLength(sql_table); sb.Append("("); // list query parameters foreach (var sql_column in sql_table.Columns.Values) { if ( (included_fields == eIncludedFields.All) || (included_fields == eIncludedFields.PKOnly && sql_column.IsPk) || (included_fields == eIncludedFields.NoIdentities && !sql_column.IsIdentity) ) { if (flag_first_value) flag_first_value = false; else sb.Append(","); sb.Append(Environment.NewLine + AddTabs(1)); sb.Append(PadSqlVariableName(NameFormatter.ToTSQLVariableName(sql_column), longest_column)); sb.Append(NameFormatter.ToTSQLType(sql_column)); } } sb.Append(Environment.NewLine + ")"); return sb.ToString(); }