23 if (function_exists(
'file_get_contents'))
return file_get_contents($file);
25 $f = fopen($file,
'r');
29 while ($s = fread($f,100000)) $t .= $s;
38 if( !defined(
'XMLS_DEBUG' ) ) {
39 define(
'XMLS_DEBUG', FALSE );
45 if( !defined(
'XMLS_PREFIX' ) ) {
46 define(
'XMLS_PREFIX',
'%%P' );
52 if( !defined(
'XMLS_PREFIX_MAXLEN' ) ) {
53 define(
'XMLS_PREFIX_MAXLEN', 10 );
59 if( !defined(
'XMLS_EXECUTE_INLINE' ) ) {
60 define(
'XMLS_EXECUTE_INLINE', FALSE );
66 if( !defined(
'XMLS_CONTINUE_ON_ERROR' ) ) {
67 define(
'XMLS_CONTINUE_ON_ERROR', FALSE );
73 if( !defined(
'XMLS_SCHEMA_VERSION' ) ) {
74 define(
'XMLS_SCHEMA_VERSION',
'0.3' );
80 if( !defined(
'XMLS_DEFAULT_SCHEMA_VERSION' ) ) {
81 define(
'XMLS_DEFAULT_SCHEMA_VERSION',
'0.1' );
89 if( !defined(
'XMLS_MODE_INSERT' ) ) {
90 define(
'XMLS_MODE_INSERT', 0 );
92 if( !defined(
'XMLS_MODE_UPDATE' ) ) {
93 define(
'XMLS_MODE_UPDATE', 1 );
95 if( !defined(
'XMLS_MODE_IGNORE' ) ) {
96 define(
'XMLS_MODE_IGNORE', 2 );
98 if( !defined(
'XMLS_EXISTING_DATA' ) ) {
99 define(
'XMLS_EXISTING_DATA', XMLS_MODE_INSERT );
105 if( !defined(
'XMLS_DEFAULT_UPGRADE_METHOD' ) ) {
106 define(
'XMLS_DEFAULT_UPGRADE_METHOD',
'ALTER' );
112 if( !defined(
'_ADODB_LAYER' ) ) {
113 require(
'adodb.inc.php' );
114 require(
'adodb-datadict.inc.php' );
189 return is_object( $this->parent ) ? $this->parent->supportedPlatform( $platform ) : TRUE;
199 return is_object( $this->parent ) ? $this->parent->prefix( $name ) : $name;
209 return strtoupper( preg_replace(
'/^`(.+)`$/',
'$1', $field ) );
278 $this->name = $this->
prefix($attributes[
'NAME']);
288 $this->currentElement = strtoupper( $tag );
290 switch( $this->currentElement ) {
292 if( !isset( $attributes[
'PLATFORM'] ) OR $this->
supportedPlatform( $attributes[
'PLATFORM'] ) ) {
293 xml_set_object( $parser, $this->
addIndex( $attributes ) );
297 if( !isset( $attributes[
'PLATFORM'] ) OR $this->
supportedPlatform( $attributes[
'PLATFORM'] ) ) {
298 xml_set_object( $parser, $this->
addData( $attributes ) );
306 $fieldName = $attributes[
'NAME'];
307 $fieldType = $attributes[
'TYPE'];
308 $fieldSize = isset( $attributes[
'SIZE'] ) ? $attributes[
'SIZE'] : NULL;
309 $fieldOpts = !empty( $attributes[
'OPTS'] ) ? $attributes[
'OPTS'] : NULL;
311 $this->
addField( $fieldName, $fieldType, $fieldSize, $fieldOpts );
315 case 'AUTOINCREMENT':
320 $this->
addFieldOpt( $this->current_field, $this->currentElement );
326 if( $attributes[
'VALUE'] ==
'' ) {
327 $attributes[
'VALUE'] =
" '' ";
330 $this->
addFieldOpt( $this->current_field, $this->currentElement, $attributes[
'VALUE'] );
335 $this->currentPlatform = ( !isset( $attributes[
'PLATFORM'] ) OR $this->
supportedPlatform( $attributes[
'PLATFORM'] ) );
348 switch( $this->currentElement ) {
351 if( isset( $this->current_field ) ) {
352 $this->
addFieldOpt( $this->current_field, $this->currentElement, $cdata );
359 if( isset( $this->current_field ) ) {
360 $this->
addFieldOpt( $this->current_field, $cdata );
376 $this->currentElement =
'';
378 switch( strtoupper( $tag ) ) {
380 $this->parent->addSQL( $this->
create( $this->parent ) );
381 xml_set_object( $parser, $this->parent );
385 unset($this->current_field);
389 $this->currentPlatform =
true;
403 $name = strtoupper( $attributes[
'NAME'] );
404 $this->indexes[
$name] =
new dbIndex( $this, $attributes );
405 return $this->indexes[
$name];
415 if( !isset( $this->data ) ) {
416 $this->data =
new dbData( $this, $attributes );
454 $this->current_field = $field_id;
457 $this->fields[$field_id][
'NAME'] =
$name;
460 $this->fields[$field_id][
'TYPE'] = $type;
463 if( isset( $size ) ) {
464 $this->fields[$field_id][
'SIZE'] = $size;
468 if( isset(
$opts ) ) {
469 $this->fields[$field_id][
'OPTS'] = array(
$opts);
471 $this->fields[$field_id][
'OPTS'] = array();
487 if( $this->currentPlatform ) {
488 if( !isset( $value ) ) {
489 $this->fields[$this->
FieldID( $field )][
'OPTS'][] = $opt;
492 $this->fields[$this->
FieldID( $field )][
'OPTS'][] = array( $opt => $value );
507 if(isset($this->currentPlatform)) {
508 $this->opts[$this->parent->db->databaseType] = $opt;
524 if( is_array( $legacy_indexes = $xmls->dict->MetaIndexes( $this->name ) ) ) {
525 foreach( $legacy_indexes as $index => $index_details ) {
526 $sql[] = $xmls->dict->DropIndexSQL( $index, $this->name );
531 foreach( $this->drop_field as $field ) {
532 unset( $this->fields[$field] );
536 if( is_array( $legacy_fields = $xmls->dict->MetaColumns( $this->name ) ) ) {
538 if( $this->drop_table ) {
539 $sql[] = $xmls->dict->DropTableSQL( $this->name );
545 foreach( $legacy_fields as $field_id => $field ) {
546 if( !isset( $this->fields[$field_id] ) ) {
547 $sql[] = $xmls->dict->DropColumnSQL( $this->name, $field->name );
552 if( $this->drop_table ) {
556 $legacy_fields = array();
562 foreach( $this->fields as $field_id => $finfo ) {
564 if( !isset( $finfo[
'SIZE'] ) ) {
569 $fldarray[$field_id] = array(
570 'NAME' => $finfo[
'NAME'],
571 'TYPE' => $finfo[
'TYPE'],
572 'SIZE' => $finfo[
'SIZE']
576 if( isset( $finfo[
'OPTS'] ) ) {
577 foreach( $finfo[
'OPTS'] as $opt ) {
579 if( is_array( $opt ) ) {
581 $value = $opt[key( $opt )];
582 @$fldarray[$field_id][$key] .= $value;
585 $fldarray[$field_id][$opt] = $opt;
591 if( empty( $legacy_fields ) ) {
593 $sql[] = $xmls->dict->CreateTableSQL( $this->name, $fldarray, $this->opts );
594 logMsg( end( $sql ),
'Generated CreateTableSQL' );
597 logMsg(
"Upgrading {$this->name} using '{$xmls->upgrade}'" );
598 switch( $xmls->upgrade ) {
601 logMsg(
'Generated ChangeTableSQL (ALTERing table)' );
602 $sql[] = $xmls->dict->ChangeTableSQL( $this->name, $fldarray, $this->opts );
605 logMsg(
'Doing upgrade REPLACE (testing)' );
606 $sql[] = $xmls->dict->DropTableSQL( $this->name );
607 $sql[] = $xmls->dict->CreateTableSQL( $this->name, $fldarray, $this->opts );
615 foreach( $this->indexes as $index ) {
616 $sql[] = $index->create( $xmls );
619 if( isset( $this->data ) ) {
620 $sql[] = $this->data->create( $xmls );
630 if( isset( $this->current_field ) ) {
632 logMsg(
"Dropping field '{$this->current_field}' from table '{$this->name}'" );
637 logMsg(
"Dropping table '{$this->name}'" );
639 $this->drop_table = TRUE;
689 $this->name = $this->
prefix ($attributes[
'NAME']);
701 $this->currentElement = strtoupper( $tag );
703 switch( $this->currentElement ) {
728 switch( $this->currentElement ) {
744 $this->currentElement =
'';
746 switch( strtoupper( $tag ) ) {
748 xml_set_object( $parser, $this->parent );
773 $this->opts[] = $opt;
791 foreach( $this->columns as $id => $col ) {
792 if( !isset( $this->parent->fields[$id] ) ) {
793 unset( $this->columns[$id] );
797 return $xmls->dict->CreateIndexSQL( $this->name, $this->parent->name, $this->columns, $this->opts );
844 $this->currentElement = strtoupper( $tag );
846 switch( $this->currentElement ) {
848 $this->row = count( $this->data );
866 switch( $this->currentElement ) {
882 $this->currentElement =
'';
884 switch( strtoupper( $tag ) ) {
886 xml_set_object( $parser, $this->parent );
899 if( !isset( $this->row ) || !isset( $this->data[$this->row] ) ) {
904 if( isset( $attributes[
'NAME'] ) ) {
905 $this->current_field = $this->
FieldID( $attributes[
'NAME'] );
907 $this->current_field = count( $this->data[$this->row] );
911 if( !isset( $this->data[$this->row][$this->current_field] ) ) {
912 $this->data[
$this->row][$this->current_field] =
'';
924 if ( isset( $this->data[$this->row][$this->current_field] ) ) {
926 $this->data[
$this->row][$this->current_field] .= $cdata;
937 $table = $xmls->dict->TableName($this->parent->name);
938 $table_field_count = count($this->parent->fields);
939 $tables = $xmls->db->MetaTables();
942 $ukeys = $xmls->db->MetaPrimaryKeys( $table );
943 if( !empty( $this->parent->indexes ) and !empty( $ukeys ) ) {
944 foreach( $this->parent->indexes as $indexObj ) {
945 if( !in_array( $indexObj->name, $ukeys ) ) $ukeys[] = $indexObj->name;
950 foreach( $this->data as
$row ) {
951 $table_fields = $this->parent->fields;
953 $rawfields = array();
955 foreach( $row as $field_id => $field_data ) {
956 if( !array_key_exists( $field_id, $table_fields ) ) {
957 if( is_numeric( $field_id ) ) {
958 $field_id = reset( array_keys( $table_fields ) );
964 $name = $table_fields[$field_id][
'NAME'];
966 switch( $table_fields[$field_id][
'TYPE'] ) {
972 $fields[$name] = intval($field_data);
979 $fields[$name] = $xmls->db->qstr( $field_data );
980 $rawfields[$name] = $field_data;
983 unset($table_fields[$field_id]);
988 if( empty( $fields ) ) {
993 if( count( $fields ) < $table_field_count ) {
994 foreach( $table_fields as $field ) {
995 if( isset( $field[
'OPTS'] ) and ( in_array(
'NOTNULL', $field[
'OPTS'] ) || in_array(
'KEY', $field[
'OPTS'] ) ) && !in_array(
'AUTOINCREMENT', $field[
'OPTS'] ) ) {
1003 if( !in_array( $table,
$tables ) or ( $mode = $xmls->existingData() ) == XMLS_MODE_INSERT ) {
1005 logMsg(
"$table doesn't exist, inserting or mode is INSERT" );
1006 $sql[] =
'INSERT INTO '. $table .
' ('. implode(
',', array_keys( $fields ) ) .
') VALUES ('. implode(
',', $fields ) .
')';
1011 $mfields = array_merge( $fields, $rawfields );
1012 $keyFields = array_intersect( $ukeys, array_keys( $mfields ) );
1014 if( empty( $ukeys ) or count( $keyFields ) == 0 ) {
1016 logMsg(
"Either schema or data has no unique keys, so safe to insert" );
1017 $sql[] =
'INSERT INTO '. $table .
' ('. implode(
',', array_keys( $fields ) ) .
') VALUES ('. implode(
',', $fields ) .
')';
1023 foreach( $ukeys as $key ) {
1024 if( isset( $mfields[$key] ) and $mfields[$key] ) {
1025 if( $where ) $where .=
' AND ';
1026 $where .= $key .
' = ' . $xmls->db->qstr( $mfields[$key] );
1029 $records = $xmls->db->Execute(
'SELECT * FROM ' . $table .
' WHERE ' . $where );
1030 switch( $records->RecordCount() ) {
1033 logMsg(
"No matching records. Inserting new row with unique data" );
1034 $sql[] = $xmls->db->GetInsertSQL( $records, $mfields );
1038 logMsg(
"One matching record..." );
1039 if( $mode == XMLS_MODE_UPDATE ) {
1040 logMsg(
"...Updating existing row from unique data" );
1041 $sql[] = $xmls->db->GetUpdateSQL( $records, $mfields );
1046 logMsg(
"More than one matching record. Ignoring row." );
1091 if( isset( $attributes[
'KEY'] ) ) {
1092 $this->prefixKey = $attributes[
'KEY'];
1095 $prefixMethod = isset( $attributes[
'PREFIXMETHOD'] ) ? strtoupper( trim( $attributes[
'PREFIXMETHOD'] ) ) :
'';
1100 $this->prefixMethod =
'AUTO';
1103 $this->prefixMethod =
'MANUAL';
1106 $this->prefixMethod =
'NONE';
1118 $this->currentElement = strtoupper( $tag );
1120 switch( $this->currentElement ) {
1125 if( !isset( $attributes[
'PLATFORM'] ) OR $this->
supportedPlatform( $attributes[
'PLATFORM'] ) ) {
1140 switch( $this->currentElement ) {
1156 $this->currentElement =
'';
1158 switch( strtoupper( $tag ) ) {
1164 $this->parent->addSQL( $this->
create( $this->parent ) );
1165 xml_set_object( $parser, $this->parent );
1190 unset( $this->query );
1202 if( !isset( $this->query ) OR empty( $sql ) ) {
1206 $this->query .= $sql;
1217 if( !isset( $this->query ) ) {
1221 $this->queries[] = $return = trim($this->query);
1223 unset( $this->query );
1235 foreach( $this->queries as $id =>
$query ) {
1236 switch( $this->prefixMethod ) {
1242 $query = $this->
prefixQuery(
'/^\s*((?is)INSERT\s+(INTO\s+)?)((\w+\s*,?\s*)+)(\s.*$)/',
$query, $xmls->objectPrefix );
1243 $query = $this->
prefixQuery(
'/^\s*((?is)UPDATE\s+(FROM\s+)?)((\w+\s*,?\s*)+)(\s.*$)/',
$query, $xmls->objectPrefix );
1244 $query = $this->
prefixQuery(
'/^\s*((?is)DELETE\s+(FROM\s+)?)((\w+\s*,?\s*)+)(\s.*$)/',
$query, $xmls->objectPrefix );
1247 #$data = preg_replace( '/(?ias)(^\s*SELECT\s+.*\s+FROM)\s+(\W\s*,?\s*)+((?i)\s+WHERE.*$)/', "\1 $prefix\2 \3", $data );
1252 if( isset( $this->prefixKey ) AND( $this->prefixKey !==
'' ) ) {
1254 $query = str_replace( $this->prefixKey, $xmls->objectPrefix,
$query );
1257 $query = str_replace( XMLS_PREFIX , $xmls->objectPrefix,
$query );
1261 $this->queries[$id] = trim(
$query );
1277 if( !isset( $prefix ) ) {
1281 if( preg_match( $regex,
$query, $match ) ) {
1282 $preamble = $match[1];
1283 $postamble = $match[5];
1284 $objectList = explode(
',', $match[3] );
1289 foreach( $objectList as $object ) {
1290 if( $prefixedList !==
'' ) {
1291 $prefixedList .=
', ';
1294 $prefixedList .= $prefix . trim( $object );
1297 $query = $preamble .
' ' . $prefixedList .
' ' . $postamble;
1371 var
$versionRegex =
'/<schema.*?( version="([^"]*)")?.*?>/';
1410 $this->mgq = get_magic_quotes_runtime();
1411 #set_magic_quotes_runtime(0);
1412 ini_set(
"magic_quotes_runtime", 0);
1415 $this->debug = $this->db->debug;
1416 $this->dict = NewDataDictionary( $this->db );
1417 $this->sqlArray = array();
1418 $this->schemaVersion = XMLS_SCHEMA_VERSION;
1419 $this->executeInline( XMLS_EXECUTE_INLINE );
1420 $this->continueOnError( XMLS_CONTINUE_ON_ERROR );
1421 $this->existingData( XMLS_EXISTING_DATA );
1422 $this->setUpgradeMethod();
1442 if( !is_string( $method ) ) {
1446 $method = strtoupper( $method );
1451 $this->upgrade = $method;
1454 $this->upgrade = $method;
1457 $this->upgrade =
'ALTER';
1460 $this->upgrade =
'NONE';
1464 $this->upgrade = XMLS_DEFAULT_UPGRADE_METHOD;
1490 if( is_int( $mode ) ) {
1492 case XMLS_MODE_UPDATE:
1493 $mode = XMLS_MODE_UPDATE;
1495 case XMLS_MODE_IGNORE:
1496 $mode = XMLS_MODE_IGNORE;
1498 case XMLS_MODE_INSERT:
1499 $mode = XMLS_MODE_INSERT;
1502 $mode = XMLS_EXISTING_DATA;
1505 $this->existingData = $mode;
1525 if( is_bool( $mode ) ) {
1526 $this->executeInline = $mode;
1546 if( is_bool( $mode ) ) {
1547 $this->continueOnError = $mode;
1593 if( !($fp = fopen( $filename,
'r' )) ) {
1594 logMsg(
'Unable to open file' );
1600 logMsg(
'Invalid Schema Version' );
1604 if( $returnSchema ) {
1606 while( $data = fread( $fp, 4096 ) ) {
1607 $xmlstring .= $data .
"\n";
1617 while( $data = fread( $fp, 4096 ) ) {
1618 if( !xml_parse( $xmlParser, $data, feof( $fp ) ) ) {
1620 "XML error: %s at line %d",
1621 xml_error_string( xml_get_error_code( $xmlParser) ),
1622 xml_get_current_line_number( $xmlParser)
1627 xml_parser_free( $xmlParser );
1644 if( !is_string( $xmlstring ) OR empty( $xmlstring ) ) {
1645 logMsg(
'Empty or Invalid Schema' );
1651 logMsg(
'Invalid Schema Version' );
1655 if( $returnSchema ) {
1663 if( !xml_parse( $xmlParser, $xmlstring, TRUE ) ) {
1665 "XML error: %s at line %d",
1666 xml_error_string( xml_get_error_code( $xmlParser) ),
1667 xml_get_current_line_number( $xmlParser)
1671 xml_parser_free( $xmlParser );
1726 if( !is_bool( $continueOnErr ) ) {
1737 $this->success = $this->dict->ExecuteSQLArray(
$sqlArray, $continueOnErr );
1775 $fp = fopen( $filename,
"w" );
1777 foreach(
$sqlArray as $key => $query ) {
1778 fwrite( $fp, $query .
";\n" );
1792 $xmlParser = xml_parser_create();
1793 xml_set_object( $xmlParser, $this );
1796 xml_set_element_handler( $xmlParser,
'_tag_open',
'_tag_close' );
1797 xml_set_character_data_handler( $xmlParser,
'_tag_cdata' );
1808 switch( strtoupper( $tag ) ) {
1810 if( !isset( $attributes[
'PLATFORM'] ) OR $this->
supportedPlatform( $attributes[
'PLATFORM'] ) ) {
1811 $this->obj =
new dbTable( $this, $attributes );
1812 xml_set_object( $parser, $this->obj );
1816 if( !isset( $attributes[
'PLATFORM'] ) OR $this->
supportedPlatform( $attributes[
'PLATFORM'] ) ) {
1817 $this->obj =
new dbQuerySet( $this, $attributes );
1818 xml_set_object( $parser, $this->obj );
1868 if( !isset ($newVersion) ) {
1872 if( $version == $newVersion ) {
1878 if( is_string(
$result ) AND is_string( $newFile ) AND ( $fp = fopen( $newFile,
'w' ) ) ) {
1917 if( !isset ($newVersion) ) {
1921 if( $version == $newVersion ) {
1925 if( substr(
$result, 0, 3 ) == sprintf(
'%c%c%c', 239, 187, 191 ) ) {
1932 if( is_string(
$result ) AND is_string( $newFile ) AND ( $fp = fopen( $newFile,
'w' ) ) ) {
1943 if( ! function_exists(
'xslt_create' ) ) {
1947 $xsl_file = dirname( __FILE__ ) .
'/xsl/' . $xsl .
'.xsl';
1950 if( !is_readable( $xsl_file ) ) {
1954 switch( $schematype )
1957 if( !is_readable( $schema ) ) {
1965 if( !is_string( $schema ) ) {
1970 $arguments = array (
1976 $xh = xslt_create ();
1979 xslt_set_error_handler ($xh, array (&$this,
'xslt_error_handler'));
1982 $result = xslt_process ($xh,
'arg:/_xml',
'arg:/_xsl', NULL, $arguments);
2000 if( is_array( $fields ) ) {
2002 'Message Type' => ucfirst( $fields[
'msgtype'] ),
2003 'Message Code' => $fields[
'code'],
2004 'Message' => $fields[
'msg'],
2005 'Error Number' => $errno,
2009 switch( $fields[
'URI'] ) {
2011 $msg[
'Input'] =
'XML';
2014 $msg[
'Input'] =
'XSL';
2017 $msg[
'Input'] = $fields[
'URI'];
2020 $msg[
'Line'] = $fields[
'line'];
2023 'Message Type' =>
'Error',
2024 'Error Number' => $errno,
2026 'Fields' => var_export( $fields, TRUE )
2030 $error_details = $msg[
'Message Type'] .
' in XSLT Transformation' .
"\n"
2033 foreach( $msg as $label => $details ) {
2034 $error_details .=
'<tr><td><b>' . $label .
': </b></td><td>' . htmlentities( $details ) .
'</td></tr>' .
"\n";
2037 $error_details .=
'</table>';
2053 if( !($fp = fopen( $filename,
'r' )) ) {
2059 while( $data = fread( $fp, 4096 ) ) {
2060 if( preg_match( $this->versionRegex, $data, $matches ) ) {
2061 return !empty( $matches[2] ) ? $matches[2] : XMLS_DEFAULT_SCHEMA_VERSION;
2078 if( !is_string( $xmlstring ) OR empty( $xmlstring ) ) {
2082 if( preg_match( $this->versionRegex, $xmlstring, $matches ) ) {
2083 return !empty( $matches[2] ) ? $matches[2] : XMLS_DEFAULT_SCHEMA_VERSION;
2102 function ExtractSchema( $data = FALSE, $indent =
' ', $prefix =
'' , $stripprefix=
false) {
2103 $old_mode = $this->db->SetFetchMode( ADODB_FETCH_NUM );
2105 $schema =
'<?xml version="1.0"?>' .
"\n"
2106 .
'<schema version="' . $this->schemaVersion .
'">' .
"\n";
2108 if( is_array(
$tables = $this->db->MetaTables(
'TABLES' , ($prefix) ? $prefix.
'%' :
'') ) ) {
2109 foreach(
$tables as $table ) {
2110 if ($stripprefix) $table = str_replace(str_replace(
'\\_',
'_', $pfx ),
'', $table);
2111 $schema .= $indent .
'<table name="' . htmlentities( $table ) .
'">' .
"\n";
2114 $rs = $this->db->Execute(
'SELECT * FROM ' . $table .
' WHERE -1' );
2115 $fields = $this->db->MetaColumns( $table );
2116 $indexes = $this->db->MetaIndexes( $table );
2118 if( is_array( $fields ) ) {
2119 foreach( $fields as $details ) {
2123 if( isset($details->max_length) && $details->max_length > 0 ) {
2124 $extra .=
' size="' . $details->max_length .
'"';
2127 if( isset($details->primary_key) && $details->primary_key ) {
2128 $content[] =
'<KEY/>';
2129 } elseif( isset($details->not_null) && $details->not_null ) {
2130 $content[] =
'<NOTNULL/>';
2133 if( isset($details->has_default) && $details->has_default ) {
2134 $content[] =
'<DEFAULT value="' . htmlentities( $details->default_value ) .
'"/>';
2137 if( isset($details->auto_increment) && $details->auto_increment ) {
2138 $content[] =
'<AUTOINCREMENT/>';
2141 if( isset($details->unsigned) && $details->unsigned ) {
2142 $content[] =
'<UNSIGNED/>';
2147 $details->primary_key = 0;
2148 $type = $rs->MetaType( $details );
2150 $schema .= str_repeat( $indent, 2 ) .
'<field name="' . htmlentities( $details->name ) .
'" type="' . $type .
'"' . $extra;
2152 if( !empty( $content ) ) {
2153 $schema .=
">\n" . str_repeat( $indent, 3 )
2154 . implode(
"\n" . str_repeat( $indent, 3 ), $content ) .
"\n"
2155 . str_repeat( $indent, 2 ) .
'</field>' .
"\n";
2162 if( is_array( $indexes ) ) {
2163 foreach( $indexes as $index => $details ) {
2164 $schema .= str_repeat( $indent, 2 ) .
'<index name="' . $index .
'">' .
"\n";
2166 if( $details[
'unique'] ) {
2167 $schema .= str_repeat( $indent, 3 ) .
'<UNIQUE/>' .
"\n";
2170 foreach( $details[
'columns'] as $column ) {
2171 $schema .= str_repeat( $indent, 3 ) .
'<col>' . htmlentities( $column ) .
'</col>' .
"\n";
2174 $schema .= str_repeat( $indent, 2 ) .
'</index>' .
"\n";
2179 $rs = $this->db->Execute(
'SELECT * FROM ' . $table );
2181 if( is_object( $rs ) && !$rs->EOF ) {
2182 $schema .= str_repeat( $indent, 2 ) .
"<data>\n";
2184 while( $row = $rs->FetchRow() ) {
2185 foreach( $row as $key => $val ) {
2186 if ( $val != htmlentities( $val ) ) {
2187 $row[$key] =
'<![CDATA[' . $val .
']]>';
2191 $schema .= str_repeat( $indent, 3 ) .
'<row><f>' . implode(
'</f><f>', $row ) .
"</f></row>\n";
2194 $schema .= str_repeat( $indent, 2 ) .
"</data>\n";
2198 $schema .= $indent .
"</table>\n";
2202 $this->db->SetFetchMode( $old_mode );
2204 $schema .=
'</schema>';
2221 case empty( $prefix ):
2222 logMsg(
'Cleared prefix' );
2223 $this->objectPrefix =
'';
2226 case strlen( $prefix ) > XMLS_PREFIX_MAXLEN:
2228 case !preg_match(
'/^[a-z][a-z0-9_]+$/i', $prefix ):
2229 logMsg(
'Invalid prefix: ' . $prefix );
2233 if( $underscore AND substr( $prefix, -1 ) !=
'_' ) {
2238 logMsg(
'Set prefix: ' . $prefix );
2239 $this->objectPrefix = $prefix;
2253 if( !empty( $this->objectPrefix ) ) {
2256 return preg_replace(
'/^(`?)(.+)$/',
'$1' . $this->objectPrefix .
'$2', $name );
2272 if( !empty( $platform ) ) {
2273 $regex =
'/(^|\|)' . $this->db->databaseType .
'(\||$)/i';
2275 if( preg_match(
'/^- /', $platform ) ) {
2276 if (preg_match ( $regex, substr( $platform, 2 ) ) ) {
2277 logMsg(
'Platform ' . $platform .
' is NOT supported' );
2281 if( !preg_match ( $regex, $platform ) ) {
2282 logMsg(
'Platform ' . $platform .
' is NOT supported' );
2288 logMsg(
'Platform ' . $platform .
' is supported' );
2298 $this->sqlArray = array();
2310 if( is_array( $sql ) ) {
2311 foreach( $sql as $line ) {
2318 if( is_string( $sql ) ) {
2319 $this->sqlArray[] = $sql;
2323 $saved = $this->db->debug;
2325 $ok = $this->db->Execute( $sql );
2326 $this->db->debug = $saved;
2329 if( $this->debug ) {
2330 ADOConnection::outp( $this->db->ErrorMsg() );
2360 switch( strtolower( $format ) ) {
2365 return !empty(
$sqlArray ) ? nl2br( htmlentities( implode(
";\n\n",
$sqlArray ) .
';' ) ) :
'';
2378 ini_set(
"magic_quotes_runtime", $this->mgq );
2379 #set_magic_quotes_runtime( $this->mgq );
2389 function logMsg( $msg, $title = NULL, $force = FALSE ) {
2390 if( XMLS_DEBUG or $force ) {
2393 if( isset( $title ) ) {
2394 echo
'<h3>' . htmlentities( $title ) .
'</h3>';
2397 if( @is_object( $this ) ) {
2398 echo
'[' . get_class( $this ) .
'] ';