Difference between revisions of "HOWTO use the very same CCDB for different databases"

From GlueXWiki
Jump to: navigation, search
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
CCDB uses connection string to connect to databases. To use different databases with one installation of CCDB one should pass different connection string to it. How to do this?
+
CCDB uses connection string to connect to databases. To use different databases with one installation of CCDB one should pass different connection string to it. So, here is how to do this.
 +
 
 +
Lets consider we have two databases '''ONE''' and '''TWO'''
  
  
Line 10: Line 12:
  
  
Flag '-c' has higher priority, so if one does next command, one is solid sure CCDB connects to db '''ONE''':
+
Flag '-c' has higher priority, so if you execute the next command, you may be solid sure '''ccdb''' is connected to DB '''ONE'''
  
 
<pre>
 
<pre>
Line 17: Line 19:
  
  
Thus one can create an alias:
+
To skip writing '-c ...', one could create an alias:
 
<pre>
 
<pre>
 
alias ccdb_online="ccdb -c mysql://ONE_user@host/ONE"
 
alias ccdb_online="ccdb -c mysql://ONE_user@host/ONE"
 
</pre>
 
</pre>
  
Whenever ''ccdb_online'' is called, it connects to database ''ONE'' now.  
+
Now when ''ccdb_online'' is called, it connects to database ''ONE''.  
  
  
  
To end up with the example, lets consider we have two databases '''ONE''' and '''TWO'''.
+
To end up with the example, lets suppose we have environment setup:
If we have environment setup:
+
  
 
<pre>
 
<pre>

Latest revision as of 23:16, 3 April 2014

CCDB uses connection string to connect to databases. To use different databases with one installation of CCDB one should pass different connection string to it. So, here is how to do this.

Lets consider we have two databases ONE and TWO


1. Command line tools (CCDB CLI):

There are two ways of passing connection string to ccdb command:

  • Use CCDB_CONNECTION environment variable
  • '-c <connection string>' flag on ccdb start.


Flag '-c' has higher priority, so if you execute the next command, you may be solid sure ccdb is connected to DB ONE

> ccdb -i -c mysql://ONE_db_user@host/ONE


To skip writing '-c ...', one could create an alias:

alias ccdb_online="ccdb -c mysql://ONE_user@host/ONE"

Now when ccdb_online is called, it connects to database ONE.


To end up with the example, lets suppose we have environment setup:

alias ccdb_online="ccdb -c mysql://ONE_user@host/ONE"  
export CCDB_CONNECTION=mysql://TWO_user@host/TWO


Now if we call...

> ccdb -i          # connects to db TWO, because of CCDB_CONNECTION
> ccdb_online -i   # connects to ONE, because it is alias with '-c' flag


Without doubt one should be able even to call:

> ccdb -i -c sqlite:///some.file.db
> ccdb_online -i -c sqlite:///some.file.db   # SHOULD work too



2. JANA

Jana uses JANA_CALIB_URL environment variable. One has to set right connection string to this variable before JANA starts.



3. Language interfaces.

Language interfaces (C++ API, Python API and Java) API get connection string directly in factory function. Like:

Calibration* calib = CalibrationGenerator.Create("mysql://ONE_user@host/ONE",...)

So one just passes the right connection string to API.