Beispiel #1
0
        // Create an input source of given type and location
        // The locator argument is a path or connection string. The actual filename or table name comes later.
        internal static DataSourceStream Create(SourceKind source, string locator)
        {
            switch (source)
            {
            case SourceKind.Csv:
                return(DataSourceCsv.Create(locator));

            case SourceKind.Text:
                return(DataSourceFile.Create(locator));

            case SourceKind.Sql:
                return(DataSourceSql.Create(locator));

            case SourceKind.Oledb:
                return(DataSourceOleDb.Create(locator));

            case SourceKind.Odbc:
                return(DataSourceOdbc.Create(locator));

            default:
                throw Error.Argument($"bad source: {source}");
            }
        }
Beispiel #2
0
        internal static DataSourceSql Create(string locator)
        {
            var ds = new DataSourceSql {
                _connector = locator,
            };

            try {
                ds._connection = new SqlConnection(locator);
            } catch (Exception ex) {
                throw Error.Fatal($"Sql: {ex.Message}");
            }
            ds._convdict = new Dictionary <string, CommonType> {
                { "char", CommonType.Text },
                { "varchar", CommonType.Text },
                { "nchar", CommonType.Text },
                { "nvarchar", CommonType.Text },
                { "text", CommonType.Text },
                { "bit", CommonType.Bool },
                { "int", CommonType.Integer },
                { "bigint", CommonType.Integer },
                { "smallint", CommonType.Integer },
                { "tinyint", CommonType.Integer },
                { "numeric", CommonType.Number },
                { "decimal", CommonType.Number },
                { "money", CommonType.Number },
                { "smallmoney", CommonType.Number },
                { "date", CommonType.Time },
                { "datetime", CommonType.Time },
                { "time", CommonType.Time },
                { "datetime2", CommonType.Time },
                { "smalldatetime", CommonType.Time },
                { "datetimeoffset", CommonType.Time },
            };

            return(ds);
        }