[ Index ]
 

Code source de eGroupWare 1.2.106-2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/etemplate/inc/ -> class.so_sql.inc.php (sommaire)

(pas de description)

Poids: 800 lignes (26 kb)
Inclus ou requis: 13 fois
Référencé: 0 fois
Nécessite: 0 fichiers

Définit 1 class

so_sql:: (14 méthodes):
  so_sql()
  setup_table()
  data_merge()
  db2data()
  data2db()
  init()
  read()
  save()
  delete()
  search()
  _get_columns()
  get_rows()
  not_unique()
  query_list()


Classe: so_sql  - X-Ref

generalized SQL Storage Object

the class can be used in following ways:
1) by calling the constructor with an app and table-name or
2) by setting the following documented class-vars in a class derifed from this one
Of cause can you derife the class and call the constructor with params.

so_sql($app='',$table='',$db=null,$column_prefix='')   X-Ref
constructor of the class

NEED to be called from the constructor of the derived class !!!

param: string $app should be set if table-defs to be read from <app>/setup/tables_current.inc.php
param: string $table should be set if table-defs to be read from <app>/setup/tables_current.inc.php
param: object/db $db database object, if not the one in $GLOBALS['egw']->db should be used, eg. for an other database
param: string $colum_prefix='' column prefix to automatic remove from the column-name, if the column name starts with it

setup_table($app,$table,$colum_prefix='')   X-Ref
sets up the class for an app and table (by using the table-definition of $app/setup/tables_current.inc.php

If you need a more complex conversation then just removing the column_prefix, you have to do so in a derifed class !!!

param: string $app app-name $table belongs too
param: string $table table-name
param: string $colum_prefix='' column prefix to automatic remove from the column-name, if the column name starts with it

data_merge($new)   X-Ref
merges in new values from the given new data-array

param: $new array in form col => new_value with values to set

db2data($data=null)   X-Ref
changes the data from the db-format to your work-format

it gets called everytime when data is read from the db
This function needs to be reimplemented in the derived class

param: array $data if given works on that array and returns result, else works on internal data-array

data2db($data=null)   X-Ref
changes the data from your work-format to the db-format

It gets called everytime when data gets writen into db or on keys for db-searches
this needs to be reimplemented in the derived class

param: array $data if given works on that array and returns result, else works on internal data-array

init($keys=array()   X-Ref
initializes data with the content of key

param: array $keys array with keys in form internalName => value

read($keys,$extra_cols='',$join='')   X-Ref
reads row matched by key and puts all cols in the data array

param: array $keys array with keys in form internalName => value, may be a scalar value if only one key
param: string/array $extra_cols string or array of strings to be added to the SELECT, eg. "count(*) as num"
param: string $join='' sql to do a join, added as is after the table-name, eg. ", table2 WHERE x=y" or
return: array/boolean data if row could be retrived else False

save($keys=null)   X-Ref
saves the content of data to the db

param: array $keys if given $keys are copied to data before saveing => allows a save as
return: int 0 on success and errno != 0 else

delete($keys=null)   X-Ref
deletes row representing keys in internal data or the supplied $keys if != null

param: array $keys if given array with col => value pairs to characterise the rows to delete
return: int affected rows, should be 1 if ok, 0 if an error

search($criteria,$only_keys=True,$order_by='',$extra_cols='',$wildcard='',$empty=False,$op='AND',$start=false,$filter=null,$join='',$need_full_no_count=false)   X-Ref
searches db for rows matching searchcriteria

'*' and '?' are replaced with sql-wildcards '%' and '_'

For a union-query you call search for each query with $start=='UNION' and one more with only $order_by and $start set to run the union-query.

param: array/string $criteria array of key and data cols, OR a SQL query (content for WHERE), fully quoted (!)
param: boolean/string $only_keys=true True returns only keys, False returns all cols. comma seperated list of keys to return
param: string $order_by='' fieldnames + {ASC|DESC} separated by colons ',', can also contain a GROUP BY (if it contains ORDER BY)
param: string/array $extra_cols='' string or array of strings to be added to the SELECT, eg. "count(*) as num"
param: string $wildcard='' appended befor and after each criteria
param: boolean $empty=false False=empty criteria are ignored in query, True=empty have to be empty in row
param: string $op='AND' defaults to 'AND', can be set to 'OR' too, then criteria's are OR'ed together
param: mixed $start=false if != false, return only maxmatch rows begining with start, or array($start,$num), or 'UNION' for a part of a union query
param: array $filter=null if set (!=null) col-data pairs, to be and-ed (!) into the query without wildcards
param: string $join='' sql to do a join, added as is after the table-name, eg. ", table2 WHERE x=y" or
param: boolean $need_full_no_count=false If true an unlimited query is run to determine the total number of rows, default false
return: boolean/array of matching rows (the row is an array of the cols) or False

_get_columns($only_keys,$extra_cols)   X-Ref
extract the requested columns from $only_keys and $extra_cols param of a search

param: boolean/string $only_keys=true True returns only keys, False returns all cols. comma seperated list of keys to return
param: string/array $extra_cols='' string or array of strings to be added to the SELECT, eg. "count(*) as num"
return: array with columns as db-name => internal-name pairs

get_rows($query,&$rows,&$readonlys,$join='',$need_full_no_count=false)   X-Ref
query rows for the nextmatch widget

param: array $query with keys 'start', 'search', 'order', 'sort', 'col_filter'
param: array &$rows returned rows/competitions
param: array &$readonlys eg. to disable buttons based on acl, not use here, maybe in a derived class
param: string $join='' sql to do a join, added as is after the table-name, eg. ", table2 WHERE x=y" or
param: boolean $need_full_no_count=false If true an unlimited query is run to determine the total number of rows, default false
return: int total number of rows

not_unique($data=null)   X-Ref
Check if values for unique keys are unique

param: array $data data-set to check, defaults to $this->data
return: int 0: all keys are unique, 1: first key not unique, 2: ...

query_list($value_col,$key_col='',$filter=array()   X-Ref
Query DB for a list / array with one colum as key and an other one(s) as value, eg. id => title pairs

We do some caching as these kind of function is usualy called multiple times, eg. for option-lists.

param: string $value_col array of column-names for the values of the array, can also be an expression aliased with AS,
param: string $key_col='' column-name for the keys, default '' = same as (first) $value_col: returns a distinct list
param: array $filter=array() to filter the entries
param: string $order='' order, default '' = same as (first) $value_col
return: array with key_col => value_col pairs or array if more then one value_col given (keys as in value_col)



Généré le : Sun Feb 25 17:20:01 2007 par Balluche grâce à PHPXref 0.7