On Sunday 19 June 2005 15:23, Dan Langille wrote:
...
>
> I had some thoughts about how to handle different databases.  I think
> we should have one file per database.  For example:
>
> mysql.php
> postgresql.php
>
> Each of these files will contains functions that returns an SQL
> statement.  That statement is then used by the main body of code.
>
> example:
>
> function sql_CalculateBytesPeriod($Server, $StartPeriod, $EndPeriod)
> {
>    $sql = "
> SELECT sum(JobBytes) as jobbytes
>    FROM job
> WHERE endtime < '$EndPeriod'
>    AND endtime > '$StartDate'
>    AND name='$server'";
>
>    return $sql
> }

I did something like this in Bacula by moving a lot but not all of the SQL to 
a single file, dird/sql_cmds.c   In the file, I use #ifdefs in the few places 
where different SQL is required (when concatenating output of two columns, 
and when creating temp tables).  

I regret doing this because it removes the SQL from the code, so each time I 
want to understand or change the code I need to look at two files this slows 
down programming and makes it more prone to errors (at least for me).

What you are suggesting would increase the programming time, because even for 
SQL is identical: we would have to write it two times; we would also have to 
modify it in two places; and as in what I did, the SQL would be separate from 
the code that uses it.

>
>
> To document what goes into each file, have a main 'documention'
> example.
>
> <?php
>
> function sql_CalculateBytesPeriod($Server, $StartPeriod, $EndPeriod)
> {
>
>    # obtain the number of bytes backed up from a particular server
>    # between two given dates.
>    #
>    # example result set:
>
> /*
> bacula=> select SUM(JobFiles) from Job WHERE EndTime < '2005-06-18
> 23:59:59' and EndTime > '2005-05-18 00:00:00' and Name='nezlok'
> bacula-> ;
>  sum
> ------
>  8817
> (1 row)
>
> bacula=>
> */
>    return '';
>  }
>
>
> With this approach, the documentation is in one place. We have an
> example result set.

-- 
Best regards,

Kern

  (">
  /\
  V_V


-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Bacula-users mailing list
Bacula-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bacula-users

Reply via email to