phpDocumentor pond
[ class tree: pond ] [ index: pond ] [ all elements ]

Procedural File: _upgrade.funcs.php

Source Location: /qp_inc/_core/model/db/_upgrade.funcs.php

Page Details

This file implements functions useful for upgrading DB schema.

This file is part of the Quam Plures project - http://quamplures.net/. See also https://launchpad.net/quam-plures.

Author:  fplanque: Francois PLANQUE
Author:  blueyed: Daniel HAHLER
Author:  Wordpress team
Copyright:  (c) 2009 - 2011 by the Quam Plures developers - http://quamplures.net/
Copyright:  

(c)2003-2009 by Francois PLANQUE - http://fplanque.net/. Parts of this file are copyright (c)2004-2005 by Daniel HAHLER - https://thequod.de/.

db_delta() is based on dbDelta() from Wordpress, see http://trac.wordpress.org/file/trunk/wp-admin/upgrade-functions.php.

Filesource:  Source Code for this file
License:  GNU General Public License (GPL)
Functions
db_delta  [line 80]

array db_delta( array $queries, [array $exclude_types = array()], [boolean $execute = false]  )

Get the delta query to adjust the current database according to a given (list of) "CREATE TABLE"-, "CREATE DATABASE"-, "INSERT"- or "UPDATE"-statement(s).

It's not recommend to use INSERT or UPDATE statements with this function, as they are just handled "as-is".

NOTE:

  • You should use single quotes (') to give string type values (this is in fact required for ENUM and SET fields).
  • KEYs for AUTO_INCREMENT fields should be defined in column_definition, otherwise we had to detect the key type from the INDEX query and add it to the ALTER/ADD query.
  • If a column changes from "NULL" to "NOT NULL" we generate an extra UPDATE query to prevent "Data truncated for column 'X' at row Y" errors.
The following query types are generated/marked and can be excluded:
  • 'create_table'
  • 'create_database'
  • 'insert'
  • 'update'
  • 'drop_column'
  • 'change_column'
  • 'change_default'
  • 'add_column'
  • 'add_index'
  • 'drop_index'
  • 'alter_engine'
NOTE: it may be needed to merge an 'add_index' or 'drop_index' type query into an 'add_column'/'change_column' query (adding "AUTO_INCREMENT" for example)!

NOTE: collations and charset changes are ignored. It seems quite difficult to support this, and it seems to be best to handle this "manually".

Parameters:
array   $queries:  The list of queries for which the DB should be adjusted
array   $exclude_types:  Exclude query types (see list above).
boolean   $execute:  Execute generated queries? TODO: get this outta here!!!! (sooooo bloated!)

API Tags:
Return:  The generated queries. table_name => array of arrays (queries with keys 'queries' (array), 'note' (string) and 'type' (string)) There's usually just a single query in "queries", but in some cases additional queries are needed (e.g., 'UPDATE' before we can change "NULL" setting).
See:  http://dev.mysql.com/doc/refman/4.1/en/create-table.html

Information Tags:
Author:  Originally taken from Wordpress, heavily enhanced and modified by blueyed
Todo:  Handle COMMENT for tables?!

[ Top ]
db_delta_remove_quotes  [line 1175]

string db_delta_remove_quotes( string $fieldname, [string $quotes = '`"']  )

Remove quotes/backticks around a field/table name.

Parameters:
string   $fieldname:  Field name
string   $quotes:  List of quote chars to remove


[ Top ]
install_make_db_schema_current  [line 1199]

void install_make_db_schema_current( [boolean $display = true]  )

Alter the DB schema to match the current expected one ($schema_queries).

Parameters:
boolean   $display:  Display what we've done?

Information Tags:
Todo:  if used by install only, then put it into the install folder!!!

[ Top ]