|
Adodb Dokumentation
V5.14 8 Sept 2011
|


Öffentliche Methoden | |
| dbData (&$parent, $attributes=NULL) | |
| _tag_open (&$parser, $tag, $attributes) | |
| _tag_cdata (&$parser, $cdata) | |
| _tag_close (&$parser, $tag) | |
| addField ($attributes) | |
| addData ($cdata) | |
| create (&$xmls) | |
| dbData (&$parent, $attributes=NULL) | |
| _tag_open (&$parser, $tag, $attributes) | |
| _tag_cdata (&$parser, $cdata) | |
| _tag_close (&$parser, $tag) | |
| addField ($attributes) | |
| addData ($cdata) | |
| create (&$xmls) | |
Datenfelder | |
| $data = array() | |
| $row | |
Definiert in Zeile 775 der Datei adodb-xmlschema.inc.php.
| _tag_cdata | ( | &$ | parser, |
| $ | cdata | ||
| ) |
XML Callback to process CDATA elements
Processes XML cdata.
private
Erneute Implementation von dbObject.
Definiert in Zeile 823 der Datei adodb-xmlschema.inc.php.
{
switch( $this->currentElement ) {
// Index field name
case 'F':
$this->addData( $cdata );
break;
default:
}
}

| _tag_cdata | ( | &$ | parser, |
| $ | cdata | ||
| ) |
XML Callback to process CDATA elements
Processes XML cdata.
private
Erneute Implementation von dbObject.
Definiert in Zeile 865 der Datei adodb-xmlschema03.inc.php.
{
switch( $this->currentElement ) {
// Index field name
case 'F':
$this->addData( $cdata );
break;
default:
}
}

| _tag_close | ( | &$ | parser, |
| $ | tag | ||
| ) |
XML Callback to process end elements
private
Erneute Implementation von dbObject.
Definiert in Zeile 839 der Datei adodb-xmlschema.inc.php.
{
$this->currentElement = '';
switch( strtoupper( $tag ) ) {
case 'DATA':
xml_set_object( $parser, $this->parent );
break;
}
}
| _tag_close | ( | &$ | parser, |
| $ | tag | ||
| ) |
XML Callback to process end elements
private
Erneute Implementation von dbObject.
Definiert in Zeile 881 der Datei adodb-xmlschema03.inc.php.
{
$this->currentElement = '';
switch( strtoupper( $tag ) ) {
case 'DATA':
xml_set_object( $parser, $this->parent );
break;
}
}
| _tag_open | ( | &$ | parser, |
| $ | tag, | ||
| $ | attributes | ||
| ) |
XML Callback to process start elements
Processes XML opening tags. Elements currently processed are: DROP, CLUSTERED, BITMAP, UNIQUE, FULLTEXT & HASH.
private
Erneute Implementation von dbObject.
Definiert in Zeile 801 der Datei adodb-xmlschema.inc.php.
{
$this->currentElement = strtoupper( $tag );
switch( $this->currentElement ) {
case 'ROW':
$this->row = count( $this->data );
$this->data[$this->row] = array();
break;
case 'F':
$this->addField($attributes);
default:
// print_r( array( $tag, $attributes ) );
}
}

| _tag_open | ( | &$ | parser, |
| $ | tag, | ||
| $ | attributes | ||
| ) |
XML Callback to process start elements
Processes XML opening tags. Elements currently processed are: ROW and F (field).
private
Erneute Implementation von dbObject.
Definiert in Zeile 843 der Datei adodb-xmlschema03.inc.php.
{
$this->currentElement = strtoupper( $tag );
switch( $this->currentElement ) {
case 'ROW':
$this->row = count( $this->data );
$this->data[$this->row] = array();
break;
case 'F':
$this->addField($attributes);
default:
// print_r( array( $tag, $attributes ) );
}
}

| addData | ( | $ | cdata | ) |
Adds options to the index
| string | $opt | Comma-separated list of index options. |
Definiert in Zeile 872 der Datei adodb-xmlschema.inc.php.
{
if( !isset( $this->data[$this->row] ) ) {
$this->data[$this->row] = array();
}
if( !isset( $this->data[$this->row][$this->current_field] ) ) {
$this->data[$this->row][$this->current_field] = '';
}
$this->data[$this->row][$this->current_field] .= $cdata;
}

| addData | ( | $ | cdata | ) |
Adds options to the index
| string | $opt | Comma-separated list of index options. |
Definiert in Zeile 922 der Datei adodb-xmlschema03.inc.php.
{
// check we're in a valid field
if ( isset( $this->data[$this->row][$this->current_field] ) ) {
// add data to field
$this->data[$this->row][$this->current_field] .= $cdata;
}
}
| addField | ( | $ | attributes | ) |
Adds a field to the index
| string | $name | Field name |
Definiert in Zeile 855 der Datei adodb-xmlschema.inc.php.
{
if( isset( $attributes['NAME'] ) ) {
$name = $attributes['NAME'];
} else {
$name = count($this->data[$this->row]);
}
// Set the field index so we know where we are
$this->current_field = $this->FieldID( $name );
}


| addField | ( | $ | attributes | ) |
Adds a field to the insert
| string | $name | Field name |
Definiert in Zeile 897 der Datei adodb-xmlschema03.inc.php.
{
// check we're in a valid row
if( !isset( $this->row ) || !isset( $this->data[$this->row] ) ) {
return;
}
// Set the field index so we know where we are
if( isset( $attributes['NAME'] ) ) {
$this->current_field = $this->FieldID( $attributes['NAME'] );
} else {
$this->current_field = count( $this->data[$this->row] );
}
// initialise data
if( !isset( $this->data[$this->row][$this->current_field] ) ) {
$this->data[$this->row][$this->current_field] = '';
}
}

| create | ( | &$ | xmls | ) |
Generates the SQL that will create the index in the database
| object | $xmls | adoSchema object |
Erneute Implementation von dbObject.
Definiert in Zeile 890 der Datei adodb-xmlschema.inc.php.
{
$table = $xmls->dict->TableName($this->parent->name);
$table_field_count = count($this->parent->fields);
$sql = array();
// eliminate any columns that aren't in the table
foreach( $this->data as $row ) {
$table_fields = $this->parent->fields;
$fields = array();
foreach( $row as $field_id => $field_data ) {
if( !array_key_exists( $field_id, $table_fields ) ) {
if( is_numeric( $field_id ) ) {
$field_id = reset( array_keys( $table_fields ) );
} else {
continue;
}
}
$name = $table_fields[$field_id]['NAME'];
switch( $table_fields[$field_id]['TYPE'] ) {
case 'C':
case 'C2':
case 'X':
case 'X2':
$fields[$name] = $xmls->db->qstr( $field_data );
break;
case 'I':
case 'I1':
case 'I2':
case 'I4':
case 'I8':
$fields[$name] = intval($field_data);
break;
default:
$fields[$name] = $field_data;
}
unset($table_fields[$field_id]);
}
// check that at least 1 column is specified
if( empty( $fields ) ) {
continue;
}
// check that no required columns are missing
if( count( $fields ) < $table_field_count ) {
foreach( $table_fields as $field ) {
if (isset( $field['OPTS'] ))
if( ( in_array( 'NOTNULL', $field['OPTS'] ) || in_array( 'KEY', $field['OPTS'] ) ) && !in_array( 'AUTOINCREMENT', $field['OPTS'] ) ) {
continue(2);
}
}
}
$sql[] = 'INSERT INTO '. $table .' ('. implode( ',', array_keys( $fields ) ) .') VALUES ('. implode( ',', $fields ) .')';
}
return $sql;
}
| create | ( | &$ | xmls | ) |
Generates the SQL that will add/update the data in the database
| object | $xmls | adoSchema object |
Erneute Implementation von dbObject.
Definiert in Zeile 936 der Datei adodb-xmlschema03.inc.php.
{
$table = $xmls->dict->TableName($this->parent->name);
$table_field_count = count($this->parent->fields);
$tables = $xmls->db->MetaTables();
$sql = array();
$ukeys = $xmls->db->MetaPrimaryKeys( $table );
if( !empty( $this->parent->indexes ) and !empty( $ukeys ) ) {
foreach( $this->parent->indexes as $indexObj ) {
if( !in_array( $indexObj->name, $ukeys ) ) $ukeys[] = $indexObj->name;
}
}
// eliminate any columns that aren't in the table
foreach( $this->data as $row ) {
$table_fields = $this->parent->fields;
$fields = array();
$rawfields = array(); // Need to keep some of the unprocessed data on hand.
foreach( $row as $field_id => $field_data ) {
if( !array_key_exists( $field_id, $table_fields ) ) {
if( is_numeric( $field_id ) ) {
$field_id = reset( array_keys( $table_fields ) );
} else {
continue;
}
}
$name = $table_fields[$field_id]['NAME'];
switch( $table_fields[$field_id]['TYPE'] ) {
case 'I':
case 'I1':
case 'I2':
case 'I4':
case 'I8':
$fields[$name] = intval($field_data);
break;
case 'C':
case 'C2':
case 'X':
case 'X2':
default:
$fields[$name] = $xmls->db->qstr( $field_data );
$rawfields[$name] = $field_data;
}
unset($table_fields[$field_id]);
}
// check that at least 1 column is specified
if( empty( $fields ) ) {
continue;
}
// check that no required columns are missing
if( count( $fields ) < $table_field_count ) {
foreach( $table_fields as $field ) {
if( isset( $field['OPTS'] ) and ( in_array( 'NOTNULL', $field['OPTS'] ) || in_array( 'KEY', $field['OPTS'] ) ) && !in_array( 'AUTOINCREMENT', $field['OPTS'] ) ) {
continue(2);
}
}
}
// The rest of this method deals with updating existing data records.
if( !in_array( $table, $tables ) or ( $mode = $xmls->existingData() ) == XMLS_MODE_INSERT ) {
// Table doesn't yet exist, so it's safe to insert.
logMsg( "$table doesn't exist, inserting or mode is INSERT" );
$sql[] = 'INSERT INTO '. $table .' ('. implode( ',', array_keys( $fields ) ) .') VALUES ('. implode( ',', $fields ) .')';
continue;
}
// Prepare to test for potential violations. Get primary keys and unique indexes
$mfields = array_merge( $fields, $rawfields );
$keyFields = array_intersect( $ukeys, array_keys( $mfields ) );
if( empty( $ukeys ) or count( $keyFields ) == 0 ) {
// No unique keys in schema, so safe to insert
logMsg( "Either schema or data has no unique keys, so safe to insert" );
$sql[] = 'INSERT INTO '. $table .' ('. implode( ',', array_keys( $fields ) ) .') VALUES ('. implode( ',', $fields ) .')';
continue;
}
// Select record containing matching unique keys.
$where = '';
foreach( $ukeys as $key ) {
if( isset( $mfields[$key] ) and $mfields[$key] ) {
if( $where ) $where .= ' AND ';
$where .= $key . ' = ' . $xmls->db->qstr( $mfields[$key] );
}
}
$records = $xmls->db->Execute( 'SELECT * FROM ' . $table . ' WHERE ' . $where );
switch( $records->RecordCount() ) {
case 0:
// No matching record, so safe to insert.
logMsg( "No matching records. Inserting new row with unique data" );
$sql[] = $xmls->db->GetInsertSQL( $records, $mfields );
break;
case 1:
// Exactly one matching record, so we can update if the mode permits.
logMsg( "One matching record..." );
if( $mode == XMLS_MODE_UPDATE ) {
logMsg( "...Updating existing row from unique data" );
$sql[] = $xmls->db->GetUpdateSQL( $records, $mfields );
}
break;
default:
// More than one matching record; the result is ambiguous, so we must ignore the row.
logMsg( "More than one matching record. Ignoring row." );
}
}
return $sql;
}
| dbData | ( | &$ | parent, |
| $ | attributes = NULL |
||
| ) |
Initializes the new dbIndex object.
| object | $parent | Parent object |
| array | $attributes | Attributes |
Definiert in Zeile 789 der Datei adodb-xmlschema.inc.php.
{
$this->parent = $parent;
}
| dbData | ( | &$ | parent, |
| $ | attributes = NULL |
||
| ) |
Initializes the new dbData object.
| object | $parent | Parent object |
| array | $attributes | Attributes |
Definiert in Zeile 831 der Datei adodb-xmlschema03.inc.php.
{
$this->parent = $parent;
}