Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <configuration>
- <database-connections>
- <database-connection name="rok-material">
- <driver>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver>
- <connection-string>jdbc:sqlserver://s.domain.com;database=Material;user=test;password=test;</connection-string>
- </database-connection>
- <database-connection name="rok-dc">
- <driver>net.sourceforge.jtds.jdbc.Driver</driver>
- <!-- http://jtds.sourceforge.net/faq.html#urlFormat -->
- <connection-string>jdbc:jtds:sqlserver://a.domain.com/dcSql;user=test;password=test;</connection-string>
- </database-connection>
- </database-connections>
- </configuration>
- xquery version "3.0";
- module namespace db="http://domain.com/db";
- declare namespace sql="http://exist-db.org/xquery/sql";
- import module namespace functx="http://www.functx.com";
- import module namespace config="http://domain.com/inventory/config" at "config.xqm";
- declare variable $db:config-doc := doc($config:app-root || '/data/configuration.xml');
- declare function db:get-connection($connection-name as xs:string)
- {
- let $connection-node := $db:config-doc/configuration/database-connections/database-connection[@name/string() eq $connection-name]
- return
- if(not($connection-node))
- then ()
- else sql:get-connection($connection-node/driver/text(), $connection-node/connection-string/text())
- };
- declare function db:execute($connection, $query as xs:string, $use-column-names as xs:boolean)
- {
- sql:execute($connection, $query, $use-column-names)
- };
- declare function db:execute-on($connection-name as xs:string, $query as xs:string)
- {
- db:execute(db:get-connection($connection-name), $query, true())
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement