phpgroupware-developers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Phpgroupware-developers] Schema Availability to Apps


From: Ralf Becker
Subject: Re: [Phpgroupware-developers] Schema Availability to Apps
Date: Wed, 21 May 2003 08:34:25 +0200
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; de-AT; rv:1.3) Gecko/20030312

I use something similar in some of my apps:

It's an (abstract) base-class for an so-layer. It includes the schema and works on that information. It has functions for reading, writeting or searching in the table and two function to convert the db-representation of the data-object in the internal one and back (with can be extended / overwritten in the extending class).

If you want to check it out: etemplate/inc/so_sql.inc.php

Examples how to use the class are in the etemplte tutorial and each function has ein extensive include-doc.

Ralf

PS It does not deal with MSSQL or Sybase (missing) datetime types at the moment, but its easy to add, as the class is aware of the type of each colum and abstracts the sql to access the table (you dont need to write sql direct).

Michael Dean schrieb:
I remember raising this issue when I first proposed the schema_proc
classes to phpGW, and while working with DCL recently, I have come
across a need for loading table schemas dynamically so I can use the
metadata to generate SQL.  This is necessary for a class I have that
generates SQL based on several attributes, including column list,
filters, joins, etc.

The issue at hand is that MSSQL and Sybase do not have native datetime
support in DCL.  I am currently implementing this functionality (and it
can/will be pushed to phpGW classes).  The reason the native support did
not exist was because the client libraries returned the default format
(Day Mon DD YYYY HH:MM:SS AM/PM), which isn't something you want to
parse.  To work around this, I need to wrap all column list references
in an abstract function.

So, what I have decided to do (rather than hard code all my dates and
timestamps) is break up the schema defined in phpgw_baseline into
multiple files under dcl/schema.  I have then created a method to load
this based on table name (LoadSchema).  The dcl/schema directory has a
bunch of schema.*.php files that individually set the table's metadata
in the phpgw_baseline array.  This means the tables_current.php would
just include all of the schema.*.php files instead of being one huge
array definition.

Anyway, I thought I'd share this function and if anyone finds it to be
useful in phpGW (I know I would), we can add this to the API.

Mike

********** Code Samples ************

/////////////// LoadSchema definition - global in scope
//
function LoadSchema($sTableName)
{
        $sConst = sprintf('SCHEMA_%s_INCLUDED', $sTableName);
        if (!defined($sConst))
        {
                if (!is_array($GLOBALS['phpgw_baseline']))
                        $GLOBALS['phpgw_baseline'] = array();

                define($sConst, 1);
                include(sprintf($GLOBALS['dcl_root'] . 'schema/schema.%s.php',
$sTableName));
        }
}

/////////////// schema.dcl_preferences.php file from app/schema dir
//
<?php
$GLOBALS['phpgw_baseline']['dcl_preferences'] = array(
        'fd' => array(
                'personnel_id' => array('type' => 'int', 'precision' => 4, 
'nullable'
=> false),
                'preferences_data' => array('type' => 'text')
        ),
        'pk' => array('personnel_id'),
        'fk' => array(),
        'ix' => array(),
        'uc' => array()
);
?>



_______________________________________________
Phpgroupware-developers mailing list
address@hidden
http://mail.gnu.org/mailman/listinfo/phpgroupware-developers


--
----------------------------------------------------------------------
Ralf Becker
OUTDOOR UNLIMITED Training GmbH                Telefon 0631 / 31657-0
Leibnizstraße 17                               Telefax 0631 / 31657-26
D-67663 Kaiserslautern            EMail address@hidden





reply via email to

[Prev in Thread] Current Thread [Next in Thread]