Advertisement
Guest User

Untitled

a guest
Sep 27th, 2013
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XML 1.73 KB | None | 0 0
  1. <configuration>
  2.     <database-connections>
  3.         <database-connection name="rok-material">
  4.             <driver>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver>
  5.             <connection-string>jdbc:sqlserver://s.domain.com;database=Material;user=test;password=test;</connection-string>
  6.         </database-connection>
  7.         <database-connection name="rok-dc">
  8.             <driver>net.sourceforge.jtds.jdbc.Driver</driver>
  9.             <!-- http://jtds.sourceforge.net/faq.html#urlFormat -->
  10.             <connection-string>jdbc:jtds:sqlserver://a.domain.com/dcSql;user=test;password=test;</connection-string>
  11.         </database-connection>
  12.     </database-connections>
  13. </configuration>
  14.  
  15.  
  16.  
  17. xquery version "3.0";
  18.  
  19. module namespace db="http://domain.com/db";
  20. declare namespace sql="http://exist-db.org/xquery/sql";
  21. import module namespace functx="http://www.functx.com";
  22. import module namespace config="http://domain.com/inventory/config" at "config.xqm";
  23.  
  24. declare variable $db:config-doc := doc($config:app-root || '/data/configuration.xml');
  25.  
  26. declare function db:get-connection($connection-name as xs:string)
  27. {
  28.     let $connection-node := $db:config-doc/configuration/database-connections/database-connection[@name/string() eq $connection-name]
  29.    
  30.     return
  31.     if(not($connection-node))
  32.     then ()
  33.     else sql:get-connection($connection-node/driver/text(), $connection-node/connection-string/text())
  34. };
  35.  
  36. declare function db:execute($connection, $query as xs:string, $use-column-names as xs:boolean)
  37. {
  38.     sql:execute($connection, $query, $use-column-names)
  39. };
  40.  
  41. declare function db:execute-on($connection-name as xs:string, $query as xs:string)
  42. {
  43.     db:execute(db:get-connection($connection-name), $query, true())
  44. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement