cvs: pear /XML_sql2xml package.xml sql2xml.php sql2xml_ext.php

From: Date: Thu, 16 Aug 2001 17:12:44 +0000
Subject: cvs: pear /XML_sql2xml package.xml sql2xml.php sql2xml_ext.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-557@lists.php.net to get a copy of this message
chregu Thu Aug 16 13:12:44 2001 EDT Modified files: /pear/XML_sql2xml package.xml sql2xml.php sql2xml_ext.php Log: for sql2xml.php - sql selects are recognized with capitals as well - some stuff of the warning-get-rid-of from before, did not always work - if there was a < in the database it gave an xml-error, now "< " is "escaped" (but not "<[a-z.etc.]", it's assumed it's a tag) for sql2xml_ext.php - print_empty_ids is now true by default - added new useroption "TableNameForRowTags" - user_option selected_id can take the arguments first and all

Index: pear/XML_sql2xml/package.xml diff -u pear/XML_sql2xml/package.xml:1.3 pear/XML_sql2xml/package.xml:1.4 --- pear/XML_sql2xml/package.xml:1.3 Thu Aug 16 11:01:37 2001 +++ pear/XML_sql2xml/package.xml Thu Aug 16 13:12:44 2001 @@ -18,6 +18,12 @@ - works with 4.0.6 and below - setOption can delete values set before. - Added possibility of other input encoding schemes than iso-8859-1 + - print_empty_ids is true by default + - added new useroption "TableNameForRowTags" + - user_option selected_id can take the arguments first and all + BugFixes + - sql selects are recognized with capitals as well + - if there was a < in the database it gave an xml-error, now "< " is "escaped" </Notes> </Release> <FileList> Index: pear/XML_sql2xml/sql2xml.php diff -u pear/XML_sql2xml/sql2xml.php:1.3 pear/XML_sql2xml/sql2xml.php:1.4 --- pear/XML_sql2xml/sql2xml.php:1.3 Thu Aug 16 11:01:37 2001 +++ pear/XML_sql2xml/sql2xml.php Thu Aug 16 13:12:44 2001 @@ -15,7 +15,7 @@ // | Authors: Christian Stocker <chregu@phant.ch> | // +----------------------------------------------------------------------+ // -// $Id: sql2xml.php,v 1.3 2001/08/16 15:01:37 chregu Exp $ +// $Id: sql2xml.php,v 1.4 2001/08/16 17:12:44 chregu Exp $ /** * This class takes a PEAR::DB-Result Object, a sql-query-string or an array @@ -31,6 +31,8 @@ * include_once("XML/sql2xml.php"); * $db = DB::connect("mysql://root@localhost/xmltest"); * $sql2xml = new xml_sql2xml(); +* //the next one is only needed, if you need others than the default +* $sql2xml->setEncoding("ISO-8859-1","UTF-8"); * $result = $db->query("select * from bands"); * $xmlstring = $sql2xml->getXML($result); * @@ -46,7 +48,7 @@ * http://php.chregu.tv/sql2xml * * @author Christian Stocker <chregu@nomad.ch> -* @version $Id: sql2xml.php,v 1.3 2001/08/16 15:01:37 chregu Exp $ +* @version $Id: sql2xml.php,v 1.4 2001/08/16 17:12:44 chregu Exp $ * @package XML */ class XML_sql2xml { @@ -235,12 +237,13 @@ */ function add ($resultset) { + // if string, then it's a query, a xml-file or a xml-string... if (is_string($resultset)) { if (preg_match("/\.xml$/",$resultset)) { $this->AddXmlFile($resultset); } - elseif (preg_match("/.*select.*from.*/" , $resultset)) { + elseif (preg_match("/.*select.*from.*/i" , $resultset)) { $this->AddSql($resultset); } else { @@ -457,19 +460,21 @@ $parent['root'] = $this->insertNewResult(&$tableInfo); //initialize $resold to get rid of warning messages; - $resold[0] = Null; + $resold[0] = "ThisValueIsImpossibleForTheFirstFieldInTheFirstRow"; while ($FirstFetchDone == True || $res = $result->FetchRow($fetchmode)) { + //FirstFetchDone is only for emulating tableInfo, as long as not all dbs support tableInfo. can go away later $FirstFetchDone = False; while (list($key, $val) = each($res)) { + if ($resold[$tableInfo["parent_key"][$tableInfo[$key]["table"]]] != $res[$tableInfo["parent_key"][$tableInfo[$key]["table"]]] || !$this->nested) { if ($tableInfo["parent_key"][$tableInfo[$key]["table"]] == $key ) - { + { if ($this->nested || $key == 0) { @@ -658,7 +663,8 @@ // here come some helper functions... /** - * make utf8 out of the input data and escape & with &amp; + * make utf8 out of the input data and escape & with &amp; and "< " with "&lt; " + * (we assume that when there's no space after < it's a tag, which we need in the xml) * I'm not sure, if this is the standard way, but it works for me. * * @param string text to be utfed. @@ -666,10 +672,10 @@ */ function xml_encode ($text) { - if (function_exists("iconv") && isset($this->encoding_from)) + if (function_exists("iconv") && isset($this->encoding_from) && isset($this->encoding_to)) { ini_set("track_errors",1); - $text = iconv($this->encoding_from,$this->encoding_to,ereg_replace("&","&amp;",$text)); + $text = iconv($this->encoding_from,$this->encoding_to,ereg_replace("&","&amp;",ereg_replace("< ","&lt; ",$text))); if (! isset($text) ) { Index: pear/XML_sql2xml/sql2xml_ext.php diff -u pear/XML_sql2xml/sql2xml_ext.php:1.3 pear/XML_sql2xml/sql2xml_ext.php:1.4 --- pear/XML_sql2xml/sql2xml_ext.php:1.3 Thu Aug 16 11:01:37 2001 +++ pear/XML_sql2xml/sql2xml_ext.php Thu Aug 16 13:12:44 2001 @@ -15,7 +15,7 @@ // | Authors: Christian Stocker <chregu@phant.ch> | // +----------------------------------------------------------------------+ // -// $Id: sql2xml_ext.php,v 1.3 2001/08/16 15:01:37 chregu Exp $ +// $Id: sql2xml_ext.php,v 1.4 2001/08/16 17:12:44 chregu Exp $ require_once ("XML/sql2xml.php"); @@ -38,7 +38,7 @@ * for the time being * * @author Christian Stocker <chregu@nomad.ch> - * @version $Id: sql2xml_ext.php,v 1.3 2001/08/16 15:01:37 chregu Exp $ + * @version $Id: sql2xml_ext.php,v 1.4 2001/08/16 17:12:44 chregu Exp $ */ class XML_sql2xml_ext extends XML_sql2xml { @@ -51,10 +51,11 @@ $user_options = array ( 'xml_seperator' =>"_", 'element_id' => "ID", - 'print_empty_ids' => False, + 'print_empty_ids' => True, 'selected_id' => array(), 'field_translate' => array(), - 'attributes' => array() + 'attributes' => array(), + 'TableNameForRowTags' => True ); $this->setOptions(array("user_options"=>$user_options)); @@ -63,15 +64,22 @@ function insertNewRow ($parent_row, $res, $key, &$tableInfo) { - if (!$tableInfo[$key]["table"]) { + + if (!$tableInfo[$key]["table"] ) { $tableInfo[$key]["table"] = $this->tagNameResult; } if ($this->user_options['element_id'] && !$res[$tableInfo["id"][$tableInfo[$key]["table"]]] && !$this->user_options['print_empty_ids']) { return Null; } - - $new_row= $parent_row->new_child($tableInfo[$key]["table"],Null); + if ( !$this->user_options['TableNameForRowTags']) + { + $new_row= $parent_row->new_child($this->tagNameRow,Null); + } + else + { + $new_row= $parent_row->new_child($tableInfo[$key]["table"],Null); + } /* make an unique ID attribute in the row element with tablename.id if there's an id otherwise just make an unique id with the php-function, just that there's a unique id for this row. CAUTION: This ID changes every time ;) (if no id from db-table) @@ -85,10 +93,13 @@ if ($res[$tableInfo["id"][$tableInfo[$key]["table"]]] == $this->user_options['selected_id'] || $tableInfo[$key]["table"].$res[$tableInfo["id"][$tableInfo[$key]["table"]]] == $this->user_options['selected_id'] - || (is_array($this->user_options['selected_id']) && in_array($tableInfo[$key]["table"].$res[$tableInfo["id"][$tableInfo[$key]["table"]]],$this->user_options['selected_id']))) - + || (is_array($this->user_options['selected_id']) && in_array($tableInfo[$key]["table"].$res[$tableInfo["id"][$tableInfo[$key]["table"]]],$this->user_options['selected_id'])) + || $this->user_options['selected_id'] == "all" + || ($this->user_options['selected_id'] == "first") && !isset($this->table_selected[$tableInfo[$key]["table"]]) + ) { $this->SetAttribute($new_row,"selected", "selected"); + $this->table_selected[$tableInfo[$key]["table"]] = True; } $this->SetAttribute($new_row,"ID", utf8_encode($tableInfo[$key]["table"] . $res[$tableInfo["id"][$tableInfo[$key]["table"]]])); } @@ -117,6 +128,7 @@ else $xmlroot= $this->xmldoc->add_root($result_root); $this->SetAttribute($xmlroot,"type","resultset"); + return $xmlroot; }
« previous php.pear.cvs (#557) next »