├── .RData ├── .Rbuildignore ├── .ci └── Dockerfile ├── .gitignore ├── .gitmodules ├── .travis.yml ├── DESCRIPTION ├── Dockerfile ├── NAMESPACE ├── R ├── .gitignore ├── DBIConnection.R ├── DBIConvenience.R ├── DBIDriver.R ├── DBIMetaInfo.R ├── DBIResult.R ├── DBITransaction.R ├── dbObjectId.R ├── rsqlImpl.R └── zzz.R ├── README.md ├── UsingDocker.md ├── appveyor.yml ├── inst ├── data │ └── CS_BIG.csv ├── libs │ ├── LumenWorks.Framework.IO.dll │ ├── LumenWorks.Framework.IO.pdb │ ├── LumenWorks.Framework.IO.xml │ ├── RDotNet.NativeLibrary.dll │ ├── RDotNet.NativeLibrary.xml │ ├── RDotNet.dll │ ├── RDotNet.xml │ ├── i386 │ │ └── toto │ ├── log4net.config │ ├── log4net.dll │ ├── log4net.xml │ ├── rsqlserver.net.dll │ ├── rsqlserver.net.pdb │ └── x64 │ │ └── toto └── setup.sql ├── man └── rsqlserver-package.Rd ├── rsqlserver.Rproj ├── src.nocompile ├── .nuget │ └── packages.config ├── Makefile.mak ├── Makefile.win ├── install.libs.R ├── packages │ ├── .gitignore │ ├── LumenWorksCsvReader.3.9.1 │ │ ├── LumenWorksCsvReader.3.9.1.nupkg │ │ └── lib │ │ │ └── net20 │ │ │ ├── LumenWorks.Framework.IO.dll │ │ │ ├── LumenWorks.Framework.IO.pdb │ │ │ └── LumenWorks.Framework.IO.xml │ ├── R.NET.1.5.5 │ │ ├── R.NET.1.5.5.nupkg │ │ └── lib │ │ │ └── net40 │ │ │ ├── RDotNet.NativeLibrary.XML │ │ │ ├── RDotNet.NativeLibrary.dll │ │ │ ├── RDotNet.XML │ │ │ └── RDotNet.dll │ ├── log4net.2.0.8 │ │ ├── lib │ │ │ ├── net20-full │ │ │ │ ├── log4net.dll │ │ │ │ └── log4net.xml │ │ │ ├── net35-client │ │ │ │ ├── log4net.dll │ │ │ │ └── log4net.xml │ │ │ ├── net35-full │ │ │ │ ├── log4net.dll │ │ │ │ └── log4net.xml │ │ │ ├── net40-client │ │ │ │ ├── log4net.dll │ │ │ │ └── log4net.xml │ │ │ ├── net40-full │ │ │ │ ├── log4net.dll │ │ │ │ └── log4net.xml │ │ │ ├── net45-full │ │ │ │ ├── log4net.dll │ │ │ │ └── log4net.xml │ │ │ └── netstandard1.3 │ │ │ │ └── log4net.dll │ │ └── log4net.2.0.8.nupkg │ ├── repositories.config │ ├── xunit.1.9.2 │ │ ├── lib │ │ │ └── net20 │ │ │ │ ├── xunit.dll │ │ │ │ ├── xunit.dll.tdnet │ │ │ │ ├── xunit.runner.msbuild.dll │ │ │ │ ├── xunit.runner.tdnet.dll │ │ │ │ ├── xunit.runner.utility.dll │ │ │ │ └── xunit.xml │ │ ├── xunit.1.9.2.nupkg │ │ └── xunit.1.9.2.nuspec │ └── xunit.runners.1.9.2 │ │ ├── tools │ │ ├── HTML.xslt │ │ ├── NUnitXml.xslt │ │ ├── xunit.console.clr4.exe │ │ ├── xunit.console.clr4.exe.config │ │ ├── xunit.console.clr4.x86.exe │ │ ├── xunit.console.clr4.x86.exe.config │ │ ├── xunit.console.exe │ │ ├── xunit.console.exe.config │ │ ├── xunit.console.x86.exe │ │ ├── xunit.console.x86.exe.config │ │ ├── xunit.gui.clr4.exe │ │ ├── xunit.gui.clr4.x86.exe │ │ ├── xunit.gui.exe │ │ ├── xunit.gui.x86.exe │ │ ├── xunit.runner.msbuild.dll │ │ ├── xunit.runner.utility.dll │ │ └── xunit.runner.utility.xml │ │ ├── xunit.runners.1.9.2.nupkg │ │ └── xunit.runners.1.9.2.nuspec ├── rsqlserver.net.Test │ ├── App.config │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── TestSqlDataHelper.cs │ ├── packages.config │ └── rsqlserver.net.Test.csproj ├── rsqlserver.net.sln ├── rsqlserver.net.userprefs ├── rsqlserver.net │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── log4net.config │ ├── packages.config │ ├── rsqlserver.net.csproj │ └── src │ │ ├── SqlDataHelper.cs │ │ └── misc.cs └── runner │ └── rsqlserver.Test.runner.csproj └── tests ├── resources └── spSummaryProduct.sql ├── test-all.R └── testthat ├── helper.R ├── test-DBI-compliance.R ├── test-connections.R ├── test-extradbi.R ├── test-readdb.R ├── test-storedprocedure.R └── test-types-conversion.R /.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agstudy/rsqlserver/4f54256507affe3fe31c4e9b635a7bcfc1becece/.RData -------------------------------------------------------------------------------- /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^appveyor\.yml$ 4 | ^\.travis\.yml$ 5 | \.ci/ 6 | ^.*/\.nuget$ 7 | ^docker\.sh$ 8 | ^Dockerfile$ 9 | -------------------------------------------------------------------------------- /.ci/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ruaridhw/rclr:latest 2 | LABEL org.label-schema.license="GPL-2.0" \ 3 | org.label-schema.vcs-url="https://github.com/agstudy/rsqlserver" \ 4 | org.label-schema.vendor="" \ 5 | maintainer="Ruaridh Williamson " 6 | 7 | ENV workingdir /usr/local/R 8 | 9 | COPY . "$workingdir" 10 | WORKDIR "$workingdir" 11 | 12 | RUN Rscript -e "devtools::install_github('serhatcevikel/rClr@03f65ef')" 13 | 14 | CMD ["R"] 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | # User-specific files 4 | *.suo 5 | *.user 6 | *.sln.docstates 7 | # Build results 8 | [Dd]ebug/ 9 | [Rr]elease/ 10 | bin/x64/ 11 | build/ 12 | [Bb]in/ 13 | [Oo]bj/ 14 | # Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets 15 | !packages/*/build/ 16 | # MSTest test Results 17 | [Tt]est[Rr]esult*/ 18 | [Bb]uild[Ll]og.* 19 | # Visual C++ cache files 20 | ipch/ 21 | *.aps 22 | *.ncb 23 | *.opensdf 24 | *.sdf 25 | *.cachefile 26 | # Visual Studio profiler 27 | *.psess 28 | *.vsp 29 | *.vspx 30 | # Guidance Automation Toolkit 31 | *.gpState 32 | # ReSharper is a .NET coding add-in 33 | _ReSharper*/ 34 | *.[Rr]e[Ss]harper 35 | # TeamCity is a build add-in 36 | _TeamCity* 37 | # DotCover is a Code Coverage Tool 38 | *.dotCover 39 | # NCrunch 40 | *.ncrunch* 41 | .*crunch*.local.xml 42 | # Installshield output folder 43 | [Ee]xpress/ 44 | # DocProject is a documentation generator add-in 45 | DocProject/buildhelp/ 46 | DocProject/Help/*.HxT 47 | DocProject/Help/*.HxC 48 | DocProject/Help/*.hhc 49 | DocProject/Help/*.hhk 50 | DocProject/Help/*.hhp 51 | DocProject/Help/Html2 52 | DocProject/Help/html 53 | # Click-Once directory 54 | publish/ 55 | # Publish Web Output 56 | *.Publish.xml 57 | *.pubxml 58 | # NuGet Packages Directory 59 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line 60 | #packages/ 61 | # Windows Azure Build Output 62 | csx 63 | *.build.csdef 64 | # Windows Store app package directory 65 | AppPackages/ 66 | # Others 67 | sql/ 68 | *.Cache 69 | ClientBin/ 70 | [Ss]tyle[Cc]op.* 71 | ~$* 72 | *~ 73 | *.dbmdl 74 | *.[Pp]ublish.xml 75 | *.pfx 76 | *.publishsettings 77 | # RIA/Silverlight projects 78 | Generated_Code/ 79 | # Backup & report files from converting an old project file to a newer 80 | # Visual Studio version. Backup files are not needed, because we have git ;-) 81 | _UpgradeReport_Files/ 82 | Backup*/ 83 | UpgradeLog*.XML 84 | UpgradeLog*.htm 85 | # SQL Server files 86 | App_Data/*.mdf 87 | App_Data/*.ldf 88 | # ========================= 89 | # Windows detritus 90 | # ========================= 91 | # Windows image file caches 92 | Thumbs.db 93 | ehthumbs.db 94 | # Folder config file 95 | Desktop.ini 96 | # Recycle Bin used on file shares 97 | $RECYCLE.BIN/ 98 | # Mac crap 99 | .DS_Store 100 | .Rproj.user 101 | #========================= 102 | #Markdwon 103 | #======================== 104 | *.html 105 | .RData 106 | wiki 107 | .Rhistory 108 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "wiki"] 2 | path = wiki 3 | url = https://github.com/agstudy/rsqlserver.wiki.git 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | services: 2 | - docker 3 | 4 | before_install: 5 | - docker pull microsoft/mssql-server-linux:latest 6 | - docker network create sqlserver_net 7 | - | 8 | docker run -e 'ACCEPT_EULA=Y' -e 'MSSQL_SA_PASSWORD=Password12!' \ 9 | --network sqlserver_net -p 1433:1433 --name mssqldb -d microsoft/mssql-server-linux 10 | - sleep 90 11 | - docker cp inst/setup.sql mssqldb:. 12 | - | 13 | docker exec -t mssqldb /opt/mssql-tools/bin/sqlcmd \ 14 | -S localhost -U SA -P 'Password12!' \ 15 | -i setup.sql 16 | 17 | install: 18 | - docker build -t rsqlserver -f .ci/Dockerfile . 19 | 20 | script: 21 | - | 22 | docker run -e CI=true -e TRAVIS=true -e CONTINUOUS_INTEGRATION=true \ 23 | -t --network sqlserver_net --name pkgcheck rsqlserver Rscript \ 24 | -e 'devtools::install_dev_deps()' \ 25 | -e 'devtools::check(document = FALSE, check_dir = ".")' 26 | - docker cp pkgcheck:/usr/local/R/rsqlserver.Rcheck/00check.log . 27 | - cat 00check.log 28 | - if cat 00check.log | grep -q ERROR ; then exit 1; fi 29 | # Choose to fail if warnings are present in R CMD CHECK (comment this out for now) 30 | #- if cat 00check.log | grep -q WARNING ; then exit 1; fi 31 | - exit 0 32 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: rsqlserver 2 | Type: Package 3 | Title: SQL Server interface for R 4 | Version: 1.0 5 | Description: SQL Server database interface (DBI) driver for R. 6 | This is a DBI-compliant SQL Server driver based on the 7 | .NET Framework Data Provider for SQL Server; `System.Data.SqlClient`. 8 | Authors@R: c( 9 | person("Amine", "Gassem", , "contact@ag-study.com", c("cre", "aut")), 10 | person("Ruaridh", "Williamson", , "ruaridh.williamson@gmail.com", role = "aut") 11 | ) 12 | Depends: 13 | rClr, 14 | methods 15 | Imports: DBI 16 | Suggests: 17 | testthat, 18 | knitr, 19 | xtable 20 | License: GPL-2 21 | Collate: 22 | "zzz.R" 23 | "dbObjectId.R" 24 | "DBIDriver.R" 25 | "DBIConnection.R" 26 | "DBIResult.R" 27 | "DBIConvenience.R" 28 | "DBITransaction.R" 29 | "DBIMetaInfo.R" 30 | "rsqlImpl.R" 31 | LazyLoad: true 32 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ruaridhw/rclr:latest 2 | LABEL org.label-schema.license="GPL-2.0" \ 3 | org.label-schema.vcs-url="https://github.com/agstudy/rsqlserver" \ 4 | org.label-schema.vendor="" \ 5 | maintainer="Ruaridh Williamson " 6 | 7 | ENV workingdir /usr/local/R 8 | 9 | COPY . "$workingdir" 10 | WORKDIR "$workingdir" 11 | 12 | RUN Rscript -e "devtools::install_github('serhatcevikel/rClr@03f65ef');devtools::install(pkg = '.')" 13 | 14 | CMD ["R"] 15 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | import(rClr) 2 | import(methods) 3 | import(DBI) 4 | 5 | 6 | 7 | 8 | exportClasses( 9 | SqlServerDriver, SqlServerResult, 10 | SqlServerTransaction) 11 | 12 | exportMethods( 13 | # ## dbDriver 14 | dbGetInfo,dbDriver, dbUnloadDriver, dbListConnections, 15 | # 16 | # ## DBIConnection 17 | dbConnect, dbDisconnect, dbSendQuery, dbGetQuery, dbGetException, 18 | dbListResults, 19 | # 20 | # ## DBIConnection: Convenience 21 | dbListTables, dbReadTable, dbWriteTable, dbExistsTable, dbRemoveTable, 22 | dbListFields,make.db.names, 23 | # 24 | # ## DBIConnection: Transaction management 25 | dbCommit, dbRollback, 26 | # 27 | # ## DBIConnection: Stored procedures 28 | dbCallProc, 29 | # 30 | # ## DBIResult 31 | fetch, dbClearResult, 32 | dbColumnInfo, dbGetStatement, 33 | dbHasCompleted, 34 | # #dbGetRowsAffected, dbGetRowCount, 35 | # 36 | # ## DBIResult: Data conversion 37 | dbSetDataMappings, 38 | # 39 | # ## DBI extensions 40 | dbGetScalar,dbNonQuery, 41 | dbGetRowCount, 42 | dbTransaction,dbBulkCopy,dbBulkWrite, 43 | ## stored procedure 44 | dbCallProcedure) 45 | 46 | 47 | 48 | export(SqlServer) 49 | -------------------------------------------------------------------------------- /R/.gitignore: -------------------------------------------------------------------------------- 1 | .history 2 | -------------------------------------------------------------------------------- /R/DBIConnection.R: -------------------------------------------------------------------------------- 1 | ## 2 | ## Class: DBITransaction 3 | ## 4 | 5 | 6 | .NetObjFromPtr <- 7 | function(obj, clrtype = NULL){ 8 | if(exists("createReturnedObject",asNamespace("rClr"))) 9 | rClr:::createReturnedObject(obj, clrtype) 10 | else 11 | rClr:::mkClrObjRef(obj, clrtype) 12 | } 13 | setClass("SqlServerTransaction", contains=c("SqlServerObject")) 14 | setClass("SqlServerConnection", 15 | contains=c("DBIConnection", "SqlServerObject"), 16 | slots=c(trans="externalptr") 17 | ) 18 | 19 | 20 | setGeneric("dbTransaction", 21 | function(conn,name="R.transaction",...) 22 | standardGeneric("dbTransaction") 23 | ) 24 | 25 | setMethod("dbTransaction", 26 | signature(conn='SqlServerConnection',name='character'), 27 | def=function(conn,name="R.transaction",...){ 28 | if(dbGetInfo(conn,'State')$State ==1){ 29 | clr.conn <- .NetObjFromPtr(conn@Id) 30 | trans <- clrCall(clr.conn,"BeginTransaction",name) 31 | Id = clrGetExtPtr(trans) 32 | return(new("SqlServerConnection", 33 | Id = conn@Id, 34 | trans=clrGetExtPtr(trans))) 35 | 36 | } 37 | return(NULL) 38 | }, 39 | valueClass = "SqlServerConnection" 40 | ) 41 | 42 | 43 | setMethod("dbCommit", 44 | signature(conn="SqlServerConnection"), 45 | function(conn, ...) { 46 | transaction <- .NetObjFromPtr(conn@trans) 47 | clrCall(transaction,'Commit') 48 | TRUE 49 | } 50 | ) 51 | 52 | setMethod("dbRollback", 53 | signature(conn = "SqlServerConnection"), 54 | function(conn, ...) { 55 | transaction <- .NetObjFromPtr(conn@trans) 56 | clrCall(transaction,'Rollback') 57 | TRUE 58 | } 59 | ) 60 | 61 | 62 | ## 63 | ## Class: DBIConnection 64 | ## 65 | 66 | 67 | 68 | setMethod("dbConnect", "SqlServerDriver", 69 | def = function(drv, ...) { 70 | args <- list(...) 71 | if ("url" %in% names(args) && !is.null(args$url)) 72 | sqlServerConnectionUrl(args$url) 73 | else 74 | sqlServerNewConnection(drv, ...) 75 | }, 76 | valueClass = "SqlServerConnection" 77 | ) 78 | 79 | setMethod("dbConnect", "character", 80 | def = function(drv, ...) dbConnect(dbDriver(drv), ...), 81 | valueClass = "SqlServerConnection" 82 | ) 83 | 84 | ## clone a connection 85 | setMethod("dbConnect", "SqlServerConnection", 86 | def = function(drv, ...) sqlServerCloneConnection(drv, ...), 87 | valueClass = "SqlServerConnection" 88 | ) 89 | 90 | setMethod("dbDisconnect", "SqlServerConnection", 91 | def = function(conn, ...) sqlServerCloseConnection(conn, ...), 92 | valueClass = "logical" 93 | ) 94 | 95 | 96 | 97 | 98 | 99 | # the sql server connection is managed by 100 | # enum ConnectionState 101 | # Closed = 0, 102 | # Open = 1, 103 | # Connecting = 2, 104 | # Executing = 4, 105 | # Fetching = 8, 106 | # Broken = 16, 107 | setMethod("dbListResults", "SqlServerConnection", 108 | def = function(conn, ...) { 109 | state = dbGetInfo(conn, "State")$State 110 | switch(state , 111 | "1" = NULL, 112 | "0" = list(action='OpenMe'), 113 | "16" = list(action='CloseAndOpenMe')) 114 | } 115 | ) 116 | 117 | setMethod("summary", "SqlServerConnection", 118 | def = function(object, ...) sqlServerDescribeConnection(object, ...) 119 | ) 120 | setMethod("dbGetException", "SqlServerConnection", 121 | def = function(conn, ...){ 122 | if(!isIdCurrent(conn)) 123 | stop(paste("expired", class(conn))) 124 | }, 125 | valueClass = "list" 126 | ) 127 | 128 | 129 | ## TODO use SqlConnectionStringBuilder Class (.net 4.5) 130 | ## http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnectionstringbuilder.aspx 131 | 132 | sqlServerNewConnection <- 133 | function(drv, user=NULL, 134 | password=NULL, host=NULL, 135 | trusted=FALSE, 136 | dbname='TEST_RSQLSERVER', 137 | timeout=30,...) 138 | { 139 | if(!isIdCurrent(drv)) 140 | stop("expired manager") 141 | if (!is.null(host) && !is.character(host)) 142 | stop("Argument host must be a string or NULL") 143 | if (is.null(timeout) || !is.numeric(timeout)) 144 | stop("Argument timeout must be an integer value") 145 | if (is.null(trusted) || !is.logical(trusted)) 146 | stop("Argument trusted must be a boolean") 147 | url <- { 148 | url <- paste(paste0("server=",host), 149 | paste0("connection timeout=",timeout), 150 | sep=";") 151 | 152 | if(!trusted){ 153 | if (!is.null(password) && !is.character(password)) 154 | stop("Argument password must be a string or NULL") 155 | if (!is.null(user) && !is.character(user)) 156 | stop("Argument username must be a string or NULL") 157 | url <- paste(url,paste0("user id=",user), 158 | paste0("password=",password),sep=';') 159 | }else 160 | url <- paste(url , "Trusted_Connection=yes",sep=';') 161 | if (!is.null(dbname) && is.character(dbname)) 162 | url <- paste(url,paste0("Database=",dbname),sep=";") 163 | url 164 | } 165 | sqlServerConnectionUrl(url) 166 | } 167 | 168 | sqlServerConnectionUrl <- 169 | function(url){ 170 | if (is.null(url) || !is.character(url)) 171 | stop("Argument url must be a not NULL string ") 172 | 173 | id = clrNew("System.Data.SqlClient.SqlConnection",url) 174 | trans = clrNew('System.Object') 175 | clrCall(id,'Open') 176 | new("SqlServerConnection", 177 | Id = clrGetExtPtr(id), 178 | trans = clrGetExtPtr(trans)) 179 | } 180 | 181 | 182 | sqlServerCloseConnection <- 183 | function(conn,...) 184 | { 185 | if(!isIdCurrent(conn)){ 186 | warning(paste("expired SqlServerConnection")) 187 | return(TRUE) 188 | } 189 | obj <- .NetObjFromPtr(conn@Id) 190 | clrCall(obj,'Close') 191 | TRUE 192 | } 193 | 194 | 195 | sqlServerConnectionInfo <- 196 | function(dbObj,what,...){ 197 | if(!isIdCurrent(dbObj)) 198 | stop(paste("expired", class(dbObj), deparse(substitute(dbObj)))) 199 | conn <- .NetObjFromPtr(dbObj@Id) 200 | info <- vector("list", length = length(clrGetProperties(conn))) 201 | sqlDataHelper <- clrNew("rsqlserver.net.SqlDataHelper") 202 | for (prop in clrGetProperties(conn)) 203 | info[[prop]] <- clrCall(sqlDataHelper,"GetConnectionProperty",conn, 204 | prop) 205 | info <- as.list(unlist(info)) 206 | if(!missing(what)) 207 | info[what] 208 | else 209 | info 210 | } 211 | 212 | 213 | sqlServerCloneConnection <- 214 | function(conn,...){ 215 | strConnection = dbGetInfo(conn)$ConnectionString 216 | sqlServerConnectionUrl(strConnection) 217 | } 218 | -------------------------------------------------------------------------------- /R/DBIConvenience.R: -------------------------------------------------------------------------------- 1 | ## convenience methods 2 | 3 | 4 | 5 | 6 | setMethod("dbListTables", "SqlServerConnection", 7 | def = function(conn, ...){ 8 | tbls <- dbGetQuery(conn, "select name from sys.tables") 9 | if(nrow(tbls)>0) 10 | tbls <- tbls[,1] 11 | else 12 | tbls <- character() 13 | tbls 14 | }, 15 | valueClass = "character" 16 | ) 17 | 18 | setMethod("dbReadTable", signature(conn="SqlServerConnection", name="character"), 19 | def = function(conn, name, ...) sqlServerReadTable(conn, name, ...), 20 | valueClass = "data.frame" 21 | ) 22 | 23 | setMethod("dbWriteTable", 24 | signature(conn="SqlServerConnection", name="character", value="data.frame"), 25 | def = function(conn, name, value, ...){ 26 | sqlServerWriteTable(conn, name, value, ...) 27 | }, 28 | valueClass = "logical" 29 | ) 30 | 31 | ## write table from filename (TODO: connections) 32 | setMethod("dbWriteTable", 33 | signature(conn="SqlServerConnection", name="character", value="character"), 34 | def = function(conn, name, value, ...){ 35 | sqlServerImportFile(conn, name, value, ...) 36 | }, 37 | valueClass = "logical" 38 | ) 39 | ## TODO : manage case here 40 | setMethod("dbExistsTable", 41 | signature(conn="SqlServerConnection", name="character"), 42 | def = function(conn, name, ...){ 43 | req <- paste0("SELECT OBJECT_ID('",name,"','U') AS 'Object ID';") 44 | val <- dbGetScalar(conn, req) 45 | !is.null(val) 46 | }, 47 | valueClass = "logical" 48 | ) 49 | 50 | 51 | 52 | setMethod("dbRemoveTable", 53 | signature(conn="SqlServerConnection", name="character"), 54 | def = function(conn,name,...)dropTable(conn,name,...) , 55 | valueClass = "logical" 56 | ) 57 | 58 | describe.query <- 59 | "SELECT 60 | c.name Column_Name, 61 | t.Name Data_type, 62 | CAST(c.max_length as int)Max_Length, 63 | CAST(c.precision as int) precision, 64 | CAST(c.scale as int) scale, 65 | CAST( c.is_nullable as int), 66 | CAST(ISNULL(i.is_primary_key, 0) as int) isKey 67 | FROM 68 | sys.columns c 69 | INNER JOIN 70 | sys.types t ON c.system_type_id = t.system_type_id 71 | LEFT OUTER JOIN 72 | sys.index_columns ic ON ic.object_id = c.object_id AND ic.column_id = c.column_id 73 | LEFT OUTER JOIN 74 | sys.indexes i ON ic.object_id = i.object_id AND ic.index_id = i.index_id 75 | WHERE 76 | c.object_id = OBJECT_ID('%s')" 77 | 78 | 79 | 80 | ## return field names (no metadata) 81 | setMethod("dbListFields", 82 | signature(conn="SqlServerConnection", name="character"), 83 | def = function(conn, name, ...){ 84 | flds <- dbGetQuery(conn, sprintf(describe.query, name))[,1] 85 | if(length(flds)==0) 86 | flds <- character() 87 | flds 88 | }, 89 | valueClass = "character" 90 | ) 91 | 92 | 93 | # implementations --------------------------------------------------------- 94 | 95 | 96 | 97 | sqlServerReadTable <- 98 | function(con, name, row.names = "row_names", check.names = TRUE, ...) 99 | ## Use NULL, "", or 0 as row.names to prevent using any field as row.names. 100 | { 101 | out <- dbGetQuery(con, paste("SELECT * from", name)) 102 | if(check.names) 103 | names(out) <- make.names(names(out), unique = TRUE) 104 | ## should we set the row.names of the output data.frame? 105 | nms <- names(out) 106 | j <- switch(mode(row.names), 107 | "character" = if(row.names=="") 0 else 108 | match(tolower(row.names), tolower(nms), 109 | nomatch = if(missing(row.names)) 0 else -1), 110 | "numeric" = row.names, 111 | "NULL" = 0, 112 | 0) 113 | if(j==0) 114 | return(out) 115 | if(j<0 || j>ncol(out)){ 116 | warning("row.names not set on output data.frame (non-existing field)") 117 | return(out) 118 | } 119 | rnms <- out[,j] 120 | if(all(!duplicated(rnms))){ 121 | out <- out[,-j, drop = FALSE] 122 | attr(out, "row.names") <- rnms 123 | } else warning("row.names not set on output (duplicate elements in field)") 124 | out 125 | } 126 | 127 | dbCreateTable <- function(con, name, cnames, ctypes) { 128 | stmt <- sprintf('CREATE TABLE [%s] (%s)', name, 129 | paste(cnames, ctypes, collapse = ",")) 130 | if (!dbExistsTable(con, name)) { 131 | rc <- try(dbNonQuery(con, stmt)) 132 | !inherits(rc, "try-error") 133 | } else { 134 | FALSE 135 | } 136 | } 137 | 138 | ## the following is almost exactly from the RMysql driver 139 | 140 | sqlServerWriteTable <- 141 | function(con, name, value, field.types, row.names = TRUE, 142 | overwrite = FALSE, append = FALSE, ..., allow.keywords = FALSE) 143 | { 144 | if(overwrite && append) 145 | stop("overwrite and append cannot both be TRUE") 146 | # validate name 147 | name <- as.character(name) 148 | if (length(name) != 1L) 149 | stop("'name' must be a single string") 150 | if(row.names) 151 | { 152 | row_names = attr(value,"row.names") 153 | value <- cbind(row_names=row_names, value) 154 | attr(value$row_names,"class") <- attr(row_names,"class") 155 | } 156 | 157 | if(missing(field.types) || is.null(field.types)){ 158 | field.types <- lapply(value, R2DbType) 159 | } 160 | names(field.types) <- make.db.names(con, names(field.types), 161 | allow.keywords = allow.keywords) 162 | 163 | 164 | value <- sqlServer.data.frame(value,field.types) 165 | 166 | ## Do we need to clone the connection (ie., if it is in use)? 167 | if(length(dbListResults(con))!=0){ 168 | new.con <- dbConnect(con) 169 | on.exit(dbDisconnect(new.con)) 170 | } else { 171 | new.con <- con 172 | } 173 | ## con <- dbTransaction(new.con,name='sqlServerWriteTable') 174 | cnames <- names(field.types) 175 | ctypes <- field.types 176 | res <- tryCatch({ 177 | (function(con,name,cnames,ctypes){ 178 | if (dbExistsTable(con, name)){ 179 | if (overwrite) 180 | { 181 | dbRemoveTable(con, name) 182 | dbCreateTable(con, name, cnames, ctypes) 183 | } 184 | else if (append) 185 | drop <- FALSE 186 | else 187 | stop("table or view already exists") 188 | } 189 | else 190 | dbCreateTable(con, name, cnames, ctypes) 191 | })(con,name,cnames,ctypes) 192 | insert.into(con,name,cnames,value,row.names) 193 | TRUE 194 | ## dbCommit(con) 195 | },error = function(e) { 196 | stop(sqlException.Message(e)) 197 | }) 198 | } 199 | 200 | 201 | 202 | 203 | insert.into <- function(con,name,cnames,value,row.names){ 204 | 205 | if(nrow(value)<1000) { 206 | stmt.header <- sprintf('INSERT INTO %s (%s)', name, 207 | paste(cnames,collapse=',')) 208 | is.char <- sapply(value,is.character) 209 | replace.missings <- 210 | function(x)ifelse(is.na(x),'',x) 211 | value[is.char] <- vapply(value[is.char],replace.missings, 212 | rep('character',nrow(value))) 213 | stmt.body <- paste0('VALUES (',do.call(paste, 214 | c(value, sep=",",collapse='),(')),')') 215 | ## numeric missing values replaced by NULL 216 | if(any(is.na(value))) 217 | stmt.body <- gsub('NA','NULL',stmt.body) 218 | stmt = paste(stmt.header,stmt.body,sep='\n') 219 | dbNonQuery(con, stmt, data = value) 220 | }else{ 221 | ##dbCommit(con) 222 | bulk.copy(con,name,value) 223 | } 224 | } 225 | 226 | 227 | bulk.copy <- function(con,name,value,...){ 228 | if(is.data.frame(value)){ 229 | id = tempfile() 230 | on.exit(unlink(id)) 231 | write.csv(value,file=id,row.names=FALSE,na="",...) 232 | bulk.copy.file(con,name,id) 233 | } 234 | } 235 | 236 | bulk.copy.file <- function(con,name,value,headers=TRUE,delim=","){ 237 | con.string = dbGetInfo(con)$ConnectionString 238 | if (!dbExistsTable(con,name)) 239 | stop("bulk copy table does not exist") 240 | if (!is.null(value) && file.exists(value)) 241 | lapply(value, function(x) clrCallStatic("rsqlserver.net.misc","SqlBulkCopy",con.string,x,name,headers,delim)) 242 | else 243 | stop("one or more files are null or do not exist") 244 | 245 | } 246 | 247 | bulk.write.file <- function(con,name,value,headers=TRUE,delim=","){ 248 | con.string = dbGetInfo(con)$ConnectionString 249 | if (!dbExistsTable(con, name)) 250 | stop("table does not exist") 251 | else if (file.exists(value)) 252 | file.remove(value) 253 | clrCallStatic("rsqlserver.net.misc","SqlBulkWrite",con.string,value,name,headers,delim) 254 | 255 | } 256 | 257 | 258 | 259 | 260 | dbCreateTable <- function(con, name, cnames, ctypes) 261 | { 262 | stmt <- sprintf('CREATE TABLE "%s" (%s)', name, 263 | paste(cnames, ctypes, collapse = ",")) 264 | if(!dbExistsTable(con, name)){ 265 | rc <- try(dbNonQuery(con, stmt),silent=TRUE) 266 | !inherits(rc, "try-error") 267 | }else FALSE 268 | } 269 | 270 | dropTable <- function(con, name,...) 271 | { 272 | # validate name 273 | name <- as.character(name) 274 | if (length(name) != 1L) 275 | stop("'name' must be a single string") 276 | if(dbExistsTable(con, name)){ 277 | rc <- try({stmt <- sprintf('DROP TABLE "%s"', name) 278 | dbNonQuery(con, stmt)}) 279 | !inherits(rc, "try-error") 280 | }else FALSE 281 | } 282 | 283 | dropProc <- function(con,sp.name){ 284 | line1 <- paste0("IF NOT EXISTS (SELECT * FROM sys.objects", 285 | " WHERE object_id = OBJECT_ID(N'[", 286 | sp.name,"]') AND type in (N'P', N'PC'))") 287 | line2 <- paste0("DROP PROCEDURE [",sp.name,"]") 288 | stmt = paste(line1,line2,sep='\n') 289 | rc <- try(dbNonQuery(con, stmt)) 290 | !inherits(rc, "try-error") 291 | } 292 | 293 | -------------------------------------------------------------------------------- /R/DBIDriver.R: -------------------------------------------------------------------------------- 1 | .SQLserverPkgName <- "SQLServer" 2 | .SQLserverPkgRCS <- "$Id$" 3 | .SQLserver.NA.string <- "\\N" ## on input SQLite interprets \N as NULL (NA) 4 | 5 | 6 | setOldClass("data.frame") ## to appease setMethod's signature warnings... 7 | 8 | ## 9 | ## Class: DBIObject 10 | ## 11 | setClass("SqlServerObject", contains=c("DBIObject","dbObjectId", "VIRTUAL")) 12 | setClass("SqlServerDriver", contains=c("DBIDriver", "SqlServerObject")) 13 | 14 | SqlServer <- 15 | function(max.con = 100L, fetch.default.rec = 500, force.reload = FALSE, 16 | shared.cache=FALSE) 17 | { 18 | sqlServerInitDriver(max.con, fetch.default.rec, force.reload, shared.cache) 19 | } 20 | 21 | ## coerce (extract) any SqlServerObject into a SqlServerDriver 22 | setAs("SqlServerObject", "SqlServerDriver", 23 | def = function(from) { 24 | new("SqlServerDriver", Id = from@Id) 25 | } 26 | ) 27 | 28 | 29 | setMethod("dbUnloadDriver", "SqlServerDriver", 30 | def = function(drv, ...) sqlServerCloseDriver(drv, ...), 31 | valueClass = "logical" 32 | ) 33 | 34 | setMethod("dbGetInfo", "SqlServerDriver", 35 | def = function(dbObj, ...) sqlServerDriverInfo(dbObj, ...) 36 | ) 37 | 38 | setMethod("dbListConnections", "SqlServerDriver", 39 | def = function(drv, ...) dbGetInfo(drv, "connectionIds")[[1]] 40 | ) 41 | 42 | setMethod("summary", "SqlServerDriver", 43 | def = function(object, ...) sqlServerDescribeDriver(object, ...) 44 | ) 45 | 46 | -------------------------------------------------------------------------------- /R/DBIMetaInfo.R: -------------------------------------------------------------------------------- 1 | setMethod("dbGetInfo", "SqlServerConnection", 2 | def = function(dbObj, ...) 3 | .sqlServerConnectionInfo(dbObj, ...) 4 | ) 5 | 6 | 7 | # dbGetStatement(res, ...) # statement that produced result "res" 8 | # dbGetRowCount(res, ...) # number of rows fetched so far 9 | # dbGetRowsAffected(res, ...) # number of affected rows (e.g., DELETE) 10 | # dbColumnInfo(res, ...) # result set data types 11 | # dbHasCompleted(res, ...) # are there more rows to fetch on "res"? 12 | 13 | 14 | ## return -1 since it is impossible to get the number of row 15 | ## number of rows fetched so far 16 | setMethod("dbGetRowCount", "SqlServerResult", 17 | def = function(res, ...) {-1 18 | }) 19 | 20 | 21 | 22 | ## TODO: 23 | setMethod("dbHasCompleted", 24 | "SqlServerResult", 25 | def = function(res, ...) { 26 | dbGetInfo(res, "HasRows")[[1]] != "1" 27 | } 28 | , 29 | valueClass = "logical" 30 | ) 31 | 32 | .sqlServerConnectionInfo <- 33 | function(dbObj,what,...){ 34 | if(!isIdCurrent(dbObj)) 35 | stop(paste("expired", class(dbObj), deparse(substitute(dbObj)))) 36 | conn <- .NetObjFromPtr(dbObj@Id) 37 | 38 | info <- vector("list", length = length(clrGetProperties(conn))) 39 | sqlDataHelper <- clrNew("rsqlserver.net.SqlDataHelper") 40 | for (prop in clrGetProperties(conn)) 41 | info[[prop]] <- clrCall(sqlDataHelper,"GetConnectionProperty",conn,prop) 42 | info <- as.list(unlist(info)) 43 | if(!missing(what)) 44 | info[what] 45 | else 46 | info 47 | } 48 | 49 | .sqlServerGetProperty <- 50 | function(dbObj,prop,...){ 51 | dataReader <- .NetObjFromPtr(dbObj@Id) 52 | sqlDataHelper <- clrNew("rsqlserver.net.SqlDataHelper",dataReader) 53 | clrGet(sqlDataHelper,'Fetched') 54 | } 55 | 56 | -------------------------------------------------------------------------------- /R/DBIResult.R: -------------------------------------------------------------------------------- 1 | setClass("SqlServerResult", 2 | contains=c("DBIResult", "SqlServerObject"), 3 | slots=c(.fetched="numeric")) 4 | # setMethod("initialize", signature(.Object = "SqlServerResult"), 5 | # function(.Object, ...){ 6 | # .Object@fetched = 0 7 | # } 8 | 9 | setMethod("dbClearResult", "SqlServerResult", 10 | def = function(res, ...) sqlServerCloseResult(res, ...), 11 | valueClass = "logical" 12 | ) 13 | 14 | setMethod("fetch", signature(res="SqlServerResult", n="numeric"), 15 | def = function(res, n , ...){ 16 | out <- .sqlServerFetch(res, n, ...) 17 | if(is.null(out)) 18 | out <- data.frame(out) 19 | out 20 | }, 21 | valueClass = "data.frame" 22 | ) 23 | 24 | 25 | setMethod("fetch", 26 | signature(res="SqlServerResult", n="missing"), 27 | def = function(res, ...){ 28 | out <- .sqlServerFetch(res, n =-1, ...) 29 | if(is.null(out)) 30 | out <- data.frame(out) 31 | out 32 | }, 33 | valueClass = "data.frame" 34 | ) 35 | 36 | 37 | setMethod("dbSendQuery", 38 | signature(conn = "SqlServerConnection", statement = "character"), 39 | def = function(conn, statement,...) sqlServerExecStatement(conn, statement,...), 40 | valueClass = "SqlServerResult" 41 | ) 42 | 43 | setMethod("dbGetQuery", 44 | signature(conn = "SqlServerConnection", statement = "character"), 45 | def = function(conn, statement, ...) sqlServerExecRetrieve(conn, statement, ...) 46 | ) 47 | 48 | setGeneric("dbGetScalar", function(conn, statement, ...){ 49 | value <- standardGeneric("dbGetScalar") 50 | if (isS4(value)){ ## mono version !! 51 | vv <- clrCall(value,"ToString") 52 | if(!nzchar(vv)) value <- NULL 53 | } 54 | if (!is.atomic(value) || length(value) > 1L) ## valuecan be NULL 55 | stop("not a scalar atomic vector") 56 | value 57 | }) 58 | setMethod("dbGetScalar", 59 | signature(conn = "SqlServerConnection", statement = "character"), 60 | def = function(conn, statement, ...) sqlServerExecScalar(conn, statement, ...), 61 | ) 62 | 63 | 64 | setGeneric("dbNonQuery", function(conn, statement, ...) 65 | standardGeneric("dbNonQuery") 66 | ) 67 | setMethod("dbNonQuery", 68 | signature(conn = "SqlServerConnection", statement = "character"), 69 | def = function(conn, statement, ...) sqlServerNonQuery(conn, statement, ...) 70 | ) 71 | 72 | 73 | 74 | setMethod("dbGetInfo", "SqlServerResult", 75 | def = function(dbObj, ...) sqlServerResultInfo(dbObj, ...), 76 | valueClass = "list" 77 | ) 78 | 79 | setGeneric("dbBulkCopy", function(conn,name,value,headers,delim,...) 80 | standardGeneric("dbBulkCopy") 81 | ) 82 | 83 | setMethod("dbBulkCopy", 84 | signature(conn ="SqlServerConnection",value="data.frame",name="character"), 85 | def = function(conn,name,value,...) bulk.copy(conn,name,value,...) 86 | ) 87 | setMethod("dbBulkCopy", 88 | signature(conn ="SqlServerConnection",value="character",name="character"), 89 | def = function(conn,name,value,...) bulk.copy.file(conn,name,value,...) 90 | ) 91 | setMethod("dbBulkCopy", 92 | signature(conn ="SqlServerConnection",value="character",name="character",headers="logical",delim="character"), 93 | def = function(conn,name,value,headers,delim) bulk.copy.file(conn,name,value,headers,delim) 94 | ) 95 | 96 | setGeneric("dbBulkWrite", function(conn,name,value,headers,delim) 97 | standardGeneric("dbBulkWrite") 98 | ) 99 | setMethod("dbBulkWrite", 100 | signature(conn ="SqlServerConnection",value="character",name="character",headers="missing",delim="missing"), 101 | def = function(conn,name,value) bulk.write.file(conn,name,value) 102 | ) 103 | setMethod("dbBulkWrite", 104 | signature(conn ="SqlServerConnection",value="character",name="character",headers="logical",delim="character"), 105 | def = function(conn,name,value,headers,delim) bulk.write.file(conn,name,value,headers,delim) 106 | ) 107 | 108 | 109 | setGeneric("dbCallProcedure", 110 | function(conn,name,...) 111 | standardGeneric("dbCallProcedure")) 112 | 113 | setMethod("dbCallProcedure", 114 | signature(conn="SqlServerConnection",name="character"), 115 | def =function(conn,name,...) .sqlExecuteProc(conn,name,...) 116 | ) 117 | 118 | 119 | .sqlExecuteProc <- 120 | function(con,name,...){ 121 | .NotYetImplemented() 122 | } 123 | 124 | 125 | 126 | 127 | ### internal implementations 128 | ### helper functions 129 | 130 | get.command <- function(conn,stmt,...){ 131 | if(!isIdCurrent(conn)){ 132 | warning(paste("expired SqlServerConnection")) 133 | return(TRUE) 134 | } 135 | clr.conn <- .NetObjFromPtr(conn@Id) 136 | cmd <- clrNew("System.Data.SqlClient.SqlCommand",stmt,clr.conn) 137 | ll <- as.list(match.call()[-1]) 138 | if(("timeout") %in% names(ll)) 139 | clrSet(cmd,"CommandTimeout",as.integer(ll[["timeout"]])) 140 | if(isTransaction(conn)){ 141 | trans <- .NetObjFromPtr(conn@trans) 142 | clrCall(cmd,'set_Transaction',trans) 143 | } 144 | cmd 145 | } 146 | 147 | 148 | sqlServerExecStatement <- 149 | function(conn,statement,...) 150 | { 151 | cmd <- get.command(conn,statement,...) 152 | res <- try(clrCall(cmd,'ExecuteReader'),silent=TRUE) 153 | if (inherits(res, "try-error")){ 154 | stop(sqlException.Message(res)) 155 | } 156 | new("SqlServerResult", Id = clrGetExtPtr(res),.fetched=0) 157 | } 158 | 159 | sqlServerExecScalar <- 160 | function(conn,statement,...) 161 | { 162 | cmd <- get.command(conn,statement,...) 163 | res <- try(clrCall(cmd,'ExecuteScalar'),silent=TRUE) 164 | if (inherits(res, "try-error")){ 165 | stop(sqlException.Message(res)) 166 | } 167 | res 168 | 169 | } 170 | 171 | sqlServerNonQuery <- 172 | function(conn,statement,...) 173 | { 174 | cmd <- get.command(conn,statement,...) 175 | res <- try(clrCall(cmd,'ExecuteNonQuery'),silent=TRUE) 176 | if (inherits(res, "try-error")){ 177 | stop(sqlException.Message(res)) 178 | } 179 | } 180 | 181 | 182 | 183 | 184 | 185 | sqlException.Message <- 186 | function(exception){ 187 | message <- 188 | if(inherits(exception,'simpleError')) 189 | message(exception) 190 | else conditionMessage(attr(exception,"condition")) 191 | readLines(textConnection(message),n=2)[2] 192 | } 193 | 194 | 195 | .sqlServerFetch <- 196 | function(res,n){ 197 | n <- as(n, "integer") 198 | dataReader <- .NetObjFromPtr(res@Id) 199 | ncols <- clrGet(dataReader,"FieldCount") 200 | if(ncols==0) return(NULL) 201 | sqlDataHelper <- clrNew("rsqlserver.net.SqlDataHelper",dataReader) 202 | Cnames <- clrGet(sqlDataHelper,'Cnames') 203 | out <- vector('list',ncols) 204 | out <- if (n < 0L) { ## infinite pull 205 | stride <- 32768L ## start fairly small to support tiny queries and increase later 206 | while ((nrec <- clrCall(sqlDataHelper,'Fetch',stride)) > 0L) { 207 | res.Dict <- clrGet(sqlDataHelper,"ResultSet") 208 | for (i in seq.int(Cnames)){ 209 | out[[i]] <- if(is.null(out[[i]])) 210 | clrCall(res.Dict,'get_Item',Cnames[i]) 211 | else 212 | c(out[[i]], clrCall(res.Dict,'get_Item',Cnames[i])) 213 | } 214 | res@.fetched <- res@.fetched + nrec 215 | if (nrec < stride) break 216 | stride <- 524288L # 512k 217 | } 218 | out 219 | } 220 | else { 221 | nrec <- clrCall(sqlDataHelper,'Fetch',as.integer(n)) 222 | res@.fetched <- res@.fetched +nrec 223 | res.Dict <- clrGet(sqlDataHelper,"ResultSet") 224 | for (i in seq.int(Cnames)) 225 | out[[i]] <- clrCall(res.Dict,'get_Item',Cnames[i]) 226 | out 227 | } 228 | ## process missing values 229 | CDbtypes <- clrGet(sqlDataHelper,'CDbtypes') 230 | char.cols <- grep('char',CDbtypes) 231 | 232 | out[char.cols] <- lapply(out[char.cols], 233 | function(x) ifelse(nchar(x)==0,NA_character_,x)) 234 | ## process date type 235 | rtypes <- tolower(sapply(CDbtypes,db2RType)) 236 | ## POSIXct 237 | posix.cols <- grep('posixct',rtypes) 238 | out[posix.cols] <- lapply(out[posix.cols], "attr<-", which="tzone", value=Sys.timezone()) 239 | date.cols <- grep('date',rtypes) 240 | out[date.cols] <- lapply(out[date.cols],as.Date,tz=Sys.timezone()) 241 | 242 | ## set names and convert list to a data.frame 243 | names(out) <- Cnames 244 | attr(out, "row.names") <- c(NA_integer_, length(out[[1]])) 245 | class(out) <- "data.frame" 246 | out 247 | 248 | } 249 | 250 | 251 | 252 | 253 | sqlServerCloseResult <- 254 | function(res,...){ 255 | dataReader <- .NetObjFromPtr(res@Id) 256 | clrCall(dataReader,"Close") 257 | TRUE 258 | } 259 | 260 | 261 | 262 | 263 | ## helper function: it exec's *and* retrieves a statement. It should 264 | ## be named somehting else. 265 | sqlServerExecRetrieve <- 266 | function(con, statement,...) 267 | { 268 | state <- dbGetInfo(con,"State") 269 | if(state=="Closed"){ ## conn is closed 270 | new.con <- dbConnect(con) ## yep, create a clone connection 271 | on.exit(dbDisconnect(new.con)) 272 | rs <- dbSendQuery(new.con, statement,...) 273 | } else rs <- dbSendQuery(con, statement,...) 274 | res <- fetch(rs, n = -1) 275 | dbClearResult(rs) 276 | res 277 | } 278 | 279 | 280 | 281 | 282 | 283 | sqlServerResultInfo <- 284 | function(dbObj,what,...){ 285 | if(!isIdCurrent(dbObj)) 286 | stop(paste("expired", class(dbObj), deparse(substitute(dbObj)))) 287 | res <- .NetObjFromPtr(dbObj@Id) 288 | info <- vector("list", length = length(clrGetProperties(res))) 289 | sqlDataHelper <- clrNew("rsqlserver.net.SqlDataHelper",res) 290 | for (prop in c(clrGetProperties(sqlDataHelper),'Fetched')) 291 | info[[prop]] <- clrCall(sqlDataHelper,paste0("get_",prop)) 292 | info <- as.list(unlist(info)) 293 | if(!missing(what)) 294 | info[[what]] 295 | else 296 | info 297 | } 298 | 299 | 300 | netToRType <- function(obj,...) 301 | { 302 | switch(obj, 303 | System.String = "character", 304 | System.Int32 = "integer", 305 | System.Double = "numeric", 306 | System.DateTime = "character", 307 | "character") 308 | } 309 | 310 | 311 | 312 | setMethod("make.db.names", 313 | signature(dbObj="SqlServerObject", snames = "character"), 314 | def = function(dbObj, snames, keywords = .SqlServersKeywords, 315 | unique, allow.keywords, ...){ 316 | makeUnique <- function(x, sep = "_") { 317 | if (length(x) == 0) 318 | return(x) 319 | out <- x 320 | lc <- make.names(tolower(x), unique = FALSE) 321 | i <- duplicated(lc) 322 | lc <- make.names(lc, unique = TRUE) 323 | out[i] <- paste(out[i], substring(lc[i], first = nchar(out[i]) + 324 | 1), sep = sep) 325 | out 326 | } 327 | fc <- substring(snames, 1, 1) 328 | lc <- substring(snames, nchar(snames)) 329 | i <- match(fc, c("'", "\"","`"), 0) > 0 & match(lc, c("'", "\"","`"), 330 | 0) > 0 331 | snames[!i] <- make.names(snames[!i], unique = FALSE) 332 | if (unique) 333 | snames[!i] <- makeUnique(snames[!i]) 334 | if (!allow.keywords) { 335 | kwi <- match(keywords, toupper(snames), nomatch = 0L) 336 | 337 | # We could check to see if the database we are connected to is 338 | # running in ANSI mode. That would allow double quoted strings 339 | # as database identifiers. Until then, the backtick needs to be used. 340 | snames[kwi] <- paste("[", snames[kwi], "]", sep = "") 341 | } 342 | gsub("\\.", "_", snames) 343 | }, 344 | valueClass = "character" 345 | ) 346 | 347 | ## TODO complete this function 348 | ## maybe should I create some new R class to handle sql data type 349 | db2RType <- function(obj,...) 350 | { 351 | switch(obj , 352 | "bigint"="numeric", 353 | "binary"="integer", 354 | "bit"="integer", 355 | "char"= "factor", 356 | "date"= "Date", ##2008++ 357 | "datetime"="POSIXct", 358 | "datetime2"= "POSIXct", ##2008++ 359 | "datetimeoffset"= "POSIXct", ##2008++ 360 | "decimal"="numeric", 361 | "FILESTREAM attribute (varbinary(max))"= "TODO", 362 | "float"="numeric", 363 | "image"= "TODO", 364 | "int"="integer", 365 | "money"="character", 366 | "nchar"= "character", 367 | "ntext"= "character", 368 | "numeric"="numeric", 369 | "nvarchar"= "character", 370 | "real"= "numeric", 371 | "rowversion"= "TODO", 372 | "smalldatetime"= "POSIXct", 373 | "smallint"="integer", 374 | "smallmoney"= "character", 375 | "sql_variant"= "TODO", 376 | "text"= "character", 377 | "time"= "POSIXct", ##2008++ 378 | "timestamp"= "TODO", 379 | "tinyint"="integer", 380 | "uniqueidentifier"= "TODO", 381 | "varbinary"= "TODO", 382 | "varchar"= "character", 383 | "xml"= "TODO") 384 | } 385 | 386 | R2DbType <- function(obj,...) 387 | { 388 | class.obj <- ifelse(length(class(obj))==1, 389 | tolower(class(obj)), 390 | tolower(class(obj)[1])) 391 | 392 | switch(class.obj, 393 | integer = "int", 394 | factor = "char(12)" , 395 | numeric = "float", 396 | posixct = "datetime2", ## not datatime to manage fractional seconds 397 | posixlt = "datetime2", ## not datatime to manage fractional seconds 398 | date = "date", 399 | character = "varchar(128)", 400 | list = "varbinary(2000)", 401 | stop(gettextf("rsqlserver internal error [%s, %d, %s]", 402 | "R2DbType", 1L, class(obj)))) 403 | 404 | } 405 | 406 | sqlServer.data.frame <- function(obj,field.types) 407 | { 408 | out <- lapply(seq_along(field.types),function(x){ 409 | dbtype <- field.types[[x]] 410 | col <- obj[[x]] 411 | DATE_TYPES <- c("datetime","datetime2","datetimeoffset","date") 412 | col <- { 413 | if(dbtype %in% DATE_TYPES) 414 | paste0("'",col,"'") 415 | else if(grepl("char",dbtype)) { 416 | col[is.na(col)] <- '' 417 | paste0("'",gsub("'","''",col),"'") 418 | } 419 | else col 420 | } 421 | }) 422 | 423 | attr(out, "row.names") <- c(NA_integer_, length(out[[1]])) 424 | attr(out, "names") <- names(field.types) 425 | class(out) <- "data.frame" 426 | out 427 | } 428 | 429 | 430 | -------------------------------------------------------------------------------- /R/DBITransaction.R: -------------------------------------------------------------------------------- 1 | # # .net method to call a transaction 2 | # # // Start a local transaction. 3 | # # transaction = connection.BeginTransaction("SampleTransaction"); 4 | # # command.Connection = connection; 5 | # # command.Transaction = transaction; 6 | # # command.ExecuteNonQuery(); 7 | # # transaction.Commit(); 8 | # # transaction.Rollabck(); 9 | # 10 | # setClass("SqlServerTransaction", representation("SqlServerObject")) 11 | # 12 | # setGeneric("beginTransaction", 13 | # function(conn,name="R.transaction",...) 14 | # standardGeneric("beginTransaction") 15 | # ) 16 | # 17 | # setMethod("beginTransaction", 18 | # signature(conn='SqlServerConnection',name='character'), 19 | # def=function(conn,name="R.transaction",...){ 20 | # connection <- rClr:::createReturnedObject(conn@Id) 21 | # if(dbGetInfo(conn,'State')[[1]] ==1){ 22 | # trans <- clrCall(connection,"BeginTransaction",name) 23 | # Id = clrGetExtPtr(trans) 24 | # return(trans) 25 | # } 26 | # return(NULL) 27 | # }, 28 | # valueClass = "SqlServerTransaction") 29 | # 30 | # 31 | # setMethod("dbCommit", 32 | # signature(conn="SqlServerConnection"), 33 | # function(conn,trans, ...) { 34 | # transaction <- rClr:::createReturnedObject(trans@Id) 35 | # clrCall(transaction,'Commit') 36 | # TRUE 37 | # } 38 | # ) 39 | # 40 | # # setMethod("dbRollback", 41 | # # signature(trans = "SqlServerTransaction"), 42 | # # function(trans, ...) { 43 | # # transaction <- rClr:::createReturnedObject(trans@Id) 44 | # # clrCall(transaction,'bRollback') 45 | # # TRUE 46 | # # } 47 | # # ) 48 | # # 49 | -------------------------------------------------------------------------------- /R/dbObjectId.R: -------------------------------------------------------------------------------- 1 | 2 | 3 | setClass("dbObjectId", representation(Id = "externalptr", "VIRTUAL"), 4 | prototype=list(Id=NULL)) 5 | 6 | 7 | isIdCurrent <- 8 | function(obj) 9 | ## verify that obj refers to a currently open/loaded database 10 | { 11 | id <- .NetObjFromPtr(obj@Id) 12 | canCoerce(id, "cobjRef") 13 | } 14 | 15 | isTransaction <- function(conn) 16 | { 17 | trans <- .NetObjFromPtr(conn@trans) 18 | grepl('Transaction',clrTypename(trans)) 19 | } 20 | 21 | 22 | -------------------------------------------------------------------------------- /R/rsqlImpl.R: -------------------------------------------------------------------------------- 1 | 2 | 3 | sqlServerInitDriver <- 4 | function(max.con = 100L, fetch.default.rec = 500, force.reload=FALSE, 5 | shared.cache=FALSE) 6 | ## return a manager id 7 | { 8 | 9 | config.params <- as.integer(c(max.con, fetch.default.rec)) 10 | force <- as.logical(force.reload) 11 | cache <- as.logical(shared.cache) 12 | new("SqlServerDriver", Id = clrGetExtPtr(clrNew('System.Object'))) 13 | } 14 | 15 | 16 | sqlServerDriverInfo <- 17 | function(obj, what="", ...) 18 | { 19 | if(!isIdCurrent(obj)) 20 | stop(paste("expired", class(obj))) 21 | # drvId <- as(obj, "integer") 22 | # info <- .Call("RS_MySQL_managerInfo", drvId, PACKAGE = .MySQLPkgName) 23 | # ## replace drv/connection id w. actual drv/connection objects 24 | # conObjs <- vector("list", length = info$"num_con") 25 | # ids <- info$connectionIds 26 | # for(i in seq(along = ids)) 27 | # conObjs[[i]] <- new("MySQLConnection", Id = c(drvId, ids[i])) 28 | # info$connectionIds <- conObjs 29 | # info$managerId <- new("MySQLDriver", Id = drvId) 30 | # if(!missing(what)) 31 | # info[what] 32 | # else 33 | # info 34 | TRUE 35 | } 36 | 37 | 38 | 39 | 40 | 41 | ## Tsql 2012 keywords scraped from 42 | ## "http://technet.microsoft.com/en-us/library/ms189822(v=sql.110).aspx" 43 | ## using this smart helper function ! 44 | # scrape.keywords <- function(){ 45 | # ## require(XML) should uncomment this and install the packagee 46 | # url <- "http://technet.microsoft.com/en-us/library/ms189822(v=sql.110).aspx" 47 | # doc <- htmlParse(url) 48 | # ll <- xpathSApply(doc, '//*[@class="tableSection"]/*/tr/td/p',xmlValue) 49 | # ll <- ll[seq(min(grep('\n',ll))-1)] 50 | # cat(paste0('"',paste0(ll,collapse='","'),'"')) 51 | # } 52 | 53 | 54 | .SqlServersKeywords <- 55 | c("ADD","EXTERNAL","PROCEDURE","ALL","FETCH","PUBLIC","ALTER","FILE", 56 | "RAISERROR","AND","FILLFACTOR","READ","ANY","FOR","READTEXT","AS", 57 | "FOREIGN","RECONFIGURE","ASC","FREETEXT","REFERENCES","AUTHORIZATION", 58 | "FREETEXTTABLE","REPLICATION","BACKUP","FROM","RESTORE","BEGIN","FULL", 59 | "RESTRICT","BETWEEN","FUNCTION","RETURN","BREAK","GOTO","REVERT","BROWSE", 60 | "GRANT","REVOKE","BULK","GROUP","RIGHT","BY","HAVING","ROLLBACK","CASCADE", 61 | "HOLDLOCK","ROWCOUNT","CASE","IDENTITY","ROWGUIDCOL","CHECK","IDENTITY_INSERT", 62 | "RULE","CHECKPOINT","IDENTITYCOL","SAVE","CLOSE","IF","SCHEMA","CLUSTERED", 63 | "IN","SECURITYAUDIT","COALESCE","INDEX","SELECT","COLLATE","INNER", 64 | "SEMANTICKEYPHRASETABLE","COLUMN","INSERT","SEMANTICSIMILARITYDETAILSTABLE", 65 | "COMMIT","INTERSECT","SEMANTICSIMILARITYTABLE","COMPUTE","INTO","SESSION_USER", 66 | "CONSTRAINT","IS","SET","CONTAINS","JOIN","SETUSER","CONTAINSTABLE","KEY","SHUTDOWN", 67 | "CONTINUE","KILL","SOME","CONVERT","LEFT","STATISTICS","CREATE","LIKE","SYSTEM_USER", 68 | "CROSS","LINENO","TABLE","CURRENT","LOAD","TABLESAMPLE","CURRENT_DATE","MERGE", 69 | "TEXTSIZE","CURRENT_TIME","NATIONAL","THEN","CURRENT_TIMESTAMP","NOCHECK","TO", 70 | "CURRENT_USER","NONCLUSTERED","TOP","CURSOR","NOT","TRAN","DATABASE","NULL", 71 | "TRANSACTION","DBCC","NULLIF","TRIGGER","DEALLOCATE","OF","TRUNCATE","DECLARE", 72 | "OFF","TRY_CONVERT","DEFAULT","OFFSETS","TSEQUAL","DELETE","ON","UNION","DENY", 73 | "OPEN","UNIQUE","DESC","OPENDATASOURCE","UNPIVOT","DISK","OPENQUERY","UPDATE", 74 | "DISTINCT","OPENROWSET","UPDATETEXT","DISTRIBUTED","OPENXML","USE","DOUBLE", 75 | "OPTION","USER","DROP","OR","VALUES","DUMP","ORDER","VARYING","ELSE","OUTER", 76 | "VIEW","END","OVER","WAITFOR","ERRLVL","PERCENT","WHEN","ESCAPE","PIVOT","WHERE", 77 | "EXCEPT","PLAN","WHILE","EXEC","PRECISION","WITH","EXECUTE","PRIMARY","WITHIN GROUP", 78 | "EXISTS","PRINT","WRITETEXT","EXIT","PROC") 79 | 80 | 81 | -------------------------------------------------------------------------------- /R/zzz.R: -------------------------------------------------------------------------------- 1 | 2 | 3 | .onLoad <- function(libname, pkgname){ 4 | libLocation <- system.file(package=pkgname) 5 | libpath <- file.path(libLocation, 'libs') 6 | f <- file.path(libpath, 'rsqlserver.net.dll') 7 | if( !file.exists(f) ) { 8 | packageStartupMessage('Could not find path to rsqlserver.dll, 9 | you will have to load it manually') 10 | } else { 11 | clrLoadAssembly('System.Data') ## .net provider 12 | clrLoadAssembly(f) ## custom dll 13 | } 14 | } 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # rsqlserver 2 | 3 | [![Build Status](https://travis-ci.org/agstudy/rsqlserver.svg?branch=master)](https://travis-ci.org/agstudy/rsqlserver) 4 | [![Build status](https://ci.appveyor.com/api/projects/status/g30c0roi0ywenvau/branch/master?svg=true)](https://ci.appveyor.com/project/agstudy/rsqlserver/branch/master) 5 | 6 | SQL Server database interface **(DBI)** driver for R. 7 | 8 | This is a DBI-compliant SQL Server driver based on the 9 | .NET Framework Data Provider for SQL Server; `System.Data.SqlClient`. 10 | 11 | ## Motivation 12 | 13 | The .NET Framework Data Provider for SQL Server (SqlClient) uses its own protocol 14 | to communicate with SQL Server. It's lightweight and performs well because it's 15 | optimized to access a SQL Server directly without adding an OLE DB or Open Database 16 | Connectivity (ODBC) layer. For this reason, *rsqlserver* [outperforms](https://github.com/agstudy/rsqlserver/wiki/benchmarking) other R packages that rely on ODBC or JDBC layers. If you're using R to interact with SQL Server using large volumes of data and speed matters then *rsqlserver* is the answer! 17 | 18 | ## Installation 19 | 20 | *rsqlserver* is currently available on GitHub for Windows, Linux and macOS users. That said, Linux and macOS users are only able to make use of the package with some workarounds to the usual setup procedure. 21 | 22 | The package's interoperability of R and .NET code is provided by the [rClr](https://github.com/jmp75/rClr) package and unfortunately this package is currently only building on Windows and Mono 3.x (which is several years old) and therefore causing problems for macOS and Linux users. 23 | 24 | Due to the cross-platform functionality of Docker containers, it is now possible to install the package in a container on any system. 25 | 26 | ### Local Installation 27 | 28 | *Available for Windows and Linux (with patched rClr)* 29 | 30 | **Windows** users can install a pre-compiled binary of *rClr* and **Linux** users will be able to install a patched source of *rClr* by using an out-dated version of Mono. 31 | 32 | 1. Install *rClr* ([See below](#installing-rclr)) 33 | 34 | 6. Install *rsqlserver* from GitHub 35 | 36 | ```r 37 | devtools::install_github('agstudy/rsqlserver') 38 | ``` 39 | 40 | For **macOS** users, Mono 3.12.1 is able to be installed on newer OS X releases however the rClr build is not functioning properly. At the time of writing, the author of rClr is working on refreshing the package to work on newer versions of Mono which may hopefully resolve this issue. 41 | 42 | ### Docker 43 | 44 | *Available for Windows, Linux and macOS* 45 | 46 | The package can be installed on Windows, Linux and macOS via a provided Docker container which also includes an installation of SQL Server 2017. This is the best option for creating a reproducible environment for using the package that is accessible on all platforms and functions the same way regardless of the underlying system. 47 | 48 | 1. Install Docker for [Mac](https://docs.docker.com/docker-for-mac/install/) or [Windows](https://docs.docker.com/docker-for-windows/install/) 49 | 50 | 2. Go to Docker > Preferences and increase the supplied memory to at least 4GB 51 | and "Apply & Restart". This is in order to run the SQL Server container 52 | otherwise it won't even start up. 53 | 54 | 3. Open a Terminal with the repository as the working directory and follow [the instructions](UsingDocker.md) 55 | 56 | The **bcp** and **sqlcmd** tools are also [now available](https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-setup-tools#macos) 57 | for macOS and Docker. 58 | 59 | If you just want to connect to a Docker instance of SQL Server from your local 60 | Mac without *rsqlserver* then follow [these instructions](https://medium.com/@reverentgeek/sql-server-running-on-a-mac-3efafda48861). 61 | 62 | To install the necessary ODBC drivers without *rsqlserver* and connect with the 63 | *RODBC* package then follow [this wiki](https://github.com/mkleehammer/pyodbc/wiki/Connecting-to-SQL-Server-from-Mac-OSX). 64 | 65 | ### Installing rClr 66 | 67 | **Windows** 68 | 69 | The easiest option is to download a pre-compiled binary rather than try and install from source. 70 | 71 | 1. Install [Microsoft Windows SDK for Windows 7 and .NET Framework 4](https://www.microsoft.com/en-gb/download/details.aspx?id=8279). *rsqlserver* uses the .NET framework SDK to build a small C# project. 72 | Typically if your machine has the program "C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe", you can skip this step. 73 | 74 | 2. Install [Visual C++ Redistributable Packages for Visual Studio](https://go.microsoft.com/fwlink/?LinkId=746572). 75 | 76 | 3. Download [rClr 0.7-4](https://github.com/jmp75/rClr/archive/0.7-4.zip). (New binary versions will appear in the [GitHub releases](https://github.com/jmp75/rClr/releases). CodePlex is being decommissioned so the rClr 0.7-4 binary is available [here](https://github.com/ruaridhw/rClr/tree/windows-binary) if the source version won't install). 77 | 78 | 79 | ```r 80 | install.packages("path/to/rClr_0.7-4.zip", repos = NULL, type = "source") 81 | ``` 82 | 83 | **Linux** 84 | 85 | A workaround for installing the package on Linux is to downgrade the installed version of Mono to 3.12.1 using [this script](https://gist.github.com/ruaridhw/b00e75647c8e96c2f44044c970f19c7f) prior to building rClr as the package currently doesn't work on Mono 4.x or later. 86 | 87 | Once you have done this, test that the version of Mono is correct. If you see a version number other than 3.12.1 then the installation was unsuccessful. 88 | 89 | ```bash 90 | $ mono -V 91 | # Mono JIT compiler version 3.12.1 (tarball Fri Mar 6 19:12:47 UTC 2015) 92 | # Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com 93 | # TLS: __thread 94 | # SIGSEGV: altstack 95 | # Notifications: epoll 96 | # Architecture: amd64 97 | # Disabled: none 98 | # Misc: softdebug 99 | # LLVM: supported, not enabled. 100 | # GC: sgen 101 | ``` 102 | 103 | You can now install rClr from GitHub: 104 | 105 | ```r 106 | devtools::install_github('jmp75/rClr') 107 | ``` 108 | 109 | Depending on your distribution this may throw errors with the compilation of the C++ code. If you run into a similar issue as listed [here](https://github.com/jmp75/rClr/issues/27) then try this patched fork: 110 | 111 | ```r 112 | devtools::install_github('serhatcevikel/rClr@03f65ef') 113 | ``` 114 | 115 | ## Features 116 | 117 | *rsqlserver* presents many features: 118 | 119 | * Easy connection to SQL server using DBI-compliant drivers. 120 | * Fastest method for loading large delimited text files (>1million rows) and R objects into SQL Server tables or views using `dbBulkCopy` and pulling data back down into R data.frames (See benchmarking below) 121 | * Use a Trusted Connection with the server. (Windows only). 122 | * `dbSendQuery` for querying the database; low level functions using pure SQL statements. 123 | * Full DBI compliance via support of higher level convenience functions such as `dbReadTable`, `dbWriteTable` and `dbRemoveTable`. 124 | * `dbTransaction`, `dbCommit` and `dbRollback` for **Transaction** management. (TBA) 125 | * `dbCallProc` for **Stored Procedure** calls. (TBA) 126 | * Many other DBI extensions such as `dbGetScalar` and `dbGetNoQuery` 127 | * `dbParameter` to handle Transact-SQL named parameters. This will provide better type checking and improve performance. (TBA) 128 | 129 | ## Benchmarking 130 | 131 | See the *rsqlserver* wiki page on [benchmarking](https://github.com/agstudy/rsqlserver/wiki/benchmarking) performance versus two other drivers; `RODBC` and `RJDBC.` 132 | 133 | ## Acknowledgements 134 | 135 | I want to thank Jean-Michel Perraud the author of [rClr](http://r2clr.codeplex.com/) package. 136 | -------------------------------------------------------------------------------- /UsingDocker.md: -------------------------------------------------------------------------------- 1 | # Using rsqlserver with Docker 2 | 3 | This file contains instructions on building a Docker container 4 | containing 'rsqlserver' side-by-side with an MS SQL Server database 5 | 6 | If you have any problems or questions please raise an issue 7 | 8 | ## Command Line R 9 | 10 | ### Pull the latest Docker images 11 | 12 | Due to the size of the Docker images, this may take some time depending 13 | on your internet speed however this "pull" step is a once-off and further 14 | updates to the images will make use of your existing local caches. 15 | 16 | ```sh 17 | docker pull ruaridhw/rsqlserver:latest && docker pull microsoft/mssql-server-linux:latest 18 | ``` 19 | 20 | ### Start up the server container 21 | 22 | Your Docker instance will need to be allocated at least 3-4GB of memory in 23 | order for the database to successfully start up. 24 | 25 | ```sh 26 | docker run -e 'ACCEPT_EULA=Y' -e 'MSSQL_SA_PASSWORD=Password12!' -h mydockermsdb -p 1433:1433 --name mssqldb -d microsoft/mssql-server-linux 27 | ``` 28 | 29 | Edit the database password, hostname `-h` and container name `--name` 30 | parameters if required. It is possible (and advisable) to change the database 31 | password later once running to avoid showing it as plaintext. 32 | 33 | 34 | ### Run a query against the server 35 | ```sh 36 | docker exec -t mssqldb /opt/mssql-tools/bin/sqlcmd \ 37 | -S localhost -U SA -P 'Password12!' \ 38 | -Q "CREATE DATABASE rsqlserverdb; 39 | GO 40 | USE rsqlserverdb; 41 | CREATE TABLE Inventory (id INT, name NVARCHAR(50), quantity INT); 42 | INSERT INTO Inventory VALUES (1, 'banana', 150), (2, 'orange', 154); 43 | GO 44 | SELECT * FROM Inventory WHERE quantity > 152;" 45 | #> Changed database context to 'rsqlserverdb'. 46 | #> 47 | #> (2 rows affected) 48 | #> id name quantity 49 | #> ----------- -------------------------------------------------- ----------- 50 | #> 2 orange 154 51 | #> 52 | #> (1 rows affected) 53 | ``` 54 | 55 | ### Run a command in the rsqlserver R session container 56 | ```sh 57 | docker run --name testrsqlserver --link=mssqldb --rm ruaridhw/rsqlserver Rscript \ 58 | -e "library(rsqlserver)" \ 59 | -e "con <- dbConnect('SqlServer', host = 'mydockermsdb', dbname = 'rsqlserverdb', user = 'SA', password = 'Password12!')" \ 60 | -e "dbReadTable(con, 'Inventory')" 61 | #> Loading required package: methods 62 | #> Loading required package: rClr 63 | #> Assembly '/usr/local/lib/R/site-library/rClr/libs/ClrFacade.dll' doesn't have an entry point. 64 | #> Loading the dynamic library for Mono runtime... 65 | #> Loaded Common Language Runtime version 4.0.30319.17020 66 | #> id name quantity 67 | #> 1 1 banana 150 68 | #> 2 2 orange 154 69 | ``` 70 | 71 | The "Assembly entry point" warning message is a bug with rClr and can be ignored 72 | 73 | ### Re-enter the R session interactively 74 | ```sh 75 | docker run --name rsqlserver --link=mssqldb -i ruaridhw/rsqlserver 76 | #> R version 3.4.2 (2017-09-28) -- "Short Summer" 77 | #> Copyright (C) 2017 The R Foundation for Statistical Computing 78 | #> Platform: x86_64-pc-linux-gnu (64-bit) 79 | #> ... 80 | #> > 81 | ``` 82 | 83 | ## RStudio 84 | 85 | In order to use RStudio instead for easier interactivity over command line R, 86 | you can replace the Dockerfile in this repository with the two files located [here](https://github.com/ruaridhw/dockerfiles/tree/master/rsqlserver/rstudio) 87 | 88 | The "Pull" command now requires a build from the local Dockerfile: 89 | 90 | ```sh 91 | docker build -t rsqlserver-rstudio . && docker pull microsoft/mssql-server-linux:latest 92 | ``` 93 | 94 | For the `run` command, it is possible to persist a local directory on your 95 | host machine through to the container and have any updates to either directory 96 | immediately reflected in the other instance: 97 | 98 | ```sh 99 | docker run -d -p 8787:8787 --name rsqlstudio --link=mssqldb \ 100 | --mount type=bind,source=/path/to/local/rsqlserver,destination=/home/rstudio/rsqlserver \ 101 | rsqlserver-rstudio 102 | ``` 103 | 104 | In this example, `/path/to/local/rsqlserver` is a copy of the repository on the 105 | host machine which is replicated at `/home/rstudio/rsqlserver` on the container 106 | 107 | The RStudio server will run as a service on the container so simply open 108 | a local browser window pointing to http://localhost:8787 and login using 109 | the username and password "rstudio" 110 | 111 | When you are done, call `docker stop rsqlstudio` to stop the server and `docker start rsqlstudio` whenever you need it again. The `run` command 112 | is only for the container instantiation. 113 | 114 | ### Tested in the following environments: 115 | 116 | ``` 117 | R version 3.4.1 (2017-06-30) 118 | Platform: x86_64-apple-darwin15.6.0 (64-bit) 119 | Operating System: macOS Sierra 10.12.6 120 | ``` 121 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | image: Visual Studio 2015 2 | 3 | services: 4 | - mssql2014 5 | 6 | init: 7 | ps: | 8 | $ErrorActionPreference = "Stop" 9 | Invoke-WebRequest http://raw.github.com/krlmlr/r-appveyor/master/scripts/appveyor-tool.ps1 -OutFile "..\appveyor-tool.ps1" 10 | Import-Module '..\appveyor-tool.ps1' 11 | 12 | install: 13 | ps: Bootstrap 14 | 15 | environment: 16 | global: 17 | USE_RTOOLS: true 18 | 19 | matrix: 20 | - R_VERSION: release 21 | R_ARCH: x64 22 | 23 | - R_VERSION: oldrel 24 | RTOOLS_VERSION: 33 25 | CRAN: http://cran.rstudio.com 26 | 27 | matrix: 28 | fast_finish: true 29 | 30 | build_script: 31 | - ps: Invoke-WebRequest https://github.com/ruaridhw/rClr/raw/windows-binary/rClr_0.7-4.zip -OutFile "..\rClr_0.7-4.zip" 32 | - Rscript -e "install.packages('../rClr_0.7-4.zip', repos = NULL, type = 'binary')" 33 | - travis-tool.sh install_deps 34 | - sqlcmd -S "(local)\SQL2014" -U "sa" -P "Password12!" -i inst/setup.sql 35 | 36 | test_script: 37 | - travis-tool.sh run_tests 38 | 39 | on_failure: 40 | - 7z a failure.zip *.Rcheck\* 41 | - appveyor PushArtifact failure.zip 42 | 43 | artifacts: 44 | - path: '*.Rcheck\**\*.log' 45 | name: LogFiles 46 | 47 | - path: '*.Rcheck\**\*.out' 48 | name: LogFiles 49 | 50 | - path: '*.Rcheck\**\*.fail' 51 | name: LogFiles 52 | 53 | - path: '*.Rcheck\**\*.Rout' 54 | name: LogFiles 55 | 56 | - path: '\*_*.tar.gz' 57 | name: CheckArtifacts 58 | 59 | - path: '\*_*.zip' 60 | name: CheckArtifacts 61 | -------------------------------------------------------------------------------- /inst/data/CS_BIG.csv: -------------------------------------------------------------------------------- 1 | value,key 2 | 48,q 3 | 35,j 4 | 58,v 5 | 79,z 6 | 34,s 7 | 99,w 8 | 75,s 9 | 67,k 10 | 72,e 11 | 2,f 12 | 14,m 13 | 55,p 14 | 86,f 15 | 53,t 16 | 21,m 17 | 30,e 18 | 7,i 19 | 92,d 20 | 51,p 21 | 35,c 22 | 16,q 23 | 41,c 24 | 100,d 25 | 14,f 26 | 69,k 27 | 93,y 28 | 57,t 29 | 84,j 30 | 55,m 31 | 79,c 32 | 36,q 33 | 95,m 34 | 3,m 35 | 45,a 36 | 18,k 37 | 27,j 38 | 22,g 39 | 67,a 40 | 75,k 41 | 48,v 42 | 83,y 43 | 28,o 44 | 59,w 45 | 18,k 46 | 52,b 47 | 31,k 48 | 81,v 49 | 60,e 50 | 46,c 51 | 24,s 52 | 50,b 53 | 30,y 54 | 30,n 55 | 45,l 56 | 17,t 57 | 93,x 58 | 100,b 59 | 29,j 60 | 95,i 61 | 71,t 62 | 35,r 63 | 25,s 64 | 53,i 65 | 84,b 66 | 35,e 67 | 13,q 68 | 29,c 69 | 7,e 70 | 7,i 71 | 80,m 72 | 20,a 73 | 4,i 74 | 17,e 75 | 83,a 76 | 11,v 77 | 75,i 78 | 15,j 79 | 68,d 80 | 40,w 81 | 10,y 82 | 55,o 83 | 86,j 84 | 47,m 85 | 78,i 86 | 19,v 87 | 91,w 88 | 39,o 89 | 39,f 90 | 71,y 91 | 18,w 92 | 47,i 93 | 74,m 94 | 49,m 95 | 18,k 96 | 83,w 97 | 89,a 98 | 23,i 99 | 11,y 100 | 67,p 101 | 95,j 102 | 34,u 103 | 64,l 104 | 32,k 105 | 50,s 106 | 72,v 107 | 44,a 108 | 35,j 109 | 69,y 110 | 45,m 111 | 41,s 112 | 21,r 113 | 50,f 114 | 14,g 115 | 2,j 116 | 95,i 117 | 52,k 118 | 65,i 119 | 59,s 120 | 84,j 121 | 14,w 122 | 79,e 123 | 33,a 124 | 9,x 125 | 44,t 126 | 50,a 127 | 6,x 128 | 98,w 129 | 26,g 130 | 60,x 131 | 10,e 132 | 7,t 133 | 26,h 134 | 40,x 135 | 58,b 136 | 96,e 137 | 25,f 138 | 68,q 139 | 13,h 140 | 82,l 141 | 45,b 142 | 4,g 143 | 75,w 144 | 75,a 145 | 91,u 146 | 84,k 147 | 96,z 148 | 54,n 149 | 11,a 150 | 33,h 151 | 72,c 152 | 98,v 153 | 71,k 154 | 38,k 155 | 62,n 156 | 37,x 157 | 67,i 158 | 74,n 159 | 72,h 160 | 87,c 161 | 39,s 162 | 4,y 163 | 81,r 164 | 77,y 165 | 49,q 166 | 9,b 167 | 75,w 168 | 94,s 169 | 44,w 170 | 44,h 171 | 64,q 172 | 56,v 173 | 85,c 174 | 48,d 175 | 28,w 176 | 92,e 177 | 60,h 178 | 31,p 179 | 25,l 180 | 46,g 181 | 8,o 182 | 97,s 183 | 65,l 184 | 82,s 185 | 26,u 186 | 98,g 187 | 38,c 188 | 97,n 189 | 4,y 190 | 96,z 191 | 42,a 192 | 83,x 193 | 23,k 194 | 15,j 195 | 65,s 196 | 6,b 197 | 78,a 198 | 42,x 199 | 17,p 200 | 44,i 201 | 82,r 202 | 97,h 203 | 32,e 204 | 5,h 205 | 10,q 206 | 7,j 207 | 27,s 208 | 20,y 209 | 68,q 210 | 6,c 211 | 80,n 212 | 52,a 213 | 83,y 214 | 21,r 215 | 71,f 216 | 39,v 217 | 16,x 218 | 16,r 219 | 58,i 220 | 32,z 221 | 19,l 222 | 60,z 223 | 45,t 224 | 94,h 225 | 77,h 226 | 4,q 227 | 18,m 228 | 39,y 229 | 84,o 230 | 98,c 231 | 53,w 232 | 88,u 233 | 26,g 234 | 36,g 235 | 30,d 236 | 16,u 237 | 44,j 238 | 30,c 239 | 30,d 240 | 32,u 241 | 98,m 242 | 22,a 243 | 25,l 244 | 25,v 245 | 19,d 246 | 66,r 247 | 92,t 248 | 90,u 249 | 38,o 250 | 16,v 251 | 63,c 252 | 14,g 253 | 56,k 254 | 64,e 255 | 19,d 256 | 75,u 257 | 57,s 258 | 59,y 259 | 73,c 260 | 29,n 261 | 37,a 262 | 39,b 263 | 74,n 264 | 79,l 265 | 80,e 266 | 82,m 267 | 83,g 268 | 69,a 269 | 97,g 270 | 8,w 271 | 64,y 272 | 36,k 273 | 84,m 274 | 21,a 275 | 85,s 276 | 10,w 277 | 80,j 278 | 53,t 279 | 61,w 280 | 7,u 281 | 93,r 282 | 34,m 283 | 46,s 284 | 69,h 285 | 75,u 286 | 46,f 287 | 24,c 288 | 37,r 289 | 74,t 290 | 58,h 291 | 80,h 292 | 3,t 293 | 87,u 294 | 18,q 295 | 12,s 296 | 9,x 297 | 39,q 298 | 66,r 299 | 26,e 300 | 57,s 301 | 5,q 302 | 86,l 303 | 48,h 304 | 60,l 305 | 61,a 306 | 12,p 307 | 72,b 308 | 61,y 309 | 47,w 310 | 63,b 311 | 45,r 312 | 24,t 313 | 6,c 314 | 38,w 315 | 7,b 316 | 84,x 317 | 62,v 318 | 17,e 319 | 80,s 320 | 11,k 321 | 43,f 322 | 43,y 323 | 37,i 324 | 76,q 325 | 47,b 326 | 54,t 327 | 77,y 328 | 82,j 329 | 62,y 330 | 59,l 331 | 28,a 332 | 91,k 333 | 100,x 334 | 36,x 335 | 80,g 336 | 9,p 337 | 14,w 338 | 9,f 339 | 74,u 340 | 41,i 341 | 18,o 342 | 44,f 343 | 38,z 344 | 81,x 345 | 45,z 346 | 54,d 347 | 77,t 348 | 16,r 349 | 73,n 350 | 95,n 351 | 58,j 352 | 89,i 353 | 32,d 354 | 23,s 355 | 69,i 356 | 70,p 357 | 91,u 358 | 94,g 359 | 75,i 360 | 67,v 361 | 32,s 362 | 72,d 363 | 62,f 364 | 30,m 365 | 52,u 366 | 11,c 367 | 62,t 368 | 3,v 369 | 57,k 370 | 13,z 371 | 89,a 372 | 41,e 373 | 59,a 374 | 11,x 375 | 42,y 376 | 73,k 377 | 98,u 378 | 23,d 379 | 41,c 380 | 29,d 381 | 85,f 382 | 52,h 383 | 74,f 384 | 13,j 385 | 53,o 386 | 43,l 387 | 22,n 388 | 82,m 389 | 73,i 390 | 52,n 391 | 66,l 392 | 11,k 393 | 35,n 394 | 97,a 395 | 93,o 396 | 99,i 397 | 67,z 398 | 72,e 399 | 45,s 400 | 98,e 401 | 81,y 402 | 28,o 403 | 76,b 404 | 10,f 405 | 11,n 406 | 64,d 407 | 91,j 408 | 50,o 409 | 10,q 410 | 14,v 411 | 9,b 412 | 18,v 413 | 79,e 414 | 72,x 415 | 19,m 416 | 38,z 417 | 8,q 418 | 94,v 419 | 62,g 420 | 19,m 421 | 7,i 422 | 58,l 423 | 69,m 424 | 4,v 425 | 75,r 426 | 39,j 427 | 71,l 428 | 76,l 429 | 12,u 430 | 74,c 431 | 97,z 432 | 88,h 433 | 62,o 434 | 68,v 435 | 61,c 436 | 9,i 437 | 36,s 438 | 66,f 439 | 99,s 440 | 92,n 441 | 57,r 442 | 78,f 443 | 100,x 444 | 51,y 445 | 96,r 446 | 46,n 447 | 100,g 448 | 65,c 449 | 77,y 450 | 63,k 451 | 38,q 452 | 17,e 453 | 66,b 454 | 32,u 455 | 64,g 456 | 34,d 457 | 79,a 458 | 44,x 459 | 79,g 460 | 89,p 461 | 16,c 462 | 16,r 463 | 42,j 464 | 9,f 465 | 47,z 466 | 53,l 467 | 76,u 468 | 73,h 469 | 89,u 470 | 17,h 471 | 89,c 472 | 61,q 473 | 40,v 474 | 63,u 475 | 61,d 476 | 44,h 477 | 24,u 478 | 6,n 479 | 17,k 480 | 85,i 481 | 9,a 482 | 92,v 483 | 25,c 484 | 49,t 485 | 24,e 486 | 16,a 487 | 62,f 488 | 41,z 489 | 94,r 490 | 93,s 491 | 57,k 492 | 68,u 493 | 65,v 494 | 16,j 495 | 70,f 496 | 35,c 497 | 94,q 498 | 65,r 499 | 84,w 500 | 22,a 501 | 5,o 502 | 42,h 503 | 25,i 504 | 43,p 505 | 29,n 506 | 18,j 507 | 79,r 508 | 88,d 509 | 27,v 510 | 91,a 511 | 20,d 512 | 67,i 513 | 3,g 514 | 77,z 515 | 26,t 516 | 46,b 517 | 42,l 518 | 75,t 519 | 72,o 520 | 53,s 521 | 24,w 522 | 77,r 523 | 28,t 524 | 63,p 525 | 83,w 526 | 63,d 527 | 68,q 528 | 36,b 529 | 39,x 530 | 6,o 531 | 12,f 532 | 49,f 533 | 85,k 534 | 99,o 535 | 58,i 536 | 22,r 537 | 71,n 538 | 16,y 539 | 99,m 540 | 22,j 541 | 83,g 542 | 40,b 543 | 90,g 544 | 43,u 545 | 33,h 546 | 5,u 547 | 18,y 548 | 19,f 549 | 1,g 550 | 59,e 551 | 39,p 552 | 54,n 553 | 93,a 554 | 33,m 555 | 69,p 556 | 77,n 557 | 7,d 558 | 9,i 559 | 42,g 560 | 11,u 561 | 85,u 562 | 21,b 563 | 35,e 564 | 52,t 565 | 25,d 566 | 99,x 567 | 8,t 568 | 89,i 569 | 75,u 570 | 11,e 571 | 40,n 572 | 84,c 573 | 14,u 574 | 77,r 575 | 81,r 576 | 91,z 577 | 69,f 578 | 97,i 579 | 87,v 580 | 96,q 581 | 47,p 582 | 98,b 583 | 9,q 584 | 71,m 585 | 83,g 586 | 1,w 587 | 45,l 588 | 76,y 589 | 68,z 590 | 11,o 591 | 95,v 592 | 34,x 593 | 71,k 594 | 97,m 595 | 9,z 596 | 32,k 597 | 81,i 598 | 12,f 599 | 33,h 600 | 82,l 601 | 86,b 602 | 22,k 603 | 48,p 604 | 82,p 605 | 86,y 606 | 74,r 607 | 34,k 608 | 38,b 609 | 84,j 610 | 42,a 611 | 59,y 612 | 88,q 613 | 30,y 614 | 42,n 615 | 3,c 616 | 69,h 617 | 29,l 618 | 28,t 619 | 46,u 620 | 97,s 621 | 6,e 622 | 16,p 623 | 46,a 624 | 18,x 625 | 39,i 626 | 13,e 627 | 4,c 628 | 18,k 629 | 97,h 630 | 19,g 631 | 60,a 632 | 68,k 633 | 81,c 634 | 86,t 635 | 100,f 636 | 19,e 637 | 52,f 638 | 59,t 639 | 23,k 640 | 1,k 641 | 94,m 642 | 74,m 643 | 89,u 644 | 62,b 645 | 39,s 646 | 90,y 647 | 69,b 648 | 78,s 649 | 31,m 650 | 51,n 651 | 93,x 652 | 50,k 653 | 1,p 654 | 12,i 655 | 40,p 656 | 59,e 657 | 46,v 658 | 70,w 659 | 39,r 660 | 63,y 661 | 21,d 662 | 22,f 663 | 17,v 664 | 68,i 665 | 100,i 666 | 66,c 667 | 6,m 668 | 42,d 669 | 63,f 670 | 64,h 671 | 82,p 672 | 89,n 673 | 64,g 674 | 33,x 675 | 18,z 676 | 22,o 677 | 77,s 678 | 67,e 679 | 25,s 680 | 94,s 681 | 82,s 682 | 65,a 683 | 5,y 684 | 92,l 685 | 2,m 686 | 47,c 687 | 6,u 688 | 80,f 689 | 94,v 690 | 30,h 691 | 99,y 692 | 26,z 693 | 23,p 694 | 3,h 695 | 40,w 696 | 30,l 697 | 48,f 698 | 93,y 699 | 56,j 700 | 95,m 701 | 85,b 702 | 18,m 703 | 92,b 704 | 20,p 705 | 98,t 706 | 55,b 707 | 99,d 708 | 80,u 709 | 98,e 710 | 88,b 711 | 87,h 712 | 13,w 713 | 60,t 714 | 49,d 715 | 43,k 716 | 30,p 717 | 86,y 718 | 11,n 719 | 51,i 720 | 86,f 721 | 8,c 722 | 100,k 723 | 4,x 724 | 81,v 725 | 91,t 726 | 78,n 727 | 21,o 728 | 78,h 729 | 26,d 730 | 45,h 731 | 80,j 732 | 22,p 733 | 28,n 734 | 78,p 735 | 94,f 736 | 65,h 737 | 90,p 738 | 91,o 739 | 89,b 740 | 97,r 741 | 76,n 742 | 83,k 743 | 49,p 744 | 99,a 745 | 21,c 746 | 19,z 747 | 10,s 748 | 85,c 749 | 30,n 750 | 6,j 751 | 57,n 752 | 64,y 753 | 9,l 754 | 44,l 755 | 44,o 756 | 27,i 757 | 49,s 758 | 9,g 759 | 99,n 760 | 24,u 761 | 5,j 762 | 49,c 763 | 9,o 764 | 90,e 765 | 36,o 766 | 19,h 767 | 23,g 768 | 98,n 769 | 40,w 770 | 11,l 771 | 86,l 772 | 74,i 773 | 29,k 774 | 26,x 775 | 82,q 776 | 46,s 777 | 54,w 778 | 78,m 779 | 70,n 780 | 87,p 781 | 35,o 782 | 65,m 783 | 72,k 784 | 11,w 785 | 50,c 786 | 74,u 787 | 10,q 788 | 18,p 789 | 56,o 790 | 63,z 791 | 67,m 792 | 72,v 793 | 21,p 794 | 28,r 795 | 94,s 796 | 59,n 797 | 94,g 798 | 79,y 799 | 30,e 800 | 41,d 801 | 55,s 802 | 88,e 803 | 69,e 804 | 49,z 805 | 28,d 806 | 25,m 807 | 65,a 808 | 43,x 809 | 62,q 810 | 61,q 811 | 91,o 812 | 91,y 813 | 11,v 814 | 42,n 815 | 62,o 816 | 28,t 817 | 19,v 818 | 6,u 819 | 57,v 820 | 72,u 821 | 1,d 822 | 42,o 823 | 69,h 824 | 99,p 825 | 38,m 826 | 84,r 827 | 1,s 828 | 1,i 829 | 61,z 830 | 90,b 831 | 23,l 832 | 47,m 833 | 91,u 834 | 64,w 835 | 30,v 836 | 89,n 837 | 23,d 838 | 35,n 839 | 71,u 840 | 94,w 841 | 68,m 842 | 50,f 843 | 61,s 844 | 84,w 845 | 9,q 846 | 21,x 847 | 30,r 848 | 33,u 849 | 41,v 850 | 82,a 851 | 54,g 852 | 18,s 853 | 12,i 854 | 11,q 855 | 30,h 856 | 98,g 857 | 30,j 858 | 72,t 859 | 98,n 860 | 7,h 861 | 81,j 862 | 85,z 863 | 22,k 864 | 66,g 865 | 47,i 866 | 95,p 867 | 15,d 868 | 84,w 869 | 33,z 870 | 77,d 871 | 47,h 872 | 98,t 873 | 83,z 874 | 17,q 875 | 7,i 876 | 81,o 877 | 78,q 878 | 87,b 879 | 50,e 880 | 26,f 881 | 13,t 882 | 65,s 883 | 99,k 884 | 48,e 885 | 98,f 886 | 21,i 887 | 41,c 888 | 67,b 889 | 51,i 890 | 12,q 891 | 67,v 892 | 82,b 893 | 32,p 894 | 41,s 895 | 81,c 896 | 6,r 897 | 74,a 898 | 5,p 899 | 98,x 900 | 75,c 901 | 17,b 902 | 71,w 903 | 83,c 904 | 94,r 905 | 78,b 906 | 59,q 907 | 16,k 908 | 74,m 909 | 27,f 910 | 91,x 911 | 64,k 912 | 94,s 913 | 88,j 914 | 99,x 915 | 59,t 916 | 52,f 917 | 16,y 918 | 90,q 919 | 19,u 920 | 22,m 921 | 100,y 922 | 58,o 923 | 37,e 924 | 13,j 925 | 62,q 926 | 11,d 927 | 85,c 928 | 77,s 929 | 11,r 930 | 37,r 931 | 51,o 932 | 94,v 933 | 92,n 934 | 93,y 935 | 56,z 936 | 4,h 937 | 29,z 938 | 80,x 939 | 98,q 940 | 87,e 941 | 33,v 942 | 72,x 943 | 83,b 944 | 67,s 945 | 87,i 946 | 76,x 947 | 35,v 948 | 24,h 949 | 20,n 950 | 17,p 951 | 26,p 952 | 66,u 953 | 86,i 954 | 44,x 955 | 85,v 956 | 85,e 957 | 9,v 958 | 96,o 959 | 48,g 960 | 7,g 961 | 38,t 962 | 59,r 963 | 70,c 964 | 41,l 965 | 8,c 966 | 7,z 967 | 93,z 968 | 55,v 969 | 68,z 970 | 48,b 971 | 90,g 972 | 19,e 973 | 6,j 974 | 93,y 975 | 42,t 976 | 46,i 977 | 53,u 978 | 33,e 979 | 17,z 980 | 17,j 981 | 28,b 982 | 39,l 983 | 96,r 984 | 37,r 985 | 35,a 986 | 54,g 987 | 71,g 988 | 58,l 989 | 76,m 990 | 82,v 991 | 49,z 992 | 32,s 993 | 56,b 994 | 21,m 995 | 77,z 996 | 61,m 997 | 29,h 998 | 53,h 999 | 91,g 1000 | 83,t 1001 | 73,e -------------------------------------------------------------------------------- /inst/libs/LumenWorks.Framework.IO.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agstudy/rsqlserver/4f54256507affe3fe31c4e9b635a7bcfc1becece/inst/libs/LumenWorks.Framework.IO.dll -------------------------------------------------------------------------------- /inst/libs/LumenWorks.Framework.IO.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agstudy/rsqlserver/4f54256507affe3fe31c4e9b635a7bcfc1becece/inst/libs/LumenWorks.Framework.IO.pdb -------------------------------------------------------------------------------- /inst/libs/RDotNet.NativeLibrary.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agstudy/rsqlserver/4f54256507affe3fe31c4e9b635a7bcfc1becece/inst/libs/RDotNet.NativeLibrary.dll -------------------------------------------------------------------------------- /inst/libs/RDotNet.NativeLibrary.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | RDotNet.NativeLibrary 5 | 6 | 7 | 8 | 9 | A proxy for unmanaged dynamic link library (DLL). 10 | 11 | 12 | 13 | 14 | Creates a proxy for the specified dll. 15 | 16 | The DLL's name. 17 | 18 | 19 | 20 | Creates the delegate function for the specified function defined in the DLL. 21 | 22 | The type of delegate. 23 | The delegate. 24 | 25 | 26 | 27 | Creates the delegate function for the specified function defined in the DLL. 28 | 29 | The type of delegate. 30 | The name of function. 31 | The delegate. 32 | 33 | 34 | 35 | Gets the handle of the specified entry. 36 | 37 | The name of function. 38 | The handle. 39 | 40 | 41 | 42 | Adds a directory to the search path used to locate DLLs for the application. 43 | 44 | 45 | Calls SetDllDirectory in the kernel32.dll on Windows. 46 | 47 | 48 | The directory to be added to the search path. 49 | If this parameter is an empty string (""), the call removes the current directory from the default DLL search order. 50 | If this parameter is NULL, the function restores the default search order. 51 | 52 | If the function succeeds, the return value is nonzero. 53 | 54 | 55 | 56 | Collection of utility methods for operating systems. 57 | 58 | 59 | 60 | 61 | Gets the platform on which the current process runs. 62 | 63 | 64 | 's platform is not even on Mac OS X. 65 | This method returns when the current process runs on Mac OS X. 66 | This method uses UNIX's uname command to check the operating system, 67 | so this method cannot check the OS correctly if the PATH environment variable is changed (will returns ). 68 | 69 | The current platform. 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /inst/libs/RDotNet.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agstudy/rsqlserver/4f54256507affe3fe31c4e9b635a7bcfc1becece/inst/libs/RDotNet.dll -------------------------------------------------------------------------------- /inst/libs/i386/toto: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agstudy/rsqlserver/4f54256507affe3fe31c4e9b635a7bcfc1becece/inst/libs/i386/toto -------------------------------------------------------------------------------- /inst/libs/log4net.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /inst/libs/log4net.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agstudy/rsqlserver/4f54256507affe3fe31c4e9b635a7bcfc1becece/inst/libs/log4net.dll -------------------------------------------------------------------------------- /inst/libs/rsqlserver.net.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agstudy/rsqlserver/4f54256507affe3fe31c4e9b635a7bcfc1becece/inst/libs/rsqlserver.net.dll -------------------------------------------------------------------------------- /inst/libs/rsqlserver.net.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agstudy/rsqlserver/4f54256507affe3fe31c4e9b635a7bcfc1becece/inst/libs/rsqlserver.net.pdb -------------------------------------------------------------------------------- /inst/libs/x64/toto: -------------------------------------------------------------------------------- 1 | aa 2 | -------------------------------------------------------------------------------- /inst/setup.sql: -------------------------------------------------------------------------------- 1 | -- ---------------------------- 2 | -- Create database structure for 3 | -- the purposes of TestSqlDataHelper.cs 4 | -- ---------------------------- 5 | CREATE DATABASE rsqlserverdb; 6 | GO 7 | USE rsqlserverdb; 8 | GO 9 | 10 | -- ---------------------------- 11 | -- Table structure for CS_BIG 12 | -- ---------------------------- 13 | IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[CS_BIG]') AND type IN ('U')) 14 | DROP TABLE [dbo].[CS_BIG] 15 | GO 16 | 17 | CREATE TABLE [dbo].[CS_BIG] ( 18 | [value] int NULL, 19 | [key] nvarchar(255) NULL 20 | ) 21 | GO 22 | 23 | ALTER TABLE [dbo].[CS_BIG] SET (LOCK_ESCALATION = TABLE) 24 | GO 25 | 26 | -- ---------------------------- 27 | -- Table structure for CS_DATE 28 | -- ---------------------------- 29 | IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[CS_DATE]') AND type IN ('U')) 30 | DROP TABLE [dbo].[CS_DATE] 31 | GO 32 | 33 | CREATE TABLE [dbo].[CS_DATE] ( 34 | [cdate] nvarchar(255) NULL 35 | ) 36 | GO 37 | 38 | ALTER TABLE [dbo].[CS_DATE] SET (LOCK_ESCALATION = TABLE) 39 | GO 40 | 41 | -- ---------------------------- 42 | -- Table structure for CS_EXOTIC 43 | -- ---------------------------- 44 | IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[CS_EXOTIC]') AND type IN ('U')) 45 | DROP TABLE [dbo].[CS_EXOTIC] 46 | GO 47 | 48 | CREATE TABLE [dbo].[CS_EXOTIC] ( 49 | [col_varchar] nvarchar(100) NULL, 50 | [col_int] int NULL, 51 | [col_bigint] bigint NULL, 52 | [col_bit] bit NULL, 53 | [col_numeric] numeric(10,6) NULL, 54 | [col_decimal] decimal(10,6) NULL 55 | ) 56 | GO 57 | 58 | ALTER TABLE [dbo].[CS_EXOTIC] SET (LOCK_ESCALATION = TABLE) 59 | GO 60 | 61 | -- ---------------------------- 62 | -- Table structure for CS_MTCARS 63 | -- ---------------------------- 64 | IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[CS_MTCARS]') AND type IN ('U')) 65 | DROP TABLE [dbo].[CS_MTCARS] 66 | GO 67 | 68 | CREATE TABLE [dbo].[CS_MTCARS] ( 69 | [mpg] decimal(18,1) NULL, 70 | [cyl] int NULL, 71 | [disp] decimal(18,1) NULL, 72 | [hp] int NULL, 73 | [drat] decimal(18,2) NULL, 74 | [wt] decimal(18,3) NULL, 75 | [qsec] decimal(18,2) NULL, 76 | [vs] int NULL, 77 | [am] int NULL, 78 | [gear] int NULL, 79 | [carb] int NULL 80 | ) 81 | GO 82 | 83 | ALTER TABLE [dbo].[CS_MTCARS] SET (LOCK_ESCALATION = TABLE) 84 | GO 85 | 86 | -- ---------------------------- 87 | -- Records of [CS_DATE] 88 | -- ---------------------------- 89 | INSERT INTO [dbo].[CS_DATE] VALUES 90 | (N'2017-01-01T00:00:00Z'), 91 | (N'2017-01-01T14:53:09Z'), 92 | (N'2017-01-02T05:46:19Z'), 93 | (N'2017-01-02T20:39:29Z'), 94 | (N'2017-01-03T11:32:39Z'), 95 | (N'2017-01-04T02:25:49Z'), 96 | (N'2017-01-04T17:18:59Z'), 97 | (N'2017-01-05T08:12:09Z'), 98 | (N'2017-01-05T23:05:19Z'), 99 | (N'2017-01-06T13:58:28Z'), 100 | (N'2017-01-07T04:51:38Z'), 101 | (N'2017-01-07T19:44:48Z'), 102 | (N'2017-01-08T10:37:58Z'), 103 | (N'2017-01-09T01:31:08Z'), 104 | (N'2017-01-09T16:24:18Z'), 105 | (N'2017-01-10T07:17:28Z'), 106 | (N'2017-01-10T22:10:38Z'), 107 | (N'2017-01-11T13:03:48Z'), 108 | (N'2017-01-12T03:56:57Z'), 109 | (N'2017-01-12T18:50:07Z'), 110 | (N'2017-01-13T09:43:17Z'), 111 | (N'2017-01-14T00:36:27Z'), 112 | (N'2017-01-14T15:29:37Z'), 113 | (N'2017-01-15T06:22:47Z'), 114 | (N'2017-01-15T21:15:57Z'), 115 | (N'2017-01-16T12:09:07Z'), 116 | (N'2017-01-17T03:02:17Z'), 117 | (N'2017-01-17T17:55:26Z'), 118 | (N'2017-01-18T08:48:36Z'), 119 | (N'2017-01-18T23:41:46Z'), 120 | (N'2017-01-19T14:34:56Z'), 121 | (N'2017-01-20T05:28:06Z'), 122 | (N'2017-01-20T20:21:16Z'), 123 | (N'2017-01-21T11:14:26Z'), 124 | (N'2017-01-22T02:07:36Z'), 125 | (N'2017-01-22T17:00:45Z'), 126 | (N'2017-01-23T07:53:55Z'), 127 | (N'2017-01-23T22:47:05Z'), 128 | (N'2017-01-24T13:40:15Z'), 129 | (N'2017-01-25T04:33:25Z'), 130 | (N'2017-01-25T19:26:35Z'), 131 | (N'2017-01-26T10:19:45Z'), 132 | (N'2017-01-27T01:12:55Z'), 133 | (N'2017-01-27T16:06:05Z'), 134 | (N'2017-01-28T06:59:14Z'), 135 | (N'2017-01-28T21:52:24Z'), 136 | (N'2017-01-29T12:45:34Z'), 137 | (N'2017-01-30T03:38:44Z'), 138 | (N'2017-01-30T18:31:54Z'), 139 | (N'2017-01-31T09:25:04Z'), 140 | (N'2017-02-01T00:18:14Z'), 141 | (N'2017-02-01T15:11:24Z'), 142 | (N'2017-02-02T06:04:34Z'), 143 | (N'2017-02-02T20:57:43Z'), 144 | (N'2017-02-03T11:50:53Z'), 145 | (N'2017-02-04T02:44:03Z'), 146 | (N'2017-02-04T17:37:13Z'), 147 | (N'2017-02-05T08:30:23Z'), 148 | (N'2017-02-05T23:23:33Z'), 149 | (N'2017-02-06T14:16:43Z'), 150 | (N'2017-02-07T05:09:53Z'), 151 | (N'2017-02-07T20:03:02Z'), 152 | (N'2017-02-08T10:56:12Z'), 153 | (N'2017-02-09T01:49:22Z'), 154 | (N'2017-02-09T16:42:32Z'), 155 | (N'2017-02-10T07:35:42Z'), 156 | (N'2017-02-10T22:28:52Z'), 157 | (N'2017-02-11T13:22:02Z'), 158 | (N'2017-02-12T04:15:12Z'), 159 | (N'2017-02-12T19:08:22Z'), 160 | (N'2017-02-13T10:01:31Z'), 161 | (N'2017-02-14T00:54:41Z'), 162 | (N'2017-02-14T15:47:51Z'), 163 | (N'2017-02-15T06:41:01Z'), 164 | (N'2017-02-15T21:34:11Z'), 165 | (N'2017-02-16T12:27:21Z'), 166 | (N'2017-02-17T03:20:31Z'), 167 | (N'2017-02-17T18:13:41Z'), 168 | (N'2017-02-18T09:06:51Z'), 169 | (N'2017-02-19T00:00:00Z'), 170 | (N'2017-02-19T14:53:10Z'), 171 | (N'2017-02-20T05:46:20Z'), 172 | (N'2017-02-20T20:39:30Z'), 173 | (N'2017-02-21T11:32:40Z'), 174 | (N'2017-02-22T02:25:50Z'), 175 | (N'2017-02-22T17:19:00Z'), 176 | (N'2017-02-23T08:12:10Z'), 177 | (N'2017-02-23T23:05:19Z'), 178 | (N'2017-02-24T13:58:29Z'), 179 | (N'2017-02-25T04:51:39Z'), 180 | (N'2017-02-25T19:44:49Z'), 181 | (N'2017-02-26T10:37:59Z'), 182 | (N'2017-02-27T01:31:09Z'), 183 | (N'2017-02-27T16:24:19Z'), 184 | (N'2017-02-28T07:17:29Z'), 185 | (N'2017-02-28T22:10:39Z'), 186 | (N'2017-03-01T13:03:48Z'), 187 | (N'2017-03-02T03:56:58Z'), 188 | (N'2017-03-02T18:50:08Z'), 189 | (N'2017-03-03T09:43:18Z') 190 | GO 191 | 192 | -- ---------------------------- 193 | -- Records of [CS_EXOTIC] 194 | -- ---------------------------- 195 | INSERT INTO [dbo].[CS_EXOTIC] VALUES 196 | (N'Utah', N'576', N'1040422319966168', N'1', N'5.740238', N'45.352324'), 197 | (N'Virginia', N'514', N'863508665932945', NULL, N'0.804227', N'51.261316'), 198 | (N'Maine', N'300', N'657983413678237', N'1', N'7.367869', N'20.981283'), 199 | (N'California', N'737', N'79605235884840', N'1', N'7.488238', N'65.711113'), 200 | (N'Florida', N'214', N'102974638053022', N'0', N'5.276618', N'49.652377'), 201 | (N'New Mexico', N'999', N'763952787550411', N'1', N'6.347286', N'98.187656'), 202 | (N'Montana', N'184', N'996602682905021', NULL, N'5.672371', N'28.317173'), 203 | (N'New Hampshire', N'75', N'289116831174531', NULL, N'1.375467', N'32.773796'), 204 | (N'Montana', N'603', N'226355531524095', N'1', N'0.206504', N'16.080238'), 205 | (N'Wyoming', N'713', N'844246903744689', NULL, N'1.856756', N'21.354147'), 206 | (N'Louisiana', N'242', N'1087537145449401', N'1', N'9.742332', N'78.497139'), 207 | (N'Illinois', N'86', N'228431535437864', N'1', N'9.533221', N'89.949775'), 208 | (N'Maryland', N'542', N'534208844488374', N'1', N'4.449566', N'32.713011'), 209 | (N'Pennsylvania', N'267', N'322914577977063', N'0', N'9.541348', N'10.027478'), 210 | (N'Florida', N'775', N'555509755103849', NULL, N'2.867655', N'15.365524'), 211 | (N'Tennessee', N'482', N'951940052057523', NULL, N'5.102333', N'79.894753'), 212 | (N'Mississippi', N'725', N'526612424006581', N'0', N'8.351639', N'39.874928'), 213 | (N'Louisiana', N'426', N'256391502858805', N'0', N'9.638287', N'2.882451'), 214 | (N'Rhode Island', N'89', N'665977025550029', N'1', N'5.408568', N'13.630778'), 215 | (N'South Dakota', N'877', N'223636030144133', N'1', N'9.728685', N'28.401720'), 216 | (N'Minnesota', N'489', N'393884700308663', N'1', N'5.184263', N'0.922502'), 217 | (N'Rhode Island', N'116', N'809801102354586', NULL, N'2.519701', N'17.845156'), 218 | (N'Alabama', N'368', N'36975848101666', NULL, N'8.283764', N'29.088656'), 219 | (N'New Mexico', N'761', N'975666558560619', N'0', N'6.513526', N'83.556715'), 220 | (N'Kentucky', N'551', N'254662511041749', N'1', N'7.053028', N'96.214242'), 221 | (N'Nevada', N'907', N'481523172334959', N'0', N'2.149908', N'99.661604'), 222 | (N'West Virginia', N'406', N'826349293887338', N'1', N'2.121468', N'84.359757'), 223 | (N'Oregon', N'782', N'383089866103184', N'0', N'8.792089', N'57.362583'), 224 | (N'Kentucky', N'850', N'597418742541768', N'0', N'6.467831', N'83.639447'), 225 | (N'Ohio', N'859', N'476224848798156', N'0', N'3.777522', N'94.274086'), 226 | (N'Kansas', N'177', N'618119660113321', NULL, N'0.537073', N'81.365734'), 227 | (N'Alabama', N'480', N'766694723008655', N'0', N'6.088761', N'67.206033'), 228 | (N'New York', N'386', N'737099754163576', N'0', N'6.182096', N'93.763742'), 229 | (N'Nevada', N'244', N'921832524684993', N'1', N'9.582929', N'30.342262'), 230 | (N'Alabama', N'865', N'647212418120324', NULL, N'7.375068', N'43.208669'), 231 | (N'Indiana', N'640', N'668115055398736', N'1', N'2.489768', N'2.136369'), 232 | (N'Ohio', N'978', N'482942011804563', NULL, N'6.934648', N'4.288894'), 233 | (N'Utah', N'286', N'1118708113326247', NULL, N'7.092621', N'0.795106'), 234 | (N'Colorado', N'125', N'239744331624729', NULL, N'6.588813', N'78.752308'), 235 | (N'Oklahoma', N'890', N'4466486203153', N'1', N'3.879608', N'62.912128'), 236 | (N'Wisconsin', N'737', N'98467093313622', N'0', N'9.681096', N'76.138531'), 237 | (N'New Jersey', N'402', N'1115356443170186', N'0', N'9.880235', N'9.831263'), 238 | (N'New York', N'122', N'65145224023590', NULL, N'3.523463', N'47.280617'), 239 | (N'Nevada', N'161', N'1028716926570715', N'1', N'1.892983', N'83.001698'), 240 | (N'Florida', N'852', N'821947397165997', NULL, N'2.170999', N'59.824323'), 241 | (N'Iowa', N'797', N'1043944385143891', NULL, N'0.052295', N'95.696012'), 242 | (N'Connecticut', N'634', N'828311612099222', NULL, N'7.699139', N'15.082499'), 243 | (N'Michigan', N'996', N'692598896545960', N'1', N'2.230148', N'82.284110'), 244 | (N'Washington', N'328', N'340263233490463', NULL, N'0.512088', N'33.307521'), 245 | (N'Maryland', N'78', N'350143250522664', N'1', N'2.503217', N'15.654320'), 246 | (N'Florida', N'905', N'1063383841503096', N'0', N'3.438764', N'79.605267'), 247 | (N'Montana', N'65', N'1054948972424948', NULL, N'9.385435', N'60.572533'), 248 | (N'Colorado', N'861', N'101458753532292', N'0', N'8.461140', N'77.187894'), 249 | (N'Vermont', N'853', N'293084838306238', N'0', N'8.663382', N'42.850323'), 250 | (N'Kentucky', N'15', N'1028297384299408', N'1', N'2.251733', N'92.761700'), 251 | (N'Rhode Island', N'837', N'889786649558040', N'0', N'7.983315', N'97.715033'), 252 | (N'Missouri', N'443', N'973017816343045', NULL, N'5.242719', N'40.281725'), 253 | (N'Maine', N'722', N'904478680586972', N'1', N'0.044733', N'79.781785'), 254 | (N'Ohio', N'774', N'1059003133767711', N'0', N'4.001221', N'13.154652'), 255 | (N'Illinois', N'1000', N'408508465909176', N'0', N'0.968483', N'80.076757'), 256 | (N'Georgia', N'756', N'729795962743873', NULL, N'7.713511', N'27.886789'), 257 | (N'Alaska', N'366', N'598572016489556', N'1', N'1.310951', N'41.003372'), 258 | (N'Arizona', N'877', N'752815711805345', N'1', N'3.076544', N'10.536333'), 259 | (N'Idaho', N'369', N'865177532818355', N'1', N'5.414114', N'3.535011'), 260 | (N'Massachusetts', N'590', N'550863116709607', N'1', N'2.399977', N'44.958202'), 261 | (N'Oklahoma', N'912', N'637759837417494', NULL, N'7.435135', N'36.183453'), 262 | (N'South Dakota', N'638', N'842380487881197', NULL, N'3.607925', N'7.961522'), 263 | (N'Pennsylvania', N'519', N'324527901997343', N'1', N'1.984942', N'17.250572'), 264 | (N'Washington', N'117', N'408297970262121', NULL, N'5.953507', N'22.045555'), 265 | (N'Arkansas', N'214', N'344543836645436', NULL, N'7.202114', N'50.404249'), 266 | (N'Georgia', N'639', N'1030245231066475', NULL, N'6.411063', N'67.367999'), 267 | (N'Nebraska', N'926', N'451411897758692', N'0', N'0.190323', N'36.809256'), 268 | (N'South Dakota', N'728', N'560736466750628', NULL, N'8.107699', N'98.589766'), 269 | (N'Montana', N'670', N'770930781043968', NULL, N'4.112608', N'72.469840'), 270 | (N'Pennsylvania', N'454', N'788834791972128', N'0', N'2.674260', N'72.913375'), 271 | (N'Connecticut', N'626', N'1067308078619975', N'0', N'8.949051', N'25.203585'), 272 | (N'Arizona', N'128', N'750380484587695', N'1', N'2.164863', N'50.791474'), 273 | (N'Tennessee', N'336', N'592493104143663', NULL, N'5.056067', N'75.964816'), 274 | (N'New Mexico', N'923', N'940746536970575', N'0', N'8.753246', N'68.907403'), 275 | (N'Missouri', N'91', N'1010932116757719', N'1', N'8.021768', N'65.294472'), 276 | (N'Wyoming', N'626', N'762998281620993', N'0', N'2.666865', N'48.547342'), 277 | (N'New Hampshire', N'200', N'513725188056515', N'1', N'9.205457', N'50.259080'), 278 | (N'Idaho', N'563', N'234944261282886', N'1', N'2.571676', N'95.671244'), 279 | (N'Louisiana', N'136', N'1062324544139294', NULL, N'2.901048', N'44.612417'), 280 | (N'Oklahoma', N'502', N'508221093262088', N'0', N'2.341677', N'14.123576'), 281 | (N'Iowa', N'521', N'207563597220590', N'0', N'3.340830', N'16.073611'), 282 | (N'Missouri', N'334', N'249253930985972', N'1', N'2.966679', N'94.022198'), 283 | (N'Idaho', N'373', N'32408361562888', NULL, N'9.672117', N'85.177857'), 284 | (N'New Jersey', N'822', N'1055598525834250', N'0', N'8.713785', N'32.583388'), 285 | (N'Colorado', N'76', N'242996748170513', NULL, N'6.895828', N'43.641239'), 286 | (N'Louisiana', N'122', N'161549057017406', N'1', N'0.516669', N'8.879165'), 287 | (N'Virginia', N'49', N'821099798808939', NULL, N'3.796899', N'64.001718'), 288 | (N'Idaho', N'906', N'244807993768671', N'0', N'9.510789', N'72.394906'), 289 | (N'South Dakota', N'799', N'99883905638808', NULL, N'7.943288', N'23.948743'), 290 | (N'North Dakota', N'49', N'843254467934380', NULL, N'2.111595', N'70.199770'), 291 | (N'Arizona', N'638', N'1045930285696252', NULL, N'2.421815', N'62.890613'), 292 | (N'Nebraska', N'568', N'446195605605125', N'1', N'6.190431', N'16.404974'), 293 | (N'Alabama', N'889', N'449645003703458', N'0', N'3.725886', N'17.973888'), 294 | (N'Virginia', N'684', N'698547646528746', N'0', N'9.566822', N'38.639014'), 295 | (N'Washington', N'869', N'875474747656161', N'0', N'6.528122', N'93.045587') 296 | GO 297 | 298 | -- ---------------------------- 299 | -- Records of [CS_MTCARS] 300 | -- ---------------------------- 301 | INSERT INTO [dbo].[CS_MTCARS] VALUES 302 | (N'21.0', N'6', N'160.0', N'110', N'3.90', N'2.620', N'16.46', N'0', N'1', N'4', N'4'), 303 | (N'21.0', N'6', N'160.0', N'110', N'3.90', N'2.875', N'17.02', N'0', N'1', N'4', N'4'), 304 | (N'22.8', N'4', N'108.0', N'93', N'3.85', N'2.320', N'18.61', N'1', N'1', N'4', N'1'), 305 | (N'21.4', N'6', N'258.0', N'110', N'3.08', N'3.215', N'19.44', N'1', N'0', N'3', N'1'), 306 | (N'18.7', N'8', N'360.0', N'175', N'3.15', N'3.440', N'17.02', N'0', N'0', N'3', N'2'), 307 | (N'18.1', N'6', N'225.0', N'105', N'2.76', N'3.460', N'20.22', N'1', N'0', N'3', N'1'), 308 | (N'14.3', N'8', N'360.0', N'245', N'3.21', N'3.570', N'15.84', N'0', N'0', N'3', N'4'), 309 | (N'24.4', N'4', N'146.7', N'62', N'3.69', N'3.190', N'20.00', N'1', N'0', N'4', N'2'), 310 | (N'22.8', N'4', N'140.8', N'95', N'3.92', N'3.150', N'22.90', N'1', N'0', N'4', N'2'), 311 | (N'19.2', N'6', N'167.6', N'123', N'3.92', N'3.440', N'18.30', N'1', N'0', N'4', N'4'), 312 | (N'17.8', N'6', N'167.6', N'123', N'3.92', N'3.440', N'18.90', N'1', N'0', N'4', N'4'), 313 | (N'16.4', N'8', N'275.8', N'180', N'3.07', N'4.070', N'17.40', N'0', N'0', N'3', N'3'), 314 | (N'17.3', N'8', N'275.8', N'180', N'3.07', N'3.730', N'17.60', N'0', N'0', N'3', N'3'), 315 | (N'15.2', N'8', N'275.8', N'180', N'3.07', N'3.780', N'18.00', N'0', N'0', N'3', N'3'), 316 | (N'10.4', N'8', N'472.0', N'205', N'2.93', N'5.250', N'17.98', N'0', N'0', N'3', N'4'), 317 | (N'10.4', N'8', N'460.0', N'215', N'3.00', N'5.424', N'17.82', N'0', N'0', N'3', N'4'), 318 | (N'14.7', N'8', N'440.0', N'230', N'3.23', N'5.345', N'17.42', N'0', N'0', N'3', N'4'), 319 | (N'32.4', N'4', N'78.7', N'66', N'4.08', N'2.200', N'19.47', N'1', N'1', N'4', N'1'), 320 | (N'30.4', N'4', N'75.7', N'52', N'4.93', N'1.615', N'18.52', N'1', N'1', N'4', N'2'), 321 | (N'33.9', N'4', N'71.1', N'65', N'4.22', N'1.835', N'19.90', N'1', N'1', N'4', N'1'), 322 | (N'21.5', N'4', N'120.1', N'97', N'3.70', N'2.465', N'20.01', N'1', N'0', N'3', N'1'), 323 | (N'15.5', N'8', N'318.0', N'150', N'2.76', N'3.520', N'16.87', N'0', N'0', N'3', N'2'), 324 | (N'15.2', N'8', N'304.0', N'150', N'3.15', N'3.435', N'17.30', N'0', N'0', N'3', N'2'), 325 | (N'13.3', N'8', N'350.0', N'245', N'3.73', N'3.840', N'15.41', N'0', N'0', N'3', N'4'), 326 | (N'19.2', N'8', N'400.0', N'175', N'3.08', N'3.845', N'17.05', N'0', N'0', N'3', N'2'), 327 | (N'27.3', N'4', N'79.0', N'66', N'4.08', N'1.935', N'18.90', N'1', N'1', N'4', N'1'), 328 | (N'26.0', N'4', N'120.3', N'91', N'4.43', N'2.140', N'16.70', N'0', N'1', N'5', N'2'), 329 | (N'30.4', N'4', N'95.1', N'113', N'3.77', N'1.513', N'16.90', N'1', N'1', N'5', N'2'), 330 | (N'15.8', N'8', N'351.0', N'264', N'4.22', N'3.170', N'14.50', N'0', N'1', N'5', N'4'), 331 | (N'19.7', N'6', N'145.0', N'175', N'3.62', N'2.770', N'15.50', N'0', N'1', N'5', N'6'), 332 | (N'15.0', N'8', N'301.0', N'335', N'3.54', N'3.570', N'14.60', N'0', N'1', N'5', N'8'), 333 | (N'21.4', N'4', N'121.0', N'109', N'4.11', N'2.780', N'18.60', N'1', N'1', N'4', N'2') 334 | GO 335 | -------------------------------------------------------------------------------- /man/rsqlserver-package.Rd: -------------------------------------------------------------------------------- 1 | \name{rsqlserver-package} 2 | \alias{rsqlserver-package} 3 | \alias{rsqlserver} 4 | \docType{package} 5 | \title{ 6 | SQL Server interface for R 7 | } 8 | \description{ 9 | Database Interface R driver for SQL server. 10 | This package wraps the System.Data.SqlClient 11 | assembly and provide a handy R interface. 12 | } 13 | \details{ 14 | \tabular{ll}{ 15 | Package: \tab rsqlserver\cr 16 | Type: \tab Package\cr 17 | Version: \tab 1.0\cr 18 | Date: \tab 2013-10-23\cr 19 | License: \tab GPL-2\cr 20 | } 21 | } 22 | \author{ 23 | Amine Gassem (agstudy) 24 | } 25 | 26 | \references{ 27 | } 28 | 29 | \keyword{ package } 30 | \keyword{ SQL server } 31 | \seealso{ 32 | \code{{RODBC}} 33 | } 34 | -------------------------------------------------------------------------------- /rsqlserver.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: knitr 13 | LaTeX: pdfLaTeX 14 | 15 | BuildType: Package 16 | PackageInstallArgs: --no-test-load 17 | PackageRoxygenize: rd 18 | -------------------------------------------------------------------------------- /src.nocompile/.nuget/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /src.nocompile/Makefile.mak: -------------------------------------------------------------------------------- 1 | 2 | ifeq "$(BuildConfiguration)" "" 3 | BuildConfiguration:=Debug 4 | endif 5 | 6 | SLN:= rsqlserver.net.sln 7 | RSQLSERVER_BINDIR:=./rsqlserver.net/bin/$(BuildConfiguration) 8 | INSTDIR:= ../inst 9 | RSQLSERVER_BINs:= $(RSQLSERVER_BINDIR)/*.dll $(RSQLSERVER_BINDIR)/*.pdb 10 | MSB := C:/WINDOWS/Microsoft.NET/Framework/v4.0.30319/MSBuild.exe 11 | MODE:=Build 12 | SLNPROPERTIES:=/p:Configuration=$(BuildConfiguration) 13 | 14 | all: instdir SQLSERVER_RLib 15 | 16 | RSQLSERVER_LibComp: 17 | $(MSB) $(SLN) /t:$(MODE) $(SLNPROPERTIES) 18 | 19 | SQLSERVER_RLib: RSQLSERVER_LibComp 20 | -cp -u -p $(RSQLSERVER_BINs) $(INSTDIR)/libs 21 | 22 | instdir: 23 | -@rm -rf $(INSTDIR)/libs 24 | # the following two lines are required, even if empty folder, 25 | # otherwise R complains at package load time. 26 | -@mkdir -p $(INSTDIR)/libs/i386 27 | -@mkdir -p $(INSTDIR)/libs/x64 28 | -@mkdir -p $(INSTDIR)/libs 2>/dev/null 29 | 30 | .PHONY: all 31 | 32 | -------------------------------------------------------------------------------- /src.nocompile/Makefile.win: -------------------------------------------------------------------------------- 1 | 2 | # Emacs please make this -*- mode: makefile; tab-width: 8 -*- 3 | # 4 | # 5 | 6 | ifeq "$(BuildConfiguration)" "" 7 | BuildConfiguration:=Debug 8 | endif 9 | 10 | SLN:= rsqlserver.net.sln 11 | RSQLSERVERBINDIR:=./rsqlserver.net/bin/$(BuildConfiguration) 12 | 13 | INSTDIR:= ../inst 14 | RSQLSERVERBINs:= $(RSQLSERVERBINDIR)/*.dll $(RSQLSERVERBINDIR)/*.pdb 15 | MSB :=C:/WINDOWS/Microsoft.NET/Framework/v4.0.30319/MSBuild.exe 16 | MODE:=Build 17 | SLNPROPERTIES:=/p:Configuration=$(BuildConfiguration) 18 | all : 19 | # all: instdir RSQLSERVERLib 20 | 21 | RSQLSERVERLibComp: 22 | $(MSB) $(SLN) /t:$(MODE) $(SLNPROPERTIES) 23 | 24 | RSQLSERVERLib: RSQLSERVERLibComp 25 | # -@cp -u -p $(RSQLSERVERBINs) $(INSTDIR)/libs 26 | 27 | instdir: 28 | -@rm -rf $(INSTDIR)/libs 29 | # the following two lines are required, even if empty folder, otherwise R complains at package load time. 30 | -@mkdir -p $(INSTDIR)/libs/i386 31 | -@mkdir -p $(INSTDIR)/libs/x64 32 | -@mkdir -p $(INSTDIR)/libs 2>/dev/null 33 | 34 | .PHONY: all 35 | -------------------------------------------------------------------------------- /src.nocompile/install.libs.R: -------------------------------------------------------------------------------- 1 | libarch <- if (nzchar(R_ARCH)) paste('libs', R_ARCH, sep='') else "libs" 2 | dest <- file.path(R_PACKAGE_DIR, libarch) 3 | dest.dll <- file.path(R_PACKAGE_DIR, 'libs') 4 | src <- file.path(R_PACKAGE_SOURCE ,"src/rsqlserver.net/bin/Debug") 5 | files <- Sys.glob(file.path(src, c("*.dll","*.config"))) 6 | dest.files = file.path(file.path(R_PACKAGE_SOURCE,"libs"),"*.dll") 7 | if (length(Sys.glob(dest.files))) 8 | lapply(Sys.glob(dest.files),file.remove(files)) 9 | dir.create(dest, recursive = TRUE, showWarnings = FALSE) 10 | file.copy(files, dest.dll, overwrite = TRUE) -------------------------------------------------------------------------------- /src.nocompile/packages/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agstudy/rsqlserver/4f54256507affe3fe31c4e9b635a7bcfc1becece/src.nocompile/packages/.gitignore -------------------------------------------------------------------------------- /src.nocompile/packages/LumenWorksCsvReader.3.9.1/LumenWorksCsvReader.3.9.1.nupkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agstudy/rsqlserver/4f54256507affe3fe31c4e9b635a7bcfc1becece/src.nocompile/packages/LumenWorksCsvReader.3.9.1/LumenWorksCsvReader.3.9.1.nupkg -------------------------------------------------------------------------------- /src.nocompile/packages/LumenWorksCsvReader.3.9.1/lib/net20/LumenWorks.Framework.IO.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agstudy/rsqlserver/4f54256507affe3fe31c4e9b635a7bcfc1becece/src.nocompile/packages/LumenWorksCsvReader.3.9.1/lib/net20/LumenWorks.Framework.IO.dll -------------------------------------------------------------------------------- /src.nocompile/packages/LumenWorksCsvReader.3.9.1/lib/net20/LumenWorks.Framework.IO.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agstudy/rsqlserver/4f54256507affe3fe31c4e9b635a7bcfc1becece/src.nocompile/packages/LumenWorksCsvReader.3.9.1/lib/net20/LumenWorks.Framework.IO.pdb -------------------------------------------------------------------------------- /src.nocompile/packages/R.NET.1.5.5/R.NET.1.5.5.nupkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agstudy/rsqlserver/4f54256507affe3fe31c4e9b635a7bcfc1becece/src.nocompile/packages/R.NET.1.5.5/R.NET.1.5.5.nupkg -------------------------------------------------------------------------------- /src.nocompile/packages/R.NET.1.5.5/lib/net40/RDotNet.NativeLibrary.XML: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | RDotNet.NativeLibrary 5 | 6 | 7 | 8 | 9 | A proxy for unmanaged dynamic link library (DLL). 10 | 11 | 12 | 13 | 14 | Creates a proxy for the specified dll. 15 | 16 | The DLL's name. 17 | 18 | 19 | 20 | Creates the delegate function for the specified function defined in the DLL. 21 | 22 | The type of delegate. 23 | The delegate. 24 | 25 | 26 | 27 | Creates the delegate function for the specified function defined in the DLL. 28 | 29 | The type of delegate. 30 | The name of function. 31 | The delegate. 32 | 33 | 34 | 35 | Gets the handle of the specified entry. 36 | 37 | The name of function. 38 | The handle. 39 | 40 | 41 | 42 | Adds a directory to the search path used to locate DLLs for the application. 43 | 44 | 45 | Calls SetDllDirectory in the kernel32.dll on Windows. 46 | 47 | 48 | The directory to be added to the search path. 49 | If this parameter is an empty string (""), the call removes the current directory from the default DLL search order. 50 | If this parameter is NULL, the function restores the default search order. 51 | 52 | If the function succeeds, the return value is nonzero. 53 | 54 | 55 | 56 | Collection of utility methods for operating systems. 57 | 58 | 59 | 60 | 61 | Gets the platform on which the current process runs. 62 | 63 | 64 | 's platform is not even on Mac OS X. 65 | This method returns when the current process runs on Mac OS X. 66 | This method uses UNIX's uname command to check the operating system, 67 | so this method cannot check the OS correctly if the PATH environment variable is changed (will returns ). 68 | 69 | The current platform. 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /src.nocompile/packages/R.NET.1.5.5/lib/net40/RDotNet.NativeLibrary.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agstudy/rsqlserver/4f54256507affe3fe31c4e9b635a7bcfc1becece/src.nocompile/packages/R.NET.1.5.5/lib/net40/RDotNet.NativeLibrary.dll -------------------------------------------------------------------------------- /src.nocompile/packages/R.NET.1.5.5/lib/net40/RDotNet.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agstudy/rsqlserver/4f54256507affe3fe31c4e9b635a7bcfc1becece/src.nocompile/packages/R.NET.1.5.5/lib/net40/RDotNet.dll -------------------------------------------------------------------------------- /src.nocompile/packages/log4net.2.0.8/lib/net20-full/log4net.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agstudy/rsqlserver/4f54256507affe3fe31c4e9b635a7bcfc1becece/src.nocompile/packages/log4net.2.0.8/lib/net20-full/log4net.dll -------------------------------------------------------------------------------- /src.nocompile/packages/log4net.2.0.8/lib/net35-client/log4net.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agstudy/rsqlserver/4f54256507affe3fe31c4e9b635a7bcfc1becece/src.nocompile/packages/log4net.2.0.8/lib/net35-client/log4net.dll -------------------------------------------------------------------------------- /src.nocompile/packages/log4net.2.0.8/lib/net35-full/log4net.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agstudy/rsqlserver/4f54256507affe3fe31c4e9b635a7bcfc1becece/src.nocompile/packages/log4net.2.0.8/lib/net35-full/log4net.dll -------------------------------------------------------------------------------- /src.nocompile/packages/log4net.2.0.8/lib/net40-client/log4net.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agstudy/rsqlserver/4f54256507affe3fe31c4e9b635a7bcfc1becece/src.nocompile/packages/log4net.2.0.8/lib/net40-client/log4net.dll -------------------------------------------------------------------------------- /src.nocompile/packages/log4net.2.0.8/lib/net40-full/log4net.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agstudy/rsqlserver/4f54256507affe3fe31c4e9b635a7bcfc1becece/src.nocompile/packages/log4net.2.0.8/lib/net40-full/log4net.dll -------------------------------------------------------------------------------- /src.nocompile/packages/log4net.2.0.8/lib/net45-full/log4net.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agstudy/rsqlserver/4f54256507affe3fe31c4e9b635a7bcfc1becece/src.nocompile/packages/log4net.2.0.8/lib/net45-full/log4net.dll -------------------------------------------------------------------------------- /src.nocompile/packages/log4net.2.0.8/lib/netstandard1.3/log4net.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agstudy/rsqlserver/4f54256507affe3fe31c4e9b635a7bcfc1becece/src.nocompile/packages/log4net.2.0.8/lib/netstandard1.3/log4net.dll -------------------------------------------------------------------------------- /src.nocompile/packages/log4net.2.0.8/log4net.2.0.8.nupkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agstudy/rsqlserver/4f54256507affe3fe31c4e9b635a7bcfc1becece/src.nocompile/packages/log4net.2.0.8/log4net.2.0.8.nupkg -------------------------------------------------------------------------------- /src.nocompile/packages/repositories.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /src.nocompile/packages/xunit.1.9.2/lib/net20/xunit.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agstudy/rsqlserver/4f54256507affe3fe31c4e9b635a7bcfc1becece/src.nocompile/packages/xunit.1.9.2/lib/net20/xunit.dll -------------------------------------------------------------------------------- /src.nocompile/packages/xunit.1.9.2/lib/net20/xunit.dll.tdnet: -------------------------------------------------------------------------------- 1 | 2 | xUnit.net {0}.{1}.{2} build {3} 3 | xunit.runner.tdnet.dll 4 | Xunit.Runner.TdNet.TdNetRunner 5 | -------------------------------------------------------------------------------- /src.nocompile/packages/xunit.1.9.2/lib/net20/xunit.runner.msbuild.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agstudy/rsqlserver/4f54256507affe3fe31c4e9b635a7bcfc1becece/src.nocompile/packages/xunit.1.9.2/lib/net20/xunit.runner.msbuild.dll -------------------------------------------------------------------------------- /src.nocompile/packages/xunit.1.9.2/lib/net20/xunit.runner.tdnet.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agstudy/rsqlserver/4f54256507affe3fe31c4e9b635a7bcfc1becece/src.nocompile/packages/xunit.1.9.2/lib/net20/xunit.runner.tdnet.dll -------------------------------------------------------------------------------- /src.nocompile/packages/xunit.1.9.2/lib/net20/xunit.runner.utility.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agstudy/rsqlserver/4f54256507affe3fe31c4e9b635a7bcfc1becece/src.nocompile/packages/xunit.1.9.2/lib/net20/xunit.runner.utility.dll -------------------------------------------------------------------------------- /src.nocompile/packages/xunit.1.9.2/xunit.1.9.2.nupkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agstudy/rsqlserver/4f54256507affe3fe31c4e9b635a7bcfc1becece/src.nocompile/packages/xunit.1.9.2/xunit.1.9.2.nupkg -------------------------------------------------------------------------------- /src.nocompile/packages/xunit.1.9.2/xunit.1.9.2.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | xunit 5 | 1.9.2 6 | xUnit.net 7 | James Newkirk, Brad Wilson 8 | James Newkirk, Brad Wilson 9 | http://xunit.codeplex.com/license 10 | https://github.com/xunit/xunit 11 | http://download.codeplex.com/Download?ProjectName=xunit&DownloadId=365445 12 | false 13 | xUnit.net is a developer testing framework, built to support Test Driven Development, with a design goal of extreme simplicity and alignment with framework features. 14 | en-US 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /src.nocompile/packages/xunit.runners.1.9.2/tools/HTML.xslt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | ]]> 6 | 7 | 8 | 9 | xUnit.net Test Results - <xsl:value-of select="@name"/> 10 | 11 | 30 | 41 | 42 | 43 |

Assemblies Run

44 | 45 | 46 |

Summary

47 |
48 | Tests run:   49 | Failures: , 50 | Skipped: , 51 | Run time: s 52 |
53 | 54 |
55 |

Failed tests

56 | 57 |
58 | 59 |
60 |

Failed fixtures

61 | 62 |
63 | 64 |
65 |

Skipped tests

66 | 67 |
68 |
69 |

All tests

70 |
Click test class name to expand/collapse test details
71 | 72 | 73 | 74 |
75 | 76 | 77 |
78 |
79 | 80 | 81 |
82 | altrow 83 | s 84 | Skipped 85 | 86 | 87 |   88 | : 89 |
90 | 91 |
92 |
93 | 94 |

Output

95 |
96 |
97 |
98 |
99 | 100 | 101 | :
102 | Stack Trace:
103 |
104 |
105 | 106 | 107 |

108 | s 109 | 110 | ToggleClass('class') 111 | ToggleClass('class') 112 | 113 | 114 |   115 |  ( tests) 116 | 117 |
118 |

119 |
120 | display: none; 121 | class 122 | 123 |
124 |
125 | 126 |
-------------------------------------------------------------------------------- /src.nocompile/packages/xunit.runners.1.9.2/tools/NUnitXml.xslt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | False 35 | True 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | False 54 | True 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | False 80 | True 81 | 82 | 83 | 84 | False 85 | True 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | -------------------------------------------------------------------------------- /src.nocompile/packages/xunit.runners.1.9.2/tools/xunit.console.clr4.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agstudy/rsqlserver/4f54256507affe3fe31c4e9b635a7bcfc1becece/src.nocompile/packages/xunit.runners.1.9.2/tools/xunit.console.clr4.exe -------------------------------------------------------------------------------- /src.nocompile/packages/xunit.runners.1.9.2/tools/xunit.console.clr4.exe.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |
6 | 7 | 8 | 9 | 10 | 14 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src.nocompile/packages/xunit.runners.1.9.2/tools/xunit.console.clr4.x86.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agstudy/rsqlserver/4f54256507affe3fe31c4e9b635a7bcfc1becece/src.nocompile/packages/xunit.runners.1.9.2/tools/xunit.console.clr4.x86.exe -------------------------------------------------------------------------------- /src.nocompile/packages/xunit.runners.1.9.2/tools/xunit.console.clr4.x86.exe.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |
6 | 7 | 8 | 9 | 10 | 14 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src.nocompile/packages/xunit.runners.1.9.2/tools/xunit.console.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agstudy/rsqlserver/4f54256507affe3fe31c4e9b635a7bcfc1becece/src.nocompile/packages/xunit.runners.1.9.2/tools/xunit.console.exe -------------------------------------------------------------------------------- /src.nocompile/packages/xunit.runners.1.9.2/tools/xunit.console.exe.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |
6 | 7 | 8 | 9 | 10 | 14 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src.nocompile/packages/xunit.runners.1.9.2/tools/xunit.console.x86.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agstudy/rsqlserver/4f54256507affe3fe31c4e9b635a7bcfc1becece/src.nocompile/packages/xunit.runners.1.9.2/tools/xunit.console.x86.exe -------------------------------------------------------------------------------- /src.nocompile/packages/xunit.runners.1.9.2/tools/xunit.console.x86.exe.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |
6 | 7 | 8 | 9 | 10 | 14 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src.nocompile/packages/xunit.runners.1.9.2/tools/xunit.gui.clr4.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agstudy/rsqlserver/4f54256507affe3fe31c4e9b635a7bcfc1becece/src.nocompile/packages/xunit.runners.1.9.2/tools/xunit.gui.clr4.exe -------------------------------------------------------------------------------- /src.nocompile/packages/xunit.runners.1.9.2/tools/xunit.gui.clr4.x86.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agstudy/rsqlserver/4f54256507affe3fe31c4e9b635a7bcfc1becece/src.nocompile/packages/xunit.runners.1.9.2/tools/xunit.gui.clr4.x86.exe -------------------------------------------------------------------------------- /src.nocompile/packages/xunit.runners.1.9.2/tools/xunit.gui.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agstudy/rsqlserver/4f54256507affe3fe31c4e9b635a7bcfc1becece/src.nocompile/packages/xunit.runners.1.9.2/tools/xunit.gui.exe -------------------------------------------------------------------------------- /src.nocompile/packages/xunit.runners.1.9.2/tools/xunit.gui.x86.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agstudy/rsqlserver/4f54256507affe3fe31c4e9b635a7bcfc1becece/src.nocompile/packages/xunit.runners.1.9.2/tools/xunit.gui.x86.exe -------------------------------------------------------------------------------- /src.nocompile/packages/xunit.runners.1.9.2/tools/xunit.runner.msbuild.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agstudy/rsqlserver/4f54256507affe3fe31c4e9b635a7bcfc1becece/src.nocompile/packages/xunit.runners.1.9.2/tools/xunit.runner.msbuild.dll -------------------------------------------------------------------------------- /src.nocompile/packages/xunit.runners.1.9.2/tools/xunit.runner.utility.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agstudy/rsqlserver/4f54256507affe3fe31c4e9b635a7bcfc1becece/src.nocompile/packages/xunit.runners.1.9.2/tools/xunit.runner.utility.dll -------------------------------------------------------------------------------- /src.nocompile/packages/xunit.runners.1.9.2/xunit.runners.1.9.2.nupkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agstudy/rsqlserver/4f54256507affe3fe31c4e9b635a7bcfc1becece/src.nocompile/packages/xunit.runners.1.9.2/xunit.runners.1.9.2.nupkg -------------------------------------------------------------------------------- /src.nocompile/packages/xunit.runners.1.9.2/xunit.runners.1.9.2.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | xunit.runners 5 | 1.9.2 6 | xUnit.net: Runners 7 | James Newkirk, Brad Wilson 8 | James Newkirk, Brad Wilson 9 | http://xunit.codeplex.com/license 10 | https://github.com/xunit/xunit 11 | http://download.codeplex.com/Download?ProjectName=xunit&DownloadId=365445 12 | false 13 | Runners for the xUnit.net framework, including Console, GUI, and MSBuild. 14 | en-US 15 | 16 | -------------------------------------------------------------------------------- /src.nocompile/rsqlserver.net.Test/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 |
5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /src.nocompile/rsqlserver.net.Test/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("rsqlserver.net.Test")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("rsqlserver.net.Test")] 13 | [assembly: AssemblyCopyright("Copyright © 2013")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("fbcaca5f-9f91-40b5-afea-66d1a8ca8aa8")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | 38 | [assembly: log4net.Config.XmlConfigurator(Watch = true)] 39 | -------------------------------------------------------------------------------- /src.nocompile/rsqlserver.net.Test/TestSqlDataHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data.SqlClient; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using Xunit; 9 | 10 | namespace rsqlserver.net.Test 11 | { 12 | 13 | public class TestSqlDataHelper 14 | { 15 | 16 | private static string myConnectionString = "Server=localhost;Database=rsqlserverdb;User Id=sa;Password=Password12!;"; 17 | static SqlConnection myConnection = new SqlConnection(myConnectionString); 18 | 19 | private static SqlDataHelper helper; 20 | 21 | 22 | 23 | public static void TestGetProperty() 24 | { 25 | 26 | try 27 | { 28 | myConnection.Open(); 29 | var helper = new SqlDataHelper(); 30 | var state = helper.GetConnectionProperty(myConnection, "State"); 31 | myConnection.Close(); 32 | foreach (var prop in myConnection.GetType().GetProperties()) 33 | Console.WriteLine(helper.GetConnectionProperty(myConnection, prop.Name)); 34 | } 35 | catch (Exception e) 36 | { 37 | Console.WriteLine(e.ToString()); 38 | } 39 | finally 40 | { 41 | myConnection.Close(); 42 | } 43 | Console.ReadLine(); 44 | } 45 | public static void TestGetReaderProperty() 46 | { 47 | 48 | try 49 | { 50 | myConnection.Open(); 51 | SqlCommand cmd = new SqlCommand("select * from sys.tables"); 52 | cmd.Connection = myConnection; 53 | var reader = cmd.ExecuteReader(); 54 | var helper = new SqlDataHelper(reader); 55 | 56 | foreach (var prop in myConnection.GetType().GetProperties()) 57 | Console.WriteLine(helper.GetReaderProperty(prop.Name)); 58 | } 59 | catch (Exception e) 60 | { 61 | Console.WriteLine(e.ToString()); 62 | } 63 | finally 64 | { 65 | myConnection.Close(); 66 | } 67 | Console.ReadLine(); 68 | } 69 | 70 | [Fact] 71 | public static void TestFetch() 72 | { 73 | using (SqlConnection myConnection = new SqlConnection(myConnectionString)) 74 | { 75 | myConnection.Open(); 76 | SqlDataReader myReader = null; 77 | var query = "SELECT mpg, cyl, wt FROM CS_MTCARS"; 78 | SqlCommand myCommand = new SqlCommand(query, myConnection); 79 | myReader = myCommand.ExecuteReader(); 80 | helper = new SqlDataHelper(myReader); 81 | var result = helper.Fetch(20); 82 | Assert.Equal(20, result); 83 | Assert.Equal(helper.ResultSet.Keys.Count, 3); 84 | string[] cols = new string[] { "mpg", "cyl", "wt" }; 85 | foreach (string key in helper.ResultSet.Keys) 86 | Assert.Contains(key, cols); 87 | myConnection.Close(); 88 | } 89 | 90 | Assert.Equal(helper.ResultSet["mpg"].Length, helper.Fetched); 91 | Assert.Equal(helper.ResultSet.Keys.Count, helper.Cnames.Length); 92 | } 93 | [Fact] 94 | public static void TestSqlBulkCopy() 95 | { 96 | misc.SqlBulkCopy(myConnectionString, "../../../../inst/data/CS_BIG.csv", "dbo.CS_BIG", true); 97 | } 98 | [Fact] 99 | public static void TestFetch_BIG_DATE_TABLE() 100 | { 101 | using (SqlConnection myConnection = new SqlConnection(myConnectionString)) 102 | { 103 | myConnection.Open(); 104 | SqlDataReader myReader = null; 105 | var query = "SELECT * FROM CS_DATE"; 106 | 107 | SqlCommand myCommand = new SqlCommand(query, myConnection); 108 | myReader = myCommand.ExecuteReader(); 109 | helper = new SqlDataHelper(myReader); 110 | var result = helper.Fetch(5); 111 | Assert.Equal(5, result); 112 | myConnection.Close(); 113 | } 114 | } 115 | static void Main(string[] args) 116 | { 117 | myConnection.Open(); 118 | SqlDataReader myReader = null; 119 | var helper = new SqlDataHelper(); 120 | 121 | var state = helper.GetConnectionProperty(myConnection, "State"); 122 | var query = "SELECT * " + "FROM TABLE_BUG"; 123 | SqlCommand myCommand = new SqlCommand(query, myConnection); 124 | myReader = myCommand.ExecuteReader(); 125 | helper = new SqlDataHelper(myReader); 126 | var result = helper.Fetch(20); 127 | helper.GetReaderProperty("Fetched"); 128 | Console.ReadLine(); 129 | 130 | } 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /src.nocompile/rsqlserver.net.Test/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /src.nocompile/rsqlserver.net.Test/rsqlserver.net.Test.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {D5C16450-5892-44E3-85C9-B79F230EC5E7} 8 | Library 9 | Properties 10 | rsqlserver.net.Test 11 | rsqlserver.net.Test 12 | v4.5 13 | 512 14 | true 15 | 16 | 17 | AnyCPU 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | AnyCPU 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | bin\Debug[+TEST]\ 37 | 4 38 | false 39 | 40 | 41 | bin\Release[+TEST]\ 42 | 4 43 | false 44 | 45 | 46 | 47 | ..\packages\xunit.1.9.2\lib\net20\xunit.dll 48 | 49 | 50 | ..\packages\log4net.2.0.8\lib\net45-full\log4net.dll 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | {402EF9FC-7A93-4A67-B605-94C88353EC05} 66 | rsqlserver.net 67 | 68 | 69 | 70 | 75 | 76 | $(SolutionDir)runner\rsqlserver.Test.runner.csproj 77 | 78 | 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /src.nocompile/rsqlserver.net.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "rsqlserver.net", "rsqlserver.net\rsqlserver.net.csproj", "{402EF9FC-7A93-4A67-B605-94C88353EC05}" 5 | EndProject 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "rsqlserver.net.Test", "rsqlserver.net.Test\rsqlserver.net.Test.csproj", "{D5C16450-5892-44E3-85C9-B79F230EC5E7}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{36E138C8-1066-4D96-B91F-761136D5E978}" 9 | ProjectSection(SolutionItems) = preProject 10 | .nuget\packages.config = .nuget\packages.config 11 | EndProjectSection 12 | EndProject 13 | Global 14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 15 | Debug[+TEST]|Any CPU = Debug[+TEST]|Any CPU 16 | Debug|Any CPU = Debug|Any CPU 17 | Release[+TEST]|Any CPU = Release[+TEST]|Any CPU 18 | Release|Any CPU = Release|Any CPU 19 | EndGlobalSection 20 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 21 | {402EF9FC-7A93-4A67-B605-94C88353EC05}.Debug[+TEST]|Any CPU.ActiveCfg = Debug[+TEST]|Any CPU 22 | {402EF9FC-7A93-4A67-B605-94C88353EC05}.Debug[+TEST]|Any CPU.Build.0 = Debug[+TEST]|Any CPU 23 | {402EF9FC-7A93-4A67-B605-94C88353EC05}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 24 | {402EF9FC-7A93-4A67-B605-94C88353EC05}.Debug|Any CPU.Build.0 = Debug|Any CPU 25 | {402EF9FC-7A93-4A67-B605-94C88353EC05}.Release[+TEST]|Any CPU.ActiveCfg = Release[+TEST]|Any CPU 26 | {402EF9FC-7A93-4A67-B605-94C88353EC05}.Release[+TEST]|Any CPU.Build.0 = Release[+TEST]|Any CPU 27 | {402EF9FC-7A93-4A67-B605-94C88353EC05}.Release|Any CPU.ActiveCfg = Release|Any CPU 28 | {402EF9FC-7A93-4A67-B605-94C88353EC05}.Release|Any CPU.Build.0 = Release|Any CPU 29 | {D5C16450-5892-44E3-85C9-B79F230EC5E7}.Debug[+TEST]|Any CPU.ActiveCfg = Debug[+TEST]|Any CPU 30 | {D5C16450-5892-44E3-85C9-B79F230EC5E7}.Debug[+TEST]|Any CPU.Build.0 = Debug[+TEST]|Any CPU 31 | {D5C16450-5892-44E3-85C9-B79F230EC5E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 32 | {D5C16450-5892-44E3-85C9-B79F230EC5E7}.Debug|Any CPU.Build.0 = Debug|Any CPU 33 | {D5C16450-5892-44E3-85C9-B79F230EC5E7}.Release[+TEST]|Any CPU.ActiveCfg = Release[+TEST]|Any CPU 34 | {D5C16450-5892-44E3-85C9-B79F230EC5E7}.Release[+TEST]|Any CPU.Build.0 = Release[+TEST]|Any CPU 35 | {D5C16450-5892-44E3-85C9-B79F230EC5E7}.Release|Any CPU.ActiveCfg = Release|Any CPU 36 | {D5C16450-5892-44E3-85C9-B79F230EC5E7}.Release|Any CPU.Build.0 = Release|Any CPU 37 | EndGlobalSection 38 | GlobalSection(NestedProjects) = preSolution 39 | EndGlobalSection 40 | GlobalSection(SolutionProperties) = preSolution 41 | HideSolutionNode = FALSE 42 | EndGlobalSection 43 | EndGlobal 44 | -------------------------------------------------------------------------------- /src.nocompile/rsqlserver.net.userprefs: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src.nocompile/rsqlserver.net/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("rsqlserver.net")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("rsqlserver.net")] 13 | [assembly: AssemblyCopyright("Copyright © 2013")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("b5f210bb-de03-4c15-b6f8-d290bc894b08")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src.nocompile/rsqlserver.net/log4net.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /src.nocompile/rsqlserver.net/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src.nocompile/rsqlserver.net/rsqlserver.net.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {402EF9FC-7A93-4A67-B605-94C88353EC05} 8 | Library 9 | Properties 10 | rsqlserver.net 11 | rsqlserver.net 12 | v4.5 13 | 512 14 | true 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | pdbonly 27 | true 28 | bin\Release\ 29 | TRACE 30 | prompt 31 | 4 32 | 33 | 34 | bin\Debug[+TEST]\ 35 | 4 36 | false 37 | 38 | 39 | bin\Release[+TEST]\ 40 | 4 41 | false 42 | 43 | 44 | 45 | ..\packages\log4net.2.0.8\lib\net40-full\log4net.dll 46 | 47 | 48 | ..\packages\R.NET.1.5.5\lib\net40\RDotNet.dll 49 | 50 | 51 | ..\packages\R.NET.1.5.5\lib\net40\RDotNet.NativeLibrary.dll 52 | 53 | 54 | ..\packages\LumenWorksCsvReader.3.9.1\lib\net20\LumenWorks.Framework.IO.dll 55 | True 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | PreserveNewest 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 86 | 87 | -------------------------------------------------------------------------------- /src.nocompile/rsqlserver.net/src/SqlDataHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Data.SqlClient; 7 | using System.Data; 8 | using System.Collections; 9 | using System.Reflection; 10 | namespace rsqlserver.net 11 | { 12 | 13 | public static class SqlClientExtensions 14 | { 15 | #if __MonoCS__ 16 | private static Dictionary _connIds = new Dictionary(); 17 | #endif 18 | 19 | public static string GetClientConnectionId(this SqlConnection conn) 20 | { 21 | if (conn == null) 22 | { 23 | return Guid.Empty.ToString(); 24 | } 25 | 26 | #if __MonoCS__ 27 | if(!_connIds.ContainsKey(conn.GetHashCode())) { 28 | _connIds.Add(conn.GetHashCode(), Guid.NewGuid().ToString()); 29 | } 30 | 31 | return _connIds[conn.GetHashCode()]; 32 | #else 33 | return conn.ClientConnectionId.ToString(); 34 | #endif 35 | } 36 | } 37 | public class SqlDataHelper 38 | { 39 | #region map types 40 | private Dictionary NetToRType 41 | { 42 | get 43 | { 44 | var typeMap = new Dictionary(); 45 | typeMap[typeof(Single)] = typeof(Double); 46 | return typeMap; 47 | } 48 | } 49 | #endregion 50 | # region fields 51 | private int _nrows=0; 52 | private string[] _cnames; 53 | private string[] _cdbtypes; 54 | private Type[] _ctypes; 55 | private SqlDataReader _reader; 56 | Dictionary _resultSet; 57 | int _capacity = -1; 58 | 59 | #region 60 | public SqlDataHelper() 61 | { 62 | } 63 | 64 | public SqlDataHelper (SqlDataReader reader){ 65 | _reader=reader; 66 | if (_cnames == null) 67 | { 68 | _cnames = new string[_reader.FieldCount]; 69 | _cdbtypes = new string[_reader.FieldCount]; 70 | _ctypes = new Type[_reader.FieldCount]; 71 | for (int i = 0; i < _reader.FieldCount; i++) 72 | { 73 | _cdbtypes[i] = _reader.GetDataTypeName(i); 74 | _ctypes[i] = _reader.GetFieldType(i); 75 | _cnames[i] = _reader.GetName(i); 76 | } 77 | } 78 | } 79 | #endregion 80 | #endregion 81 | #region props 82 | public int Fetched 83 | { 84 | get { return _nrows; } 85 | } 86 | public string[] Cnames 87 | { 88 | get { return _cnames; } 89 | } 90 | public string[] CDbtypes 91 | { 92 | get { return _cdbtypes; } 93 | } 94 | 95 | public Dictionary ResultSet 96 | { 97 | get { return _resultSet; } 98 | } 99 | public object TimeOut { 100 | get 101 | { 102 | PropertyInfo prop = _reader.GetType().GetProperty("Command", 103 | BindingFlags.NonPublic | BindingFlags.Instance); 104 | 105 | SqlCommand cmd = (SqlCommand)prop.GetValue(_reader); 106 | return cmd.CommandTimeout; 107 | } 108 | } 109 | #endregion 110 | #region global methods 111 | public Object GetItem(SqlDataReader _reader, int i) 112 | { 113 | object value = _reader.GetValue(i); 114 | var fieldType = _reader.GetFieldType(i); 115 | //if (res != null && res.GetType() == typeof(DateTime)) 116 | // return ((DateTime)res).ToString("yyyy-MM-dd HH:mm:ss"); 117 | if (value == DBNull.Value) 118 | { 119 | if (fieldType== typeof(String)) 120 | return string.Empty; 121 | else 122 | return Single.NaN; 123 | } 124 | else 125 | { 126 | if (fieldType == typeof(long)) 127 | return Convert.ToInt32(value); 128 | } 129 | return value; 130 | 131 | } 132 | public Object GetConnectionProperty(SqlConnection _conn, string prop) 133 | { 134 | if (_conn.State == ConnectionState.Closed & 135 | prop == "ServerVersion") 136 | return string.Empty; 137 | 138 | if (prop == "ClientConnectionId") 139 | { 140 | return _conn.GetClientConnectionId(); 141 | } 142 | 143 | if (prop == "State") 144 | { 145 | return _conn.State.ToString(); 146 | } 147 | return _conn.GetType().GetProperty(prop).GetValue(_conn); 148 | } 149 | 150 | public Object GetReaderProperty(string prop) 151 | { 152 | object val = null; 153 | if (String.Compare(prop ,"Fetched")==0) 154 | val = _nrows; 155 | else if(String.Compare(prop ,"Item")!=0){ 156 | val = _reader.GetType().GetProperty(prop).GetValue(_reader); 157 | } 158 | return val; 159 | } 160 | public int Fetch(int capacity) 161 | { 162 | int cnt = 0; 163 | if (_reader == null) return -1; 164 | setCapacity(capacity); 165 | while (_reader.Read()) 166 | { 167 | // fetch rows and store data by column 168 | for (int i = 0; i < _reader.FieldCount; i++) 169 | { 170 | var value = GetItem(_reader, i); 171 | _resultSet[_cnames[i]].SetValue(value, cnt); 172 | } 173 | 174 | cnt += 1; 175 | _nrows += 1; 176 | if (cnt >= capacity) return cnt; 177 | 178 | } 179 | // trim array 180 | if (cnt < capacity) 181 | for (int i = 0; i < _reader.FieldCount; i++) 182 | _resultSet[_cnames[i]] = TrimArray(_resultSet[_cnames[i]], cnt, i); 183 | // set nrows 184 | return cnt; 185 | } 186 | #endregion 187 | #region tools 188 | private void setCapacity(int capacity){ 189 | _capacity = capacity; 190 | _resultSet = new Dictionary(); 191 | for (int i = 0; i < _reader.FieldCount; i++) 192 | { 193 | _ctypes[i] = NetToRType.Keys.Contains(_ctypes[i]) ? NetToRType[_ctypes[i]] : _ctypes[i]; 194 | _resultSet[_cnames[i]] = Array.CreateInstance(_ctypes[i], capacity); 195 | } 196 | 197 | } 198 | private Array TrimArray(Array source, int length,int curr) 199 | { 200 | Array destfoo = Array.CreateInstance(_ctypes[curr],length); 201 | Array.Copy(source, 0, destfoo, 0, length); 202 | return destfoo; 203 | } 204 | #endregion 205 | 206 | } 207 | } 208 | -------------------------------------------------------------------------------- /src.nocompile/rsqlserver.net/src/misc.cs: -------------------------------------------------------------------------------- 1 | using log4net; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Configuration; 5 | using System.Data; 6 | using System.Data.SqlClient; 7 | using System.IO; 8 | using System.Linq; 9 | using System.Text; 10 | using System.Threading.Tasks; 11 | using System.Transactions; 12 | using LumenWorks.Framework.IO.Csv; 13 | 14 | namespace rsqlserver.net 15 | { 16 | public class misc 17 | { 18 | private static readonly ILog _Logger = LogManager.GetLogger(typeof(misc)); 19 | 20 | static misc() { 21 | InitLog(); 22 | } 23 | 24 | private static void InitLog() 25 | { 26 | string asmFile = System.Reflection.Assembly.GetExecutingAssembly().Location; 27 | Configuration dllConfig = ConfigurationManager.OpenExeConfiguration(asmFile); 28 | string fileName = Path.GetDirectoryName(asmFile) + "/log4net.config"; 29 | if (!dllConfig.HasFile && File.Exists(fileName)) 30 | { 31 | System.IO.FileInfo configFileInfo = new System.IO.FileInfo(fileName); 32 | log4net.Config.XmlConfigurator.Configure(configFileInfo); 33 | } 34 | _Logger.Info("I am rsqlserver logger"); 35 | } 36 | 37 | public static Single[] GetSingleArray() 38 | { 39 | Single[] r = new Single[2] { Single.MaxValue, Single.MinValue }; 40 | return r; 41 | } 42 | 43 | public static double[] FromSingle2DoubleArray() 44 | { 45 | var r = GetSingleArray(); 46 | double[] dar = new double[r.Length]; 47 | for (int i = 0; i < r.Length; i++) 48 | dar[i] = (double)r[i]; 49 | return dar; 50 | } 51 | 52 | public static DataTable fileToDataTable(string CSVFilePathName) 53 | { 54 | DataTable dt = new DataTable(); 55 | try 56 | { 57 | string[] Lines = File.ReadAllLines(CSVFilePathName); 58 | string[] Fields; 59 | Fields = Lines[0].Split(new char[] { ',' }); 60 | int Cols = Fields.GetLength(0); 61 | //1st row must be column names; force lower case to ensure matching later on. 62 | for (int i = 0; i < Cols; i++) 63 | dt.Columns.Add(Fields[i].ToLower(), typeof(string)); 64 | DataRow Row; 65 | for (int i = 1; i < Lines.GetLength(0); i++) 66 | { 67 | Fields = Lines[i].Split(new char[] { ',' }); 68 | Row = dt.NewRow(); 69 | for (int f = 0; f < Cols; f++) 70 | Row[f] = Fields[f]; 71 | dt.Rows.Add(Row); 72 | } 73 | } 74 | catch (FileNotFoundException exception) 75 | { 76 | _Logger.DebugFormat("Error {0}", exception.Message); 77 | dt = null; 78 | } 79 | catch (Exception ex) 80 | { 81 | _Logger.DebugFormat("Error {0}", ex.Message); 82 | dt = null; 83 | } 84 | return dt; 85 | 86 | } 87 | 88 | private static Type DbToClrType(string sqlType) 89 | { 90 | switch (sqlType) 91 | { 92 | case "bigint": 93 | return typeof(Int64); 94 | 95 | case "binary": 96 | case "image": 97 | case "timestamp": 98 | case "varbinary": 99 | return typeof(Byte[]); 100 | 101 | case "bit": 102 | return typeof(Boolean); 103 | 104 | case "char": 105 | case "nchar": 106 | case "ntext": 107 | case "nvarchar": 108 | case "text": 109 | case "varchar": 110 | case "xml": 111 | return typeof(String); 112 | 113 | case "datetime": 114 | case "smalldatetime": 115 | case "date": 116 | case "time": 117 | case "datetime2": 118 | return typeof(DateTime); 119 | 120 | case "decimal": 121 | case "money": 122 | case "smallmoney": 123 | return typeof(Decimal); 124 | 125 | case "float": 126 | return typeof(Double); 127 | 128 | case "int": 129 | return typeof(Int32); 130 | 131 | case "real": 132 | return typeof(Single); 133 | 134 | case "uniqueidentifier": 135 | return typeof(Guid); 136 | 137 | case "smallint": 138 | return typeof(Int16); 139 | 140 | case "tinyint": 141 | return typeof(Byte); 142 | 143 | case "variant": 144 | case "udt": 145 | return typeof(object); 146 | 147 | case "structured": 148 | return typeof(DataTable); 149 | 150 | case "datetimeoffset": 151 | return typeof(DateTimeOffset); 152 | 153 | default: 154 | throw new ArgumentOutOfRangeException(nameof(sqlType)); 155 | } 156 | } 157 | 158 | public static void SqlBulkCopy(String connectionString, string sourcePath, string destTableName, Boolean hasHeaders = true, String delimiter = ",") 159 | { 160 | using (var reader = new CsvReader(new StreamReader(sourcePath), hasHeaders, System.Convert.ToChar(delimiter))) 161 | { 162 | 163 | using (SqlConnection destConnection = 164 | new SqlConnection(connectionString)) 165 | { 166 | destConnection.Open(); 167 | 168 | SqlCommand dbTypes = new SqlCommand( 169 | "SELECT c.Name AS COLUMN_NAME, t.Name AS DATA_TYPE " + 170 | "FROM sys.columns c " + 171 | "INNER JOIN sys.objects o ON o.object_id = c.object_id " + 172 | "LEFT JOIN sys.types t on t.user_type_id = c.user_type_id " + 173 | "WHERE o.type = 'U' AND o.object_id = OBJECT_ID(@destTable);", destConnection); 174 | 175 | dbTypes.Parameters.AddWithValue("@destTable", destTableName); 176 | SqlDataReader tabledata = dbTypes.ExecuteReader(); 177 | 178 | while (tabledata.Read()) 179 | { 180 | reader.Columns.Add(new Column { Name = tabledata["COLUMN_NAME"].ToString(), Type = DbToClrType(tabledata["DATA_TYPE"].ToString()) }); 181 | } 182 | tabledata.Close(); 183 | 184 | try 185 | { 186 | using (SqlBulkCopy bulkCopy = 187 | new SqlBulkCopy(destConnection)) 188 | { 189 | bulkCopy.DestinationTableName = destTableName; 190 | _Logger.InfoFormat("copying table {0} ....", destTableName); 191 | bulkCopy.BulkCopyTimeout = 60; 192 | bulkCopy.WriteToServer(reader); 193 | _Logger.InfoFormat("Success loading table {0} having {1} rows in database", destTableName, reader.CurrentRecordIndex); 194 | _Logger.Info("Success copy"); 195 | } 196 | } 197 | catch (Exception ex) 198 | { 199 | _Logger.DebugFormat("Failure to copy : {0}", ex.Message); 200 | throw ex; 201 | } 202 | } 203 | } 204 | } 205 | 206 | private static void writerHelper(StreamWriter writer, SqlDataReader reader, String delimiter, bool headerrow) 207 | { 208 | String row = ""; 209 | for (int i = 0; i < reader.FieldCount; i++) 210 | { 211 | if (headerrow) 212 | { 213 | row += delimiter + "\"" + reader.GetName(i).ToString() + "\""; 214 | } 215 | else 216 | { 217 | row += delimiter + "\"" + reader[i].ToString() + "\""; 218 | } 219 | } 220 | writer.WriteLine(row.Substring(1)); 221 | } 222 | 223 | public static void SqlBulkWrite(String connectionString, string destFilePath, string sourceTableName, Boolean withHeaders = true, String delimiter = ",") 224 | { 225 | using (SqlConnection destConnection = new SqlConnection(connectionString)) 226 | using (SqlCommand cmd = destConnection.CreateCommand()) 227 | { 228 | destConnection.Open(); 229 | 230 | String sql = @"SELECT * FROM " + sourceTableName; 231 | cmd.CommandText = sql; 232 | 233 | using (SqlDataReader reader = cmd.ExecuteReader()) 234 | using (StreamWriter writer = new StreamWriter(destFilePath)) 235 | { 236 | //TODO rewrite block below / writerHelper more effectively 237 | if (withHeaders) 238 | { 239 | writerHelper(writer, reader, delimiter, true); 240 | } 241 | 242 | while (reader.Read()) 243 | { 244 | writerHelper(writer, reader, delimiter, false); 245 | } 246 | } 247 | } 248 | } 249 | } 250 | } 251 | 252 | -------------------------------------------------------------------------------- /src.nocompile/runner/rsqlserver.Test.runner.csproj: -------------------------------------------------------------------------------- 1 | 4 | 5 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /tests/resources/spSummaryProduct.sql: -------------------------------------------------------------------------------- 1 | IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[spSummaryProduct]') AND type in (N'P', N'PC')) 2 | DROP PROCEDURE [dbo].[spSummaryProduct] 3 | GO 4 | CREATE PROCEDURE [dbo].[spSummaryProduct] 5 | @statistic char(6) 6 | ,@value float OUTPUT 7 | AS 8 | BEGIN 9 | IF NULLIF(@statistic, '') IS NULL 10 | BEGIN 11 | IF @statistic = 'sum' 12 | SELECT @value = (SELECT sum(value) FROM T_PRODUCT) 13 | ELSE IF @statistic = 'mean' 14 | SELECT @value = (SELECT avg(value) FROM T_PRODUCT) 15 | ELSE IF @statistic = 'median' 16 | SELECT @value = (Select Top 1 value 17 | From ( 18 | Select Top 50 Percent value 19 | From T_PRODUCT 20 | Where value Is NOT NULL 21 | Order By value 22 | ) As A 23 | Order By value DESC) 24 | END 25 | RETURN 26 | 27 | END 28 | 29 | 30 | -------------------------------------------------------------------------------- /tests/test-all.R: -------------------------------------------------------------------------------- 1 | library("testthat") 2 | test_check("rsqlserver") -------------------------------------------------------------------------------- /tests/testthat/helper.R: -------------------------------------------------------------------------------- 1 | # Edit as required to run tests on an accessible SQL Server 2 | # See docker.sh for instructions to setup a SQL Server Docker container 3 | server <- "mydockermsdb" 4 | dbname <- "rsqlserverdb" 5 | user <- "SA" 6 | password <- "Password12!" 7 | 8 | if (identical(Sys.getenv("TRAVIS"), "true")) { 9 | server <- "mssqldb" 10 | dbname <- "rsqlserverdb" 11 | user <- "sa" 12 | password <- "Password12!" 13 | } else if (identical(Sys.getenv("APPVEYOR"), "True")) { 14 | server <- "(local)\\SQL2014" 15 | dbname <- "rsqlserverdb" 16 | user <- "sa" 17 | password <- "Password12!" 18 | } 19 | 20 | url <- sprintf("Server=%s;Database=%s;User Id=%s;Password=%s;", 21 | server, dbname, user, password) 22 | 23 | get_con <- function(){ 24 | dbConnect("SqlServer", url = url) 25 | } 26 | -------------------------------------------------------------------------------- /tests/testthat/test-DBI-compliance.R: -------------------------------------------------------------------------------- 1 | context("DBI Compliance") 2 | 3 | test_that('dbListTable : Get list of all tables',{ 4 | on.exit(dbDisconnect(conn)) 5 | conn <- get_con() 6 | res <- dbListTables(conn) 7 | expect_gte(length(res),0) 8 | }) 9 | 10 | test_that("dbGetInfo : Get connection Info",{ 11 | on.exit(dbDisconnect(conn)) 12 | conn <- get_con() 13 | dbinfo <- dbGetInfo(conn) 14 | desc <- paste0("Sql server ", dbinfo$ServerVersion, " [", dbinfo$WorkstationId, "@", 15 | dbinfo$DataSource, ":", dbinfo$Database, "/", dbinfo$State, "]") 16 | expect_named(dbinfo) 17 | }) 18 | 19 | test_that("dbListFields: Get connection Info",{ 20 | on.exit(dbDisconnect(conn)) 21 | conn <- get_con() 22 | dbWriteTable(conn, name = "T_MTCARS", value = mtcars, 23 | row.names = FALSE, overwrite = TRUE) 24 | expect_equal(dbListFields(conn, "T_MTCARS"), names(mtcars)) 25 | dbRemoveTable(conn, "T_MTCARS") 26 | }) 27 | 28 | #TODO 29 | test_that("dbGetRowCount: Get row count",{ 30 | skip("dbGetRowCount not yet implemented") 31 | on.exit(dbDisconnect(conn)) 32 | conn <- get_con() 33 | query <- "SELECT * FROM T_DATE" 34 | rs <- dbSendQuery(conn, query) 35 | df <- fetch(rs, -1) 36 | expect_equal(dbGetRowCount(rs), nrow(df)) 37 | dbClearResult(rs) 38 | }) 39 | 40 | #TODO 41 | test_that("dbHasCompleted: Check that query is completed",{ 42 | skip("dbHasCompleted not yet implemented") 43 | on.exit(dbDisconnect(conn)) 44 | conn <- get_con() 45 | query <- "SELECT * FROM T_MTCARS" 46 | res <- dbSendQuery(conn, query) 47 | df1 <- fetch(res, as.integer(floor(nrow(mtcars)/2))) 48 | expect_false(dbHasCompleted(res)) 49 | df2 <- fetch(res, -1) 50 | expect_false(dbHasCompleted(res)) 51 | expect_equivalent(rbind(df1,df2),mtcars) 52 | dbClearResult(res) 53 | dbRemoveTable(conn, "T_MTCARS") 54 | }) 55 | -------------------------------------------------------------------------------- /tests/testthat/test-connections.R: -------------------------------------------------------------------------------- 1 | context("Test Connections") 2 | 3 | test_isconnected <- function(url){ 4 | on.exit(dbDisconnect(con)) 5 | con <- dbConnect("SqlServer", url = url) 6 | expect_equal(dbGetInfo(con, "State")$State, "Open") 7 | } 8 | 9 | test_that("dbConnect: Standard Security",{ 10 | url <- sprintf("Server=%s;Database=%s;User Id=%s;Password=%s;", 11 | server, dbname, user, password) 12 | test_isconnected(url) 13 | }) 14 | 15 | test_that("dbConnect: Trusted conection",{ 16 | skip_on_os(c("mac", "linux", "solaris")) 17 | url <- sprintf("Server=%s;Database=%s;Trusted_connection=True;", 18 | server, dbname) 19 | test_isconnected(url) 20 | }) 21 | 22 | test_that("dbConnect: Connecting using connection parameters",{ 23 | on.exit(dbDisconnect(con)) 24 | con <- dbConnect("SqlServer", host = server, dbname = dbname, user = user, password = password) 25 | expect_equal(dbGetInfo(con, "State")$State, "Open") 26 | }) 27 | 28 | test_that("dbConnect: Trusted connection using with connection parameters",{ 29 | skip_on_os(c("mac", "linux", "solaris")) 30 | on.exit(dbDisconnect(con)) 31 | con <- dbConnect("SqlServer", host = server, dbname = dbname, trusted = TRUE) 32 | expect_equal(dbGetInfo(con, "State")$State, "Open") 33 | }) 34 | 35 | test_that("dbConnect: Choose parameter if url is NULL",{ 36 | skip_on_os(c("mac", "linux", "solaris")) 37 | on.exit(dbDisconnect(con)) 38 | con <- dbConnect("SqlServer", host = server, dbname = dbname, trusted = TRUE, url = NULL) 39 | expect_equal(dbGetInfo(con, "State")$State, "Open") 40 | }) 41 | -------------------------------------------------------------------------------- /tests/testthat/test-extradbi.R: -------------------------------------------------------------------------------- 1 | context("Test Extra Functions") 2 | 3 | test_that("dbGetScalar: Returns null for NO_OBJECT",{ 4 | on.exit(dbDisconnect(conn)) 5 | conn <- get_con() 6 | req <- "SELECT OBJECT_ID('NO_OBJECT','S') AS 'Object ID';" 7 | res <- dbGetScalar(conn,req) 8 | expect_null(res) 9 | }) 10 | 11 | test_that("dbGetScalar: Returns a scalar",{ 12 | on.exit(dbDisconnect(conn)) 13 | conn <- get_con() 14 | req <- "SELECT OBJECT_ID('sys.sysprivs','S') AS 'Object ID';" 15 | res <- dbGetScalar(conn,req) 16 | expect_length(res, 1) 17 | }) 18 | 19 | test_that("dbConnect: Set a timeout",{ 20 | skip_on_os(c("mac", "linux", "solaris")) 21 | on.exit(dbDisconnect(conn)) 22 | conn <- get_con() 23 | query <- "SELECT name FROM sys.tables" 24 | rs <- dbSendQuery(conn, query, timeout = 90) 25 | df <- fetch(rs, -1) 26 | expect_equal(as.integer(dbGetInfo(rs, "TimeOut")), 90) 27 | dbClearResult(rs) 28 | }) 29 | -------------------------------------------------------------------------------- /tests/testthat/test-readdb.R: -------------------------------------------------------------------------------- 1 | context("Reading & Writing tables") 2 | 3 | test_that("dbWriteTable/dbRemoveTable: Create a table and remove it using handy functions", { 4 | on.exit(dbDisconnect(conn)) 5 | conn <- get_con() 6 | if(dbExistsTable(conn, "T_MTCARS")){ 7 | dbRemoveTable(conn, "T_MTCARS") 8 | } 9 | dbWriteTable(conn, name="T_MTCARS", mtcars) 10 | expect_true(dbExistsTable(conn, "T_MTCARS")) 11 | expect_true(dbRemoveTable(conn, "T_MTCARS")) 12 | expect_false(dbExistsTable(conn, "T_MTCARS")) 13 | expect_false(dbRemoveTable(conn, "T_MTCARS")) 14 | }) 15 | 16 | test_that("dbReadTable: Return a significant message if a table is not found", { 17 | on.exit(dbDisconnect(conn)) 18 | conn <- get_con() 19 | expect_error(dbReadTable(conn, "TABLE_THAT_DOESNT_EXIST"), "Invalid object name") 20 | }) 21 | 22 | test_that("dbReadTable: Reopen a connection if the connection is already closed", { 23 | skip("Not yet implemented") 24 | on.exit(dbDisconnect(conn)) 25 | conn <- get_con() 26 | dbWriteTable(conn, name = "T_MTCARS", mtcars) 27 | dbDisconnect(conn) 28 | res <- dbReadTable(conn, "T_MTCARS") 29 | dbRemoveTable(conn, "T_MTCARS") 30 | expect_is(res, class = "data.frame") 31 | }) 32 | 33 | test_that("dbGetScalar: Querying a temporary table", { 34 | on.exit(dbDisconnect(con)) 35 | req <- "CREATE TABLE #TempTable(Test int) 36 | INSERT INTO #TempTable 37 | SELECT 2 38 | SELECT * FROM #TempTable 39 | DROP TABLE #TempTable" 40 | con <- get_con() 41 | res <- dbGetScalar(con, req) 42 | expect_equal(res, 2) 43 | }) 44 | 45 | test_that("dbCreateTable: Create a table having SQL keywords as columns", { 46 | on.exit(dbDisconnect(conn)) 47 | conn <- get_con() 48 | cnames = c("key", "create", "table") 49 | cnames = make.db.names(conn, cnames, allow.keywords = FALSE) 50 | if(dbExistsTable(conn, "T_KEYWORDS")){ 51 | dbRemoveTable(conn, "T_KEYWORDS") 52 | } 53 | dbCreateTable(conn, "T_KEYWORDS", cnames, 54 | ctypes = rep("varchar(3)", 3)) 55 | expect_true(dbExistsTable(conn, "T_KEYWORDS")) 56 | dbRemoveTable(conn, "T_KEYWORDS") 57 | }) 58 | 59 | test_that("Fetch: Get n rows from a table", { 60 | on.exit(dbDisconnect(conn)) 61 | conn <- get_con() 62 | dbWriteTable(conn, name = "T_MTCARS", mtcars, overwrite = TRUE) 63 | 64 | res <- dbSendQuery(conn, "SELECT mpg, cyl, wt FROM T_MTCARS") 65 | res.dat <- fetch(res, n = nrow(mtcars)) 66 | invisible(dbClearResult(res)) 67 | expect_is(res.dat, "data.frame") 68 | expect_equal(nrow(res.dat), nrow(mtcars)) 69 | expect_is(res.dat$mpg, "numeric") 70 | expect_is(res.dat$cyl, "numeric") 71 | expect_is(res.dat$wt, "numeric") 72 | 73 | dbRemoveTable(conn, "T_MTCARS") 74 | }) 75 | 76 | test_that("dbGetQuery: Get some data from a table", { 77 | on.exit(dbDisconnect(conn)) 78 | conn <- get_con() 79 | dbWriteTable(conn, name = "T_MTCARS", mtcars, overwrite = TRUE) 80 | 81 | res <- dbGetQuery(conn, "SELECT mpg, cyl, wt FROM T_MTCARS") 82 | expect_is(res, "data.frame") 83 | expect_equal(nrow(mtcars), nrow(res)) 84 | expect_is(res$mpg, "numeric") 85 | expect_is(res$cyl, "numeric") 86 | expect_is(res$wt, "numeric") 87 | 88 | dbRemoveTable(conn, "T_MTCARS") 89 | }) 90 | 91 | build_large_df <- function(size){ 92 | set.seed(1) 93 | dat <- data.frame(value = sample(1:100, size, replace=TRUE), 94 | key = sample(letters, size, replace=TRUE), 95 | stringsAsFactors = FALSE) 96 | } 97 | 98 | test_that("dbWriteTable: Use INSERT INTO on a large data.frame",{ 99 | on.exit(dbDisconnect(conn)) 100 | N <- 999 101 | dat <- build_large_df(size = N) 102 | conn <- get_con() 103 | dbWriteTable(conn, name = "T_BIG", value = dat, row.names = FALSE, overwrite = TRUE) 104 | expect_equal(dbExistsTable(conn, "T_BIG"), TRUE) 105 | dbRemoveTable(conn, "T_BIG") 106 | }) 107 | 108 | test_that("dbWriteTable: Use BULK COPY on a large data.frame",{ 109 | on.exit(dbDisconnect(conn)) 110 | N <- 1000 111 | dat <- build_large_df(size = N) 112 | conn <- get_con() 113 | dbWriteTable(conn, name = "T_BIG", value = dat, row.names = FALSE, overwrite = TRUE) 114 | expect_equal(dbExistsTable(conn, "T_BIG"), TRUE) 115 | dbRemoveTable(conn, "T_BIG") 116 | }) 117 | 118 | test_that("dbWriteTable/dbBulkWrite : Import a large data frame and unload to text",{ 119 | on.exit(dbDisconnect(conn)) 120 | set.seed(1) 121 | N=1000 122 | table.name = paste('T_BIG',sprintf("%.9g", N) ,sep='_') 123 | dat <- data.frame(value=sample(1:100,N,replace=TRUE), 124 | key =sample(letters,N,replace=TRUE), 125 | stringsAsFactors=FALSE) 126 | conn <- get_con() 127 | dbWriteTable(conn,name=table.name,dat,row.names=FALSE,overwrite=TRUE) 128 | expect_true(dbExistsTable(conn,table.name)) 129 | dbBulkWrite(conn,name=table.name,value="t_big.csv",headers = T,delim = "\t") 130 | res <- read.csv("t_big.csv") 131 | expect_equal(nrow(res),N) 132 | file.remove("t_big.csv") 133 | }) 134 | 135 | test_that("dbBulkWrite : Read bit, bigint, decimal/numeric columns from SQL Server",{ 136 | on.exit(dbDisconnect(conn)) 137 | set.seed(1) 138 | table.name <- "T_EXOTIC" 139 | dat <- data.frame( 140 | # Standard columns 141 | col_varchar = sample(state.name, 100, replace=TRUE), 142 | col_int = sample(1000,100,replace=T), 143 | # Exotic columns 144 | col_bigint = sample(2^50,100,replace=T), 145 | col_bit = sample(c(NA,0,1),100,replace=T), 146 | col_numeric = sample(10^7,100,replace=T)/10.0^6, 147 | col_decimal = sample(10^8,100,replace=T)/10.0^6 148 | ) 149 | conn <- get_con() 150 | field.types <- c("varchar(100)","int","bigint","bit","numeric(10,6)","decimal(10,6)") 151 | names(field.types) <- names(dat) 152 | dbWriteTable(conn,name=table.name,dat,field.types=field.types,row.names=FALSE,overwrite=TRUE) 153 | expect_true(dbExistsTable(conn,table.name)) 154 | dbBulkWrite(conn,name=table.name,value="t_exotic.csv") 155 | res <- read.csv("t_exotic.csv") 156 | expect_equal(nrow(res),nrow(dat)) 157 | file.remove("t_exotic.csv") 158 | }) 159 | 160 | #TODO 161 | # Currently not writing text missing values correctly. 162 | test_that("Missing values: Write missing values",{ 163 | skip("Not yet implemented") 164 | on.exit(dbDisconnect(conn)) 165 | dat <- data.frame(txt = c("a", NA, "b", NA), 166 | value = c(1L, NA, NA, 2L), 167 | stringsAsFactors = FALSE) 168 | conn <- get_con() 169 | dbWriteTable(conn, name = "T_TABLE_MISSING", value = dat, overwrite = TRUE, row.names=FALSE) 170 | query <- "SELECT SUM(count_null) FROM ( 171 | SELECT 172 | CASE WHEN [txt] IS NULL THEN 1 ELSE 0 END + 173 | CASE WHEN [value] IS NULL THEN 1 ELSE 0 END AS count_null 174 | FROM T_TABLE_MISSING 175 | ) A" 176 | expect_equal(dbGetScalar(conn, query), 4) 177 | dbRemoveTable(conn, "T_TABLE_MISSING") 178 | }) 179 | 180 | #TODO 181 | # Failing with Message: not a widening conversion 182 | test_that("Missing values: Read missing values using Fetch",{ 183 | skip("Not yet implemented") 184 | on.exit(dbDisconnect(conn)) 185 | dat <- data.frame(txt = c("a", NA, "b", NA), 186 | value = c(1L, NA, NA, 2L), 187 | stringsAsFactors = FALSE) 188 | conn <- get_con() 189 | dbWriteTable(conn, name = "T_TABLE_MISSING", value = dat, overwrite = TRUE, row.names=FALSE) 190 | res <- dbSendQuery(conn, "SELECT * FROM T_TABLE_MISSING") 191 | df <- fetch(res, n = -1) 192 | invisible(dbClearResult(res)) 193 | expect_equivalent(df, dat) 194 | dbRemoveTable(conn, "T_TABLE_MISSING") 195 | }) 196 | 197 | #TODO 198 | test_that("Unusual Data Types: BIGINT",{ 199 | skip("Not yet implemented") 200 | on.exit(dbDisconnect(conn)) 201 | conn <- get_con() 202 | query <- "SELECT * FROM T_BIGINT" 203 | df1 <- dbGetQuery(conn, query) 204 | }) 205 | 206 | #TODO 207 | test_that("Unusual Data Types: BIT",{ 208 | skip("Not yet implemented") 209 | on.exit(dbDisconnect(conn)) 210 | conn <- get_con() 211 | query <- "SELECT * FROM T_BIT" 212 | df1 <- dbGetQuery(conn, query) 213 | }) 214 | -------------------------------------------------------------------------------- /tests/testthat/test-storedprocedure.R: -------------------------------------------------------------------------------- 1 | context("Stored Procedures") 2 | 3 | #TODO 4 | test_that("Create and execute a stored procedure",{ 5 | skip("dbCallProcedure not yet implemented") 6 | on.exit(dbDisconnect(conn)) 7 | ## create proc 8 | lines = readLines('../resources/spSummaryProduct.sql') 9 | reqs <- split(lines,cumsum(lines =="GO")) 10 | stmt.remove <- paste(reqs[[1]],collapse='\n') 11 | stmt.create <- paste(reqs[[2]][-1],collapse='\n') 12 | ## create procedure 13 | conn <- get_con() 14 | dbNonQuery(conn,stmt.remove) 15 | dbNonQuery(conn,stmt.create) 16 | ## create data 17 | dat <- data.frame(value = sample(1:100,50,replace=TRUE)) 18 | dbWriteTable(conn,'T_PRODUCT',dat,overwrite=TRUE) 19 | lapply(c('mean','sum','median'),function(x){ 20 | db.value = dbCallProcedure(conn,"spSummaryProduct",x) 21 | r.value = do.call(x,list(dat$value)) 22 | expect_equal (db.value,r.value) 23 | }) 24 | dbRemoveTable(conn,'T_PRODUCT') 25 | rsqlserver:::dropProc(conn,'spSummaryProduct') 26 | }) -------------------------------------------------------------------------------- /tests/testthat/test-types-conversion.R: -------------------------------------------------------------------------------- 1 | context("Conversion of types and DB naming conventions") 2 | 3 | test_that("db2RType: Mapping fom SQL Server types to R types",{ 4 | expect_equal(rsqlserver:::db2RType("char"), "factor") 5 | expect_equal(rsqlserver:::db2RType("varchar"), "character") 6 | expect_equal(rsqlserver:::db2RType("int"), "integer") 7 | expect_equal(rsqlserver:::db2RType("datetime"), "POSIXct") 8 | expect_equal(rsqlserver:::db2RType("float"), "numeric") 9 | expect_equal(rsqlserver:::db2RType("decimal"), "numeric") 10 | }) 11 | 12 | test_that("make.db.names: Names are valid DB names",{ 13 | drv <- dbDriver("SqlServer") 14 | expect_equal(make.db.names(drv, "a mine"), "a_mine") ## space 15 | ## keywords 16 | expect_equal(make.db.names(drv, "create", allow.keywords = TRUE), "create") 17 | expect_equal(make.db.names(drv, "create", allow.keywords = FALSE), "[create]") 18 | }) 19 | 20 | test_that("R2DbType: Automatic Conversion from R to DB",{ 21 | value <- list(x.int = 1L, 22 | x.num = 1, 23 | x.fact = factor(1), 24 | x.char = "x", 25 | x.list = list(1), 26 | x.date = Sys.Date(), 27 | x.posixct = Sys.time()) 28 | expected <- list(x.int = "int", 29 | x.num = "float", 30 | x.fact = "char(12)", 31 | x.char = "varchar(128)", 32 | x.list = "varbinary(2000)", 33 | x.date = "date", 34 | x.posixct = "datetime2") 35 | effective <- lapply(value, rsqlserver:::R2DbType) 36 | expect_identical(expected, effective) 37 | }) 38 | 39 | test_that("sqlServer.data.frame: Data is well quoted before insert",{ 40 | options(stringsAsFactors = FALSE) 41 | value <- data.frame(a = as.POSIXct("2013-11-07 01:47:33"), 42 | b = "value ' alol", 43 | c = "aa jujs", 44 | d = 1, 45 | e = as.Date("2013-11-07")) 46 | expected = data.frame(a = "'2013-11-07 01:47:33'", 47 | b = "'value '' alol'", 48 | c = "'aa jujs'", 49 | d = 1, 50 | e = "'2013-11-07'") 51 | field.types <- lapply(value, rsqlserver:::R2DbType) 52 | value.db <- rsqlserver:::sqlServer.data.frame(value, field.types) 53 | expect_equal(expected, value.db) 54 | }) 55 | 56 | test_that("dbReadTable: Read rownames in the exact type",{ 57 | on.exit(dbDisconnect(conn)) 58 | conn <- get_con() 59 | dat_int <- data.frame(x = 1:10) 60 | dat_char <- data.frame(x = 1:10) 61 | dat_date <- data.frame(x = 1:10) 62 | rownames(dat_char) <- paste0("row", seq(nrow(dat_char))) 63 | rownames(dat_date) <- seq.POSIXt(from = Sys.time(), 64 | by=1, 65 | length.out = nrow(dat_date)) 66 | invisible(lapply(ls(pattern = "dat_"), 67 | function(x){ 68 | dbWriteTable(conn, name = x, value = get(x), overwrite=TRUE) 69 | res <- dbReadTable(conn, name = x) 70 | dbRemoveTable(conn, name = x) 71 | expect_identical(rownames(get(x)), 72 | rownames(res)) 73 | })) 74 | }) 75 | 76 | test_that("dbWriteTable: Save POSIXct as DATETIME",{ 77 | on.exit(dbDisconnect(conn)) 78 | dat <- data.frame(cdate = seq.POSIXt(from = Sys.time(), 79 | by = 1, 80 | length.out = 100) 81 | ) 82 | conn <- get_con() 83 | dbWriteTable(conn, name = "T_DATE", value = dat, overwrite = TRUE) 84 | res <- dbGetScalar(conn, 85 | "SELECT DATA_TYPE 86 | FROM INFORMATION_SCHEMA.COLUMNS 87 | WHERE TABLE_NAME = 'T_DATE' AND COLUMN_NAME = 'cdate'") 88 | expect_identical(res, "datetime2") 89 | dbRemoveTable(conn, "T_DATE") 90 | }) 91 | 92 | #TODO 93 | test_that("dbReadTable: Read DATETIME as POSIXct",{ 94 | skip("Not yet implemented") 95 | on.exit(dbDisconnect(conn)) 96 | dat <- data.frame(cdate = seq.POSIXt(from = Sys.time(), 97 | by = 1, 98 | length.out = 100) 99 | ) 100 | conn <- get_con() 101 | dbWriteTable(conn, name = "T_DATE", value = dat, overwrite = TRUE) 102 | res <- dbReadTable(conn, "T_DATE") 103 | expect_is(res$cdate, "POSIXct") 104 | dbRemoveTable(conn, "T_DATE") 105 | }) 106 | 107 | #TODO 108 | test_that("dbBulkCopy: Insert POSIXct into DATETIME",{ 109 | skip("Not yet implemented") 110 | on.exit(dbDisconnect(conn)) 111 | N <- 100000 112 | dat <- data.frame(cdate = seq.POSIXt(from = Sys.time(), 113 | by = 1, 114 | length.out = N)) 115 | conn <- get_con() 116 | rsqlserver:::dbCreateTable(conn, "T_BULKCOPY", 117 | "cdate", "datetime2") 118 | dbBulkCopy(conn, value = dat, name = "T_BULKCOPY") 119 | res <- dbGetScalar(conn, 120 | "SELECT DATA_TYPE 121 | FROM INFORMATION_SCHEMA.COLUMNS 122 | WHERE TABLE_NAME = 'T_BULKCOPY' AND COLUMN_NAME = 'cdate'") 123 | expect_identical(res, "datetime2") 124 | dbRemoveTable(conn, "T_BULKCOPY") 125 | }) 126 | 127 | test_that("dbWriteTable: Save Date as DATE (#11)",{ 128 | on.exit(dbDisconnect(conn)) 129 | dat <- data.frame(cdate = seq.Date(from = Sys.Date(), 130 | by = 1, 131 | length.out = 5)) 132 | conn <- get_con() 133 | dbWriteTable(conn, name = "T_DATE", value = dat, overwrite = TRUE) 134 | res <- dbGetScalar(conn, 135 | "SELECT DATA_TYPE 136 | FROM INFORMATION_SCHEMA.COLUMNS 137 | WHERE TABLE_NAME = 'T_DATE' AND COLUMN_NAME = 'cdate'") 138 | expect_identical(res, "date") 139 | dbRemoveTable(conn, "T_DATE") 140 | }) 141 | 142 | #TODO 143 | test_that("dbReadTable: Read DATE as Date (#11)",{ 144 | skip("Not yet implemented") 145 | on.exit(dbDisconnect(conn)) 146 | dat <- data.frame(cdate = seq.Date(from = Sys.Date(), 147 | by = 1, 148 | length.out = 5)) 149 | conn <- get_con() 150 | dbWriteTable(conn, name = "T_DATE", value = dat, overwrite = TRUE) 151 | res <- dbReadTable(conn, "T_DATE") 152 | expect_is(res$cdate, "Date") 153 | dbRemoveTable(conn, "T_DATE") 154 | }) 155 | --------------------------------------------------------------------------------