AzurePoolCrossDbGenerator/DbAccess.cs
/// <summary>
/// Returns a formatted column or param definition, e.g. AgencyName nvarchar(255)
/// </summary>
Returns a formatted column or param definition, e.g.
Returns a formatted column or param definition e . g .
static string ItemDefinition(string colName, string colType, string colLen, string colPrecision, string colScale)
        {
            if (colType == "nvarchar" || colType == "varchar" || colType == "varbinary")
            {
                if (colLen == "-1" || long.Parse(colLen) > 8000) colLen = "max";
            }
            if (colType == "image")
            {
                colType = "varbinary";
                colLen = "max";
            }
            if (colType == "text")
            {
                colType = "nvarchar";
                colLen = "max";
            }
            if (!String.IsNullOrEmpty(colLen)) colType += $"({colLen})";
            if (!String.IsNullOrEmpty(colPrecision) && (colType == "numeric" || colType == "decimal")) colType += $"({colPrecision},{colScale})";
            string colNull = "";
            if (!colName.Contains("@"))
            {
                colName = $"[{colName}]"; 
                colNull = " NULL"; 
            }
            string colDef = $"{colName} {colType}{colNull},";
            if (!String.IsNullOrEmpty(colLen) && !String.IsNullOrEmpty(colPrecision))
                throw new Exception($"Invalid column definition ");
            return colDef;
        }
static string ItemDefinition ( string colName , string colType , string colLen , string colPrecision , string colScale ) { if ( colType == " " || colType == " " || colType == " " ) { if ( colLen == " " || long . Parse ( colLen ) > 8000 ) colLen = " " ; } if ( colType == " " ) { colType = " " ; colLen = " " ; } if ( colType == " " ) { colType = " " ; colLen = " " ; } if ( ! String . IsNullOrEmpty ( colLen ) ) colType += $" ( { colLen } ) " ; if ( ! String . IsNullOrEmpty ( colPrecision ) && ( colType == " " || colType == " " ) ) colType += $" ( { colPrecision } , { colScale } ) " ; string colNull = " " ; if ( ! colName . Contains ( " " ) ) { colName = $" [ { colName } ] " ; colNull = " " ; } string colDef = $" { colName } { colType } { colNull } , " ; if ( ! String . IsNullOrEmpty ( colLen ) && ! String . IsNullOrEmpty ( colPrecision ) ) throw new Exception ( $" Invalid column definition  " ) ; return colDef ; }
Returns a formatted column or param definition, e.g.
Returns a formatted column or param definition e . g .
// adjust long text types to (max) // image and text are not supported and have to be replaced // text types have length - nvarchar(255) // numeric and decimal have precision // finalise the definition // enclose column names into [ ], leave @params as-is // is required for column definitions // double check there is no numeric/text params overlap
colName
string
colType
string
colLen
string
colPrecision
string
colScale
string