@@ -273,6 +273,12 @@ |
||
| 273 | 273 | |
| 274 | 274 | //------------------------------------------------------ |
| 275 | 275 | // override this to control overall layout and formating |
| 276 | + |
|
| 277 | + /** |
|
| 278 | + * @param string $header |
|
| 279 | + * @param string $grid |
|
| 280 | + * @param string $footer |
|
| 281 | + */ |
|
| 276 | 282 | function RenderLayout($header,$grid,$footer,$attributes='border=1 bgcolor=beige') |
| 277 | 283 | { |
| 278 | 284 | echo "<table ".$attributes."><tr><td>", |
@@ -28,8 +28,8 @@ discard block |
||
| 28 | 28 | var $rs; // recordset generated |
| 29 | 29 | var $curr_page; // current page number before Render() called, calculated in constructor |
| 30 | 30 | var $rows; // number of rows per page |
| 31 | - var $linksPerPage=10; // number of links per page in navigation bar |
|
| 32 | - var $showPageLinks; |
|
| 31 | + var $linksPerPage=10; // number of links per page in navigation bar |
|
| 32 | + var $showPageLinks; |
|
| 33 | 33 | |
| 34 | 34 | var $gridAttributes = 'width=100% border=1 bgcolor=white'; |
| 35 | 35 | |
@@ -130,40 +130,40 @@ discard block |
||
| 130 | 130 | |
| 131 | 131 | //--------------------------------------------------- |
| 132 | 132 | // original code by "Pablo Costa" <[email protected]> |
| 133 | - function render_pagelinks() |
|
| 134 | - { |
|
| 135 | - global $PHP_SELF; |
|
| 136 | - $pages = $this->rs->LastPageNo(); |
|
| 137 | - $linksperpage = $this->linksPerPage ? $this->linksPerPage : $pages; |
|
| 138 | - for($i=1; $i <= $pages; $i+=$linksperpage) |
|
| 139 | - { |
|
| 140 | - if($this->rs->AbsolutePage() >= $i) |
|
| 141 | - { |
|
| 142 | - $start = $i; |
|
| 143 | - } |
|
| 144 | - } |
|
| 133 | + function render_pagelinks() |
|
| 134 | + { |
|
| 135 | + global $PHP_SELF; |
|
| 136 | + $pages = $this->rs->LastPageNo(); |
|
| 137 | + $linksperpage = $this->linksPerPage ? $this->linksPerPage : $pages; |
|
| 138 | + for($i=1; $i <= $pages; $i+=$linksperpage) |
|
| 139 | + { |
|
| 140 | + if($this->rs->AbsolutePage() >= $i) |
|
| 141 | + { |
|
| 142 | + $start = $i; |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | 145 | $numbers = ''; |
| 146 | - $end = $start+$linksperpage-1; |
|
| 146 | + $end = $start+$linksperpage-1; |
|
| 147 | 147 | $link = $this->id . "_next_page"; |
| 148 | - if($end > $pages) $end = $pages; |
|
| 148 | + if($end > $pages) $end = $pages; |
|
| 149 | 149 | |
| 150 | 150 | |
| 151 | 151 | if ($this->startLinks && $start > 1) { |
| 152 | 152 | $pos = $start - 1; |
| 153 | 153 | $numbers .= "<a href=$PHP_SELF?$link=$pos>$this->startLinks</a> "; |
| 154 | - } |
|
| 154 | + } |
|
| 155 | 155 | |
| 156 | 156 | for($i=$start; $i <= $end; $i++) { |
| 157 | - if ($this->rs->AbsolutePage() == $i) |
|
| 158 | - $numbers .= "<font color=$this->linkSelectedColor><b>$i</b></font> "; |
|
| 159 | - else |
|
| 160 | - $numbers .= "<a href=$PHP_SELF?$link=$i>$i</a> "; |
|
| 157 | + if ($this->rs->AbsolutePage() == $i) |
|
| 158 | + $numbers .= "<font color=$this->linkSelectedColor><b>$i</b></font> "; |
|
| 159 | + else |
|
| 160 | + $numbers .= "<a href=$PHP_SELF?$link=$i>$i</a> "; |
|
| 161 | 161 | |
| 162 | - } |
|
| 162 | + } |
|
| 163 | 163 | if ($this->moreLinks && $end < $pages) |
| 164 | 164 | $numbers .= "<a href=$PHP_SELF?$link=$i>$this->moreLinks</a> "; |
| 165 | - print $numbers . ' '; |
|
| 166 | - } |
|
| 165 | + print $numbers . ' '; |
|
| 166 | + } |
|
| 167 | 167 | // Link to previous page |
| 168 | 168 | function render_prev($anchor=true) |
| 169 | 169 | { |
@@ -208,9 +208,9 @@ discard block |
||
| 208 | 208 | $this->Render_First(false); |
| 209 | 209 | $this->Render_Prev(false); |
| 210 | 210 | } |
| 211 | - if ($this->showPageLinks){ |
|
| 212 | - $this->Render_PageLinks(); |
|
| 213 | - } |
|
| 211 | + if ($this->showPageLinks){ |
|
| 212 | + $this->Render_PageLinks(); |
|
| 213 | + } |
|
| 214 | 214 | if (!$this->rs->AtLastPage()) { |
| 215 | 215 | $this->Render_Next(); |
| 216 | 216 | $this->Render_Last(); |
@@ -22,13 +22,13 @@ discard block |
||
| 22 | 22 | |
| 23 | 23 | */ |
| 24 | 24 | class ADODB_Pager { |
| 25 | - var $id; // unique id for pager (defaults to 'adodb') |
|
| 26 | - var $db; // ADODB connection object |
|
| 27 | - var $sql; // sql used |
|
| 28 | - var $rs; // recordset generated |
|
| 29 | - var $curr_page; // current page number before Render() called, calculated in constructor |
|
| 30 | - var $rows; // number of rows per page |
|
| 31 | - var $linksPerPage=10; // number of links per page in navigation bar |
|
| 25 | + var $id; // unique id for pager (defaults to 'adodb') |
|
| 26 | + var $db; // ADODB connection object |
|
| 27 | + var $sql; // sql used |
|
| 28 | + var $rs; // recordset generated |
|
| 29 | + var $curr_page; // current page number before Render() called, calculated in constructor |
|
| 30 | + var $rows; // number of rows per page |
|
| 31 | + var $linksPerPage = 10; // number of links per page in navigation bar |
|
| 32 | 32 | var $showPageLinks; |
| 33 | 33 | |
| 34 | 34 | var $gridAttributes = 'width=100% border=1 bgcolor=white'; |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | var $htmlSpecialChars = true; |
| 45 | 45 | var $page = 'Page'; |
| 46 | 46 | var $linkSelectedColor = 'red'; |
| 47 | - var $cache = 0; #secs to cache with CachePageExecute() |
|
| 47 | + var $cache = 0; #secs to cache with CachePageExecute() |
|
| 48 | 48 | |
| 49 | 49 | //---------------------------------------------- |
| 50 | 50 | // constructor |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | // if you have multiple on 1 page. |
| 56 | 56 | // $id should be only be [a-z0-9]* |
| 57 | 57 | // |
| 58 | - function ADODB_Pager(&$db,$sql,$id = 'adodb', $showPageLinks = false) |
|
| 58 | + function ADODB_Pager(&$db, $sql, $id = 'adodb', $showPageLinks = false) |
|
| 59 | 59 | { |
| 60 | 60 | global $PHP_SELF; |
| 61 | 61 | |
@@ -80,12 +80,12 @@ discard block |
||
| 80 | 80 | |
| 81 | 81 | //--------------------------- |
| 82 | 82 | // Display link to first page |
| 83 | - function Render_First($anchor=true) |
|
| 83 | + function Render_First($anchor = true) |
|
| 84 | 84 | { |
| 85 | 85 | global $PHP_SELF; |
| 86 | 86 | if ($anchor) { |
| 87 | 87 | ?> |
| 88 | - <a href="<?php echo $PHP_SELF,'?',$this->id;?>_next_page=1"><?php echo $this->first;?></a> |
|
| 88 | + <a href="<?php echo $PHP_SELF, '?', $this->id; ?>_next_page=1"><?php echo $this->first; ?></a> |
|
| 89 | 89 | <?php |
| 90 | 90 | } else { |
| 91 | 91 | print "$this->first "; |
@@ -94,13 +94,13 @@ discard block |
||
| 94 | 94 | |
| 95 | 95 | //-------------------------- |
| 96 | 96 | // Display link to next page |
| 97 | - function render_next($anchor=true) |
|
| 97 | + function render_next($anchor = true) |
|
| 98 | 98 | { |
| 99 | 99 | global $PHP_SELF; |
| 100 | 100 | |
| 101 | 101 | if ($anchor) { |
| 102 | 102 | ?> |
| 103 | - <a href="<?php echo $PHP_SELF,'?',$this->id,'_next_page=',$this->rs->AbsolutePage() + 1 ?>"><?php echo $this->next;?></a> |
|
| 103 | + <a href="<?php echo $PHP_SELF, '?', $this->id, '_next_page=', $this->rs->AbsolutePage() + 1 ?>"><?php echo $this->next; ?></a> |
|
| 104 | 104 | <?php |
| 105 | 105 | } else { |
| 106 | 106 | print "$this->next "; |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | // for better performance with large recordsets, you can set |
| 114 | 114 | // $this->db->pageExecuteCountRows = false, which disables |
| 115 | 115 | // last page counting. |
| 116 | - function render_last($anchor=true) |
|
| 116 | + function render_last($anchor = true) |
|
| 117 | 117 | { |
| 118 | 118 | global $PHP_SELF; |
| 119 | 119 | |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | |
| 122 | 122 | if ($anchor) { |
| 123 | 123 | ?> |
| 124 | - <a href="<?php echo $PHP_SELF,'?',$this->id,'_next_page=',$this->rs->LastPageNo() ?>"><?php echo $this->last;?></a> |
|
| 124 | + <a href="<?php echo $PHP_SELF, '?', $this->id, '_next_page=', $this->rs->LastPageNo() ?>"><?php echo $this->last; ?></a> |
|
| 125 | 125 | <?php |
| 126 | 126 | } else { |
| 127 | 127 | print "$this->last "; |
@@ -135,17 +135,17 @@ discard block |
||
| 135 | 135 | global $PHP_SELF; |
| 136 | 136 | $pages = $this->rs->LastPageNo(); |
| 137 | 137 | $linksperpage = $this->linksPerPage ? $this->linksPerPage : $pages; |
| 138 | - for($i=1; $i <= $pages; $i+=$linksperpage) |
|
| 138 | + for ($i = 1; $i <= $pages; $i += $linksperpage) |
|
| 139 | 139 | { |
| 140 | - if($this->rs->AbsolutePage() >= $i) |
|
| 140 | + if ($this->rs->AbsolutePage() >= $i) |
|
| 141 | 141 | { |
| 142 | 142 | $start = $i; |
| 143 | 143 | } |
| 144 | 144 | } |
| 145 | 145 | $numbers = ''; |
| 146 | - $end = $start+$linksperpage-1; |
|
| 147 | - $link = $this->id . "_next_page"; |
|
| 148 | - if($end > $pages) $end = $pages; |
|
| 146 | + $end = $start + $linksperpage - 1; |
|
| 147 | + $link = $this->id."_next_page"; |
|
| 148 | + if ($end > $pages) $end = $pages; |
|
| 149 | 149 | |
| 150 | 150 | |
| 151 | 151 | if ($this->startLinks && $start > 1) { |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | $numbers .= "<a href=$PHP_SELF?$link=$pos>$this->startLinks</a> "; |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | - for($i=$start; $i <= $end; $i++) { |
|
| 156 | + for ($i = $start; $i <= $end; $i++) { |
|
| 157 | 157 | if ($this->rs->AbsolutePage() == $i) |
| 158 | 158 | $numbers .= "<font color=$this->linkSelectedColor><b>$i</b></font> "; |
| 159 | 159 | else |
@@ -162,15 +162,15 @@ discard block |
||
| 162 | 162 | } |
| 163 | 163 | if ($this->moreLinks && $end < $pages) |
| 164 | 164 | $numbers .= "<a href=$PHP_SELF?$link=$i>$this->moreLinks</a> "; |
| 165 | - print $numbers . ' '; |
|
| 165 | + print $numbers.' '; |
|
| 166 | 166 | } |
| 167 | 167 | // Link to previous page |
| 168 | - function render_prev($anchor=true) |
|
| 168 | + function render_prev($anchor = true) |
|
| 169 | 169 | { |
| 170 | 170 | global $PHP_SELF; |
| 171 | 171 | if ($anchor) { |
| 172 | 172 | ?> |
| 173 | - <a href="<?php echo $PHP_SELF,'?',$this->id,'_next_page=',$this->rs->AbsolutePage() - 1 ?>"><?php echo $this->prev;?></a> |
|
| 173 | + <a href="<?php echo $PHP_SELF, '?', $this->id, '_next_page=', $this->rs->AbsolutePage() - 1 ?>"><?php echo $this->prev; ?></a> |
|
| 174 | 174 | <?php |
| 175 | 175 | } else { |
| 176 | 176 | print "$this->prev "; |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | include_once(ADODB_DIR.'/tohtml.inc.php'); |
| 189 | 189 | ob_start(); |
| 190 | 190 | $gSQLBlockRows = $this->rows; |
| 191 | - rs2html($this->rs,$this->gridAttributes,$this->gridHeader,$this->htmlSpecialChars); |
|
| 191 | + rs2html($this->rs, $this->gridAttributes, $this->gridHeader, $this->htmlSpecialChars); |
|
| 192 | 192 | $s = ob_get_contents(); |
| 193 | 193 | ob_end_clean(); |
| 194 | 194 | return $s; |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | $this->Render_First(false); |
| 209 | 209 | $this->Render_Prev(false); |
| 210 | 210 | } |
| 211 | - if ($this->showPageLinks){ |
|
| 211 | + if ($this->showPageLinks) { |
|
| 212 | 212 | $this->Render_PageLinks(); |
| 213 | 213 | } |
| 214 | 214 | if (!$this->rs->AtLastPage()) { |
@@ -236,7 +236,7 @@ discard block |
||
| 236 | 236 | |
| 237 | 237 | //----------------------------------- |
| 238 | 238 | // Call this class to draw everything. |
| 239 | - function Render($rows=10) |
|
| 239 | + function Render($rows = 10) |
|
| 240 | 240 | { |
| 241 | 241 | global $ADODB_COUNTRECS; |
| 242 | 242 | |
@@ -247,9 +247,9 @@ discard block |
||
| 247 | 247 | $savec = $ADODB_COUNTRECS; |
| 248 | 248 | if ($this->db->pageExecuteCountRows) $ADODB_COUNTRECS = true; |
| 249 | 249 | if ($this->cache) |
| 250 | - $rs = &$this->db->CachePageExecute($this->cache,$this->sql,$rows,$this->curr_page); |
|
| 250 | + $rs = &$this->db->CachePageExecute($this->cache, $this->sql, $rows, $this->curr_page); |
|
| 251 | 251 | else |
| 252 | - $rs = &$this->db->PageExecute($this->sql,$rows,$this->curr_page); |
|
| 252 | + $rs = &$this->db->PageExecute($this->sql, $rows, $this->curr_page); |
|
| 253 | 253 | $ADODB_COUNTRECS = $savec; |
| 254 | 254 | |
| 255 | 255 | $this->rs = &$rs; |
@@ -268,12 +268,12 @@ discard block |
||
| 268 | 268 | $rs->Close(); |
| 269 | 269 | $this->rs = false; |
| 270 | 270 | |
| 271 | - $this->RenderLayout($header,$grid,$footer); |
|
| 271 | + $this->RenderLayout($header, $grid, $footer); |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | //------------------------------------------------------ |
| 275 | 275 | // override this to control overall layout and formating |
| 276 | - function RenderLayout($header,$grid,$footer,$attributes='border=1 bgcolor=beige') |
|
| 276 | + function RenderLayout($header, $grid, $footer, $attributes = 'border=1 bgcolor=beige') |
|
| 277 | 277 | { |
| 278 | 278 | echo "<table ".$attributes."><tr><td>", |
| 279 | 279 | $header, |
@@ -21,7 +21,8 @@ discard block |
||
| 21 | 21 | will be entertained by the author. |
| 22 | 22 | |
| 23 | 23 | */ |
| 24 | -class ADODB_Pager { |
|
| 24 | +class ADODB_Pager |
|
| 25 | +{ |
|
| 25 | 26 | var $id; // unique id for pager (defaults to 'adodb') |
| 26 | 27 | var $db; // ADODB connection object |
| 27 | 28 | var $sql; // sql used |
@@ -60,7 +61,10 @@ discard block |
||
| 60 | 61 | global $PHP_SELF; |
| 61 | 62 | |
| 62 | 63 | $curr_page = $id.'_curr_page'; |
| 63 | - if (empty($PHP_SELF)) $PHP_SELF = $_SERVER['PHP_SELF']; |
|
| 64 | + if (empty($PHP_SELF)) |
|
| 65 | + { |
|
| 66 | + $PHP_SELF = $_SERVER['PHP_SELF']; |
|
| 67 | + } |
|
| 64 | 68 | |
| 65 | 69 | $this->sql = $sql; |
| 66 | 70 | $this->id = $id; |
@@ -69,10 +73,15 @@ discard block |
||
| 69 | 73 | |
| 70 | 74 | $next_page = $id.'_next_page'; |
| 71 | 75 | |
| 72 | - if (isset($_GET[$next_page])) { |
|
| 76 | + if (isset($_GET[$next_page])) |
|
| 77 | + { |
|
| 73 | 78 | $_SESSION[$curr_page] = $_GET[$next_page]; |
| 74 | 79 | } |
| 75 | - if (empty($_SESSION[$curr_page])) $_SESSION[$curr_page] = 1; ## at first page |
|
| 80 | + if (empty($_SESSION[$curr_page])) |
|
| 81 | + { |
|
| 82 | + $_SESSION[$curr_page] = 1; |
|
| 83 | + } |
|
| 84 | + ## at first page |
|
| 76 | 85 | |
| 77 | 86 | $this->curr_page = $_SESSION[$curr_page]; |
| 78 | 87 | |
@@ -83,11 +92,14 @@ discard block |
||
| 83 | 92 | function Render_First($anchor=true) |
| 84 | 93 | { |
| 85 | 94 | global $PHP_SELF; |
| 86 | - if ($anchor) { |
|
| 95 | + if ($anchor) |
|
| 96 | + { |
|
| 87 | 97 | ?> |
| 88 | 98 | <a href="<?php echo $PHP_SELF,'?',$this->id;?>_next_page=1"><?php echo $this->first;?></a> |
| 89 | 99 | <?php |
| 90 | - } else { |
|
| 100 | + } |
|
| 101 | + else |
|
| 102 | + { |
|
| 91 | 103 | print "$this->first "; |
| 92 | 104 | } |
| 93 | 105 | } |
@@ -98,11 +110,14 @@ discard block |
||
| 98 | 110 | { |
| 99 | 111 | global $PHP_SELF; |
| 100 | 112 | |
| 101 | - if ($anchor) { |
|
| 113 | + if ($anchor) |
|
| 114 | + { |
|
| 102 | 115 | ?> |
| 103 | 116 | <a href="<?php echo $PHP_SELF,'?',$this->id,'_next_page=',$this->rs->AbsolutePage() + 1 ?>"><?php echo $this->next;?></a> |
| 104 | 117 | <?php |
| 105 | - } else { |
|
| 118 | + } |
|
| 119 | + else |
|
| 120 | + { |
|
| 106 | 121 | print "$this->next "; |
| 107 | 122 | } |
| 108 | 123 | } |
@@ -117,13 +132,19 @@ discard block |
||
| 117 | 132 | { |
| 118 | 133 | global $PHP_SELF; |
| 119 | 134 | |
| 120 | - if (!$this->db->pageExecuteCountRows) return; |
|
| 135 | + if (!$this->db->pageExecuteCountRows) |
|
| 136 | + { |
|
| 137 | + return; |
|
| 138 | + } |
|
| 121 | 139 | |
| 122 | - if ($anchor) { |
|
| 140 | + if ($anchor) |
|
| 141 | + { |
|
| 123 | 142 | ?> |
| 124 | 143 | <a href="<?php echo $PHP_SELF,'?',$this->id,'_next_page=',$this->rs->LastPageNo() ?>"><?php echo $this->last;?></a> |
| 125 | 144 | <?php |
| 126 | - } else { |
|
| 145 | + } |
|
| 146 | + else |
|
| 147 | + { |
|
| 127 | 148 | print "$this->last "; |
| 128 | 149 | } |
| 129 | 150 | } |
@@ -145,34 +166,47 @@ discard block |
||
| 145 | 166 | $numbers = ''; |
| 146 | 167 | $end = $start+$linksperpage-1; |
| 147 | 168 | $link = $this->id . "_next_page"; |
| 148 | - if($end > $pages) $end = $pages; |
|
| 169 | + if($end > $pages) |
|
| 170 | + { |
|
| 171 | + $end = $pages; |
|
| 172 | + } |
|
| 149 | 173 | |
| 150 | 174 | |
| 151 | - if ($this->startLinks && $start > 1) { |
|
| 175 | + if ($this->startLinks && $start > 1) |
|
| 176 | + { |
|
| 152 | 177 | $pos = $start - 1; |
| 153 | 178 | $numbers .= "<a href=$PHP_SELF?$link=$pos>$this->startLinks</a> "; |
| 154 | 179 | } |
| 155 | 180 | |
| 156 | - for($i=$start; $i <= $end; $i++) { |
|
| 181 | + for($i=$start; $i <= $end; $i++) |
|
| 182 | + { |
|
| 157 | 183 | if ($this->rs->AbsolutePage() == $i) |
| 158 | - $numbers .= "<font color=$this->linkSelectedColor><b>$i</b></font> "; |
|
| 159 | - else |
|
| 160 | - $numbers .= "<a href=$PHP_SELF?$link=$i>$i</a> "; |
|
| 184 | + { |
|
| 185 | + $numbers .= "<font color=$this->linkSelectedColor><b>$i</b></font> "; |
|
| 186 | + } |
|
| 187 | + else { |
|
| 188 | + $numbers .= "<a href=$PHP_SELF?$link=$i>$i</a> "; |
|
| 189 | + } |
|
| 161 | 190 | |
| 162 | 191 | } |
| 163 | - if ($this->moreLinks && $end < $pages) |
|
| 164 | - $numbers .= "<a href=$PHP_SELF?$link=$i>$this->moreLinks</a> "; |
|
| 192 | + if ($this->moreLinks && $end < $pages) |
|
| 193 | + { |
|
| 194 | + $numbers .= "<a href=$PHP_SELF?$link=$i>$this->moreLinks</a> "; |
|
| 195 | + } |
|
| 165 | 196 | print $numbers . ' '; |
| 166 | 197 | } |
| 167 | 198 | // Link to previous page |
| 168 | 199 | function render_prev($anchor=true) |
| 169 | 200 | { |
| 170 | 201 | global $PHP_SELF; |
| 171 | - if ($anchor) { |
|
| 202 | + if ($anchor) |
|
| 203 | + { |
|
| 172 | 204 | ?> |
| 173 | 205 | <a href="<?php echo $PHP_SELF,'?',$this->id,'_next_page=',$this->rs->AbsolutePage() - 1 ?>"><?php echo $this->prev;?></a> |
| 174 | 206 | <?php |
| 175 | - } else { |
|
| 207 | + } |
|
| 208 | + else |
|
| 209 | + { |
|
| 176 | 210 | print "$this->prev "; |
| 177 | 211 | } |
| 178 | 212 | } |
@@ -201,20 +235,27 @@ discard block |
||
| 201 | 235 | function RenderNav() |
| 202 | 236 | { |
| 203 | 237 | ob_start(); |
| 204 | - if (!$this->rs->AtFirstPage()) { |
|
| 238 | + if (!$this->rs->AtFirstPage()) |
|
| 239 | + { |
|
| 205 | 240 | $this->Render_First(); |
| 206 | 241 | $this->Render_Prev(); |
| 207 | - } else { |
|
| 242 | + } |
|
| 243 | + else |
|
| 244 | + { |
|
| 208 | 245 | $this->Render_First(false); |
| 209 | 246 | $this->Render_Prev(false); |
| 210 | 247 | } |
| 211 | - if ($this->showPageLinks){ |
|
| 248 | + if ($this->showPageLinks) |
|
| 249 | + { |
|
| 212 | 250 | $this->Render_PageLinks(); |
| 213 | 251 | } |
| 214 | - if (!$this->rs->AtLastPage()) { |
|
| 252 | + if (!$this->rs->AtLastPage()) |
|
| 253 | + { |
|
| 215 | 254 | $this->Render_Next(); |
| 216 | 255 | $this->Render_Last(); |
| 217 | - } else { |
|
| 256 | + } |
|
| 257 | + else |
|
| 258 | + { |
|
| 218 | 259 | $this->Render_Next(false); |
| 219 | 260 | $this->Render_Last(false); |
| 220 | 261 | } |
@@ -227,10 +268,20 @@ discard block |
||
| 227 | 268 | // This is the footer |
| 228 | 269 | function RenderPageCount() |
| 229 | 270 | { |
| 230 | - if (!$this->db->pageExecuteCountRows) return ''; |
|
| 271 | + if (!$this->db->pageExecuteCountRows) |
|
| 272 | + { |
|
| 273 | + return ''; |
|
| 274 | + } |
|
| 231 | 275 | $lastPage = $this->rs->LastPageNo(); |
| 232 | - if ($lastPage == -1) $lastPage = 1; // check for empty rs. |
|
| 233 | - if ($this->curr_page > $lastPage) $this->curr_page = 1; |
|
| 276 | + if ($lastPage == -1) |
|
| 277 | + { |
|
| 278 | + $lastPage = 1; |
|
| 279 | + } |
|
| 280 | + // check for empty rs. |
|
| 281 | + if ($this->curr_page > $lastPage) |
|
| 282 | + { |
|
| 283 | + $this->curr_page = 1; |
|
| 284 | + } |
|
| 234 | 285 | return "<font size=-1>$this->page ".$this->curr_page."/".$lastPage."</font>"; |
| 235 | 286 | } |
| 236 | 287 | |
@@ -242,26 +293,39 @@ discard block |
||
| 242 | 293 | |
| 243 | 294 | $this->rows = $rows; |
| 244 | 295 | |
| 245 | - if ($this->db->dataProvider == 'informix') $this->db->cursorType = IFX_SCROLL; |
|
| 296 | + if ($this->db->dataProvider == 'informix') |
|
| 297 | + { |
|
| 298 | + $this->db->cursorType = IFX_SCROLL; |
|
| 299 | + } |
|
| 246 | 300 | |
| 247 | 301 | $savec = $ADODB_COUNTRECS; |
| 248 | - if ($this->db->pageExecuteCountRows) $ADODB_COUNTRECS = true; |
|
| 302 | + if ($this->db->pageExecuteCountRows) |
|
| 303 | + { |
|
| 304 | + $ADODB_COUNTRECS = true; |
|
| 305 | + } |
|
| 249 | 306 | if ($this->cache) |
| 250 | - $rs = &$this->db->CachePageExecute($this->cache,$this->sql,$rows,$this->curr_page); |
|
| 251 | - else |
|
| 252 | - $rs = &$this->db->PageExecute($this->sql,$rows,$this->curr_page); |
|
| 307 | + { |
|
| 308 | + $rs = &$this->db->CachePageExecute($this->cache,$this->sql,$rows,$this->curr_page); |
|
| 309 | + } |
|
| 310 | + else { |
|
| 311 | + $rs = &$this->db->PageExecute($this->sql,$rows,$this->curr_page); |
|
| 312 | + } |
|
| 253 | 313 | $ADODB_COUNTRECS = $savec; |
| 254 | 314 | |
| 255 | 315 | $this->rs = &$rs; |
| 256 | - if (!$rs) { |
|
| 316 | + if (!$rs) |
|
| 317 | + { |
|
| 257 | 318 | print "<h3>Query failed: $this->sql</h3>"; |
| 258 | 319 | return; |
| 259 | 320 | } |
| 260 | 321 | |
| 261 | - if (!$rs->EOF && (!$rs->AtFirstPage() || !$rs->AtLastPage())) |
|
| 262 | - $header = $this->RenderNav(); |
|
| 263 | - else |
|
| 264 | - $header = " "; |
|
| 322 | + if (!$rs->EOF && (!$rs->AtFirstPage() || !$rs->AtLastPage())) |
|
| 323 | + { |
|
| 324 | + $header = $this->RenderNav(); |
|
| 325 | + } |
|
| 326 | + else { |
|
| 327 | + $header = " "; |
|
| 328 | + } |
|
| 265 | 329 | |
| 266 | 330 | $grid = $this->RenderGrid(); |
| 267 | 331 | $footer = $this->RenderPageCount(); |
@@ -48,6 +48,9 @@ discard block |
||
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | // avoids localization problems where , is used instead of . |
| 51 | +/** |
|
| 52 | + * @param integer $prec |
|
| 53 | + */ |
|
| 51 | 54 | function adodb_round($n,$prec) |
| 52 | 55 | { |
| 53 | 56 | return number_format($n, $prec, '.', ''); |
@@ -547,6 +550,10 @@ discard block |
||
| 547 | 550 | /* |
| 548 | 551 | Raw function to return parameter value from $settings. |
| 549 | 552 | */ |
| 553 | + |
|
| 554 | + /** |
|
| 555 | + * @param string $param |
|
| 556 | + */ |
|
| 550 | 557 | function DBParameter($param) |
| 551 | 558 | { |
| 552 | 559 | if (empty($this->settings[$param])) return false; |
@@ -949,6 +956,9 @@ discard block |
||
| 949 | 956 | return $arr; |
| 950 | 957 | } |
| 951 | 958 | |
| 959 | + /** |
|
| 960 | + * @param string $m |
|
| 961 | + */ |
|
| 952 | 962 | function undomq(&$m) |
| 953 | 963 | { |
| 954 | 964 | if (get_magic_quotes_gpc()) { |
@@ -984,7 +994,7 @@ discard block |
||
| 984 | 994 | * <code>ADODB_OPT_LOW</code> for CPU-less optimization |
| 985 | 995 | * Default is LOW <code>ADODB_OPT_LOW</code> |
| 986 | 996 | * @author Markus Staab |
| 987 | - * @return Returns <code>true</code> on success and <code>false</code> on error |
|
| 997 | + * @return false|null <code>true</code> on success and <code>false</code> on error |
|
| 988 | 998 | */ |
| 989 | 999 | function OptimizeTables() |
| 990 | 1000 | { |
@@ -1015,7 +1025,7 @@ discard block |
||
| 1015 | 1025 | * <code>ADODB_OPT_LOW</code> for CPU-less optimization |
| 1016 | 1026 | * Default is LOW <code>ADODB_OPT_LOW</code> |
| 1017 | 1027 | * @author Markus Staab |
| 1018 | - * @return Returns <code>true</code> on success and <code>false</code> on error |
|
| 1028 | + * @return boolean <code>true</code> on success and <code>false</code> on error |
|
| 1019 | 1029 | */ |
| 1020 | 1030 | function OptimizeTable( $table, $mode = ADODB_OPT_LOW) |
| 1021 | 1031 | { |
@@ -1029,7 +1039,7 @@ discard block |
||
| 1029 | 1039 | * optimize each using <code>optmizeTable()</code> |
| 1030 | 1040 | * |
| 1031 | 1041 | * @author Markus Staab |
| 1032 | - * @return Returns <code>true</code> on success and <code>false</code> on error |
|
| 1042 | + * @return boolean <code>true</code> on success and <code>false</code> on error |
|
| 1033 | 1043 | */ |
| 1034 | 1044 | function optimizeDatabase() |
| 1035 | 1045 | { |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | function& adodb_log_sql(&$conn,$sql,$inputarr) |
| 66 | 66 | { |
| 67 | 67 | |
| 68 | - $perf_table = adodb_perf::table(); |
|
| 68 | + $perf_table = adodb_perf::table(); |
|
| 69 | 69 | $conn->fnExecute = false; |
| 70 | 70 | $t0 = microtime(); |
| 71 | 71 | $rs =& $conn->Execute($sql,$inputarr); |
@@ -213,15 +213,15 @@ discard block |
||
| 213 | 213 | var $createTableSQL = false; |
| 214 | 214 | var $maxLength = 2000; |
| 215 | 215 | |
| 216 | - // Sets the tablename to be used |
|
| 217 | - function table($newtable = false) |
|
| 218 | - { |
|
| 219 | - static $_table; |
|
| 216 | + // Sets the tablename to be used |
|
| 217 | + function table($newtable = false) |
|
| 218 | + { |
|
| 219 | + static $_table; |
|
| 220 | 220 | |
| 221 | - if (!empty($newtable)) $_table = $newtable; |
|
| 221 | + if (!empty($newtable)) $_table = $newtable; |
|
| 222 | 222 | if (empty($_table)) $_table = 'adodb_logsql'; |
| 223 | - return $_table; |
|
| 224 | - } |
|
| 223 | + return $_table; |
|
| 224 | + } |
|
| 225 | 225 | |
| 226 | 226 | // returns array with info to calculate CPU Load |
| 227 | 227 | function _CPULoad() |
@@ -348,7 +348,7 @@ discard block |
||
| 348 | 348 | |
| 349 | 349 | function Tracer($sql) |
| 350 | 350 | { |
| 351 | - $perf_table = adodb_perf::table(); |
|
| 351 | + $perf_table = adodb_perf::table(); |
|
| 352 | 352 | $saveE = $this->conn->fnExecute; |
| 353 | 353 | $this->conn->fnExecute = false; |
| 354 | 354 | |
@@ -394,7 +394,7 @@ discard block |
||
| 394 | 394 | $s = '<h3>Invalid SQL</h3>'; |
| 395 | 395 | $saveE = $this->conn->fnExecute; |
| 396 | 396 | $this->conn->fnExecute = false; |
| 397 | - $perf_table = adodb_perf::table(); |
|
| 397 | + $perf_table = adodb_perf::table(); |
|
| 398 | 398 | $rs =& $this->conn->SelectLimit("select distinct count(*),sql1,tracer as error_msg from $perf_table where tracer like 'ERROR:%' group by sql1,tracer order by 1 desc",$numsql);//,$numsql); |
| 399 | 399 | $this->conn->fnExecute = $saveE; |
| 400 | 400 | if ($rs) { |
@@ -413,7 +413,7 @@ discard block |
||
| 413 | 413 | { |
| 414 | 414 | global $ADODB_FETCH_MODE; |
| 415 | 415 | |
| 416 | - $perf_table = adodb_perf::table(); |
|
| 416 | + $perf_table = adodb_perf::table(); |
|
| 417 | 417 | $saveE = $this->conn->fnExecute; |
| 418 | 418 | $this->conn->fnExecute = false; |
| 419 | 419 | |
@@ -492,7 +492,7 @@ discard block |
||
| 492 | 492 | { |
| 493 | 493 | global $ADODB_FETCH_MODE; |
| 494 | 494 | |
| 495 | - $perf_table = adodb_perf::table(); |
|
| 495 | + $perf_table = adodb_perf::table(); |
|
| 496 | 496 | $saveE = $this->conn->fnExecute; |
| 497 | 497 | $this->conn->fnExecute = false; |
| 498 | 498 | |
@@ -635,7 +635,7 @@ discard block |
||
| 635 | 635 | function UI($pollsecs=5) |
| 636 | 636 | { |
| 637 | 637 | |
| 638 | - $perf_table = adodb_perf::table(); |
|
| 638 | + $perf_table = adodb_perf::table(); |
|
| 639 | 639 | $conn = $this->conn; |
| 640 | 640 | |
| 641 | 641 | $app = $conn->host; |
@@ -963,91 +963,91 @@ discard block |
||
| 963 | 963 | |
| 964 | 964 | /************************************************************************/ |
| 965 | 965 | |
| 966 | - /** |
|
| 967 | - * Reorganise multiple table-indices/statistics/.. |
|
| 968 | - * OptimizeMode could be given by last Parameter |
|
| 969 | - * |
|
| 970 | - * @example |
|
| 971 | - * <pre> |
|
| 972 | - * optimizeTables( 'tableA'); |
|
| 973 | - * </pre> |
|
| 974 | - * <pre> |
|
| 975 | - * optimizeTables( 'tableA', 'tableB', 'tableC'); |
|
| 976 | - * </pre> |
|
| 977 | - * <pre> |
|
| 978 | - * optimizeTables( 'tableA', 'tableB', ADODB_OPT_LOW); |
|
| 979 | - * </pre> |
|
| 980 | - * |
|
| 981 | - * @param string table name of the table to optimize |
|
| 982 | - * @param int mode optimization-mode |
|
| 983 | - * <code>ADODB_OPT_HIGH</code> for full optimization |
|
| 984 | - * <code>ADODB_OPT_LOW</code> for CPU-less optimization |
|
| 985 | - * Default is LOW <code>ADODB_OPT_LOW</code> |
|
| 986 | - * @author Markus Staab |
|
| 987 | - * @return Returns <code>true</code> on success and <code>false</code> on error |
|
| 988 | - */ |
|
| 989 | - function OptimizeTables() |
|
| 990 | - { |
|
| 991 | - $args = func_get_args(); |
|
| 992 | - $numArgs = func_num_args(); |
|
| 966 | + /** |
|
| 967 | + * Reorganise multiple table-indices/statistics/.. |
|
| 968 | + * OptimizeMode could be given by last Parameter |
|
| 969 | + * |
|
| 970 | + * @example |
|
| 971 | + * <pre> |
|
| 972 | + * optimizeTables( 'tableA'); |
|
| 973 | + * </pre> |
|
| 974 | + * <pre> |
|
| 975 | + * optimizeTables( 'tableA', 'tableB', 'tableC'); |
|
| 976 | + * </pre> |
|
| 977 | + * <pre> |
|
| 978 | + * optimizeTables( 'tableA', 'tableB', ADODB_OPT_LOW); |
|
| 979 | + * </pre> |
|
| 980 | + * |
|
| 981 | + * @param string table name of the table to optimize |
|
| 982 | + * @param int mode optimization-mode |
|
| 983 | + * <code>ADODB_OPT_HIGH</code> for full optimization |
|
| 984 | + * <code>ADODB_OPT_LOW</code> for CPU-less optimization |
|
| 985 | + * Default is LOW <code>ADODB_OPT_LOW</code> |
|
| 986 | + * @author Markus Staab |
|
| 987 | + * @return Returns <code>true</code> on success and <code>false</code> on error |
|
| 988 | + */ |
|
| 989 | + function OptimizeTables() |
|
| 990 | + { |
|
| 991 | + $args = func_get_args(); |
|
| 992 | + $numArgs = func_num_args(); |
|
| 993 | 993 | |
| 994 | - if ( $numArgs == 0) return false; |
|
| 994 | + if ( $numArgs == 0) return false; |
|
| 995 | 995 | |
| 996 | - $mode = ADODB_OPT_LOW; |
|
| 997 | - $lastArg = $args[ $numArgs - 1]; |
|
| 998 | - if ( !is_string($lastArg)) { |
|
| 999 | - $mode = $lastArg; |
|
| 1000 | - unset( $args[ $numArgs - 1]); |
|
| 1001 | - } |
|
| 996 | + $mode = ADODB_OPT_LOW; |
|
| 997 | + $lastArg = $args[ $numArgs - 1]; |
|
| 998 | + if ( !is_string($lastArg)) { |
|
| 999 | + $mode = $lastArg; |
|
| 1000 | + unset( $args[ $numArgs - 1]); |
|
| 1001 | + } |
|
| 1002 | 1002 | |
| 1003 | - foreach( $args as $table) { |
|
| 1004 | - $this->optimizeTable( $table, $mode); |
|
| 1005 | - } |
|
| 1003 | + foreach( $args as $table) { |
|
| 1004 | + $this->optimizeTable( $table, $mode); |
|
| 1005 | + } |
|
| 1006 | 1006 | } |
| 1007 | 1007 | |
| 1008 | - /** |
|
| 1009 | - * Reorganise the table-indices/statistics/.. depending on the given mode. |
|
| 1010 | - * Default Implementation throws an error. |
|
| 1011 | - * |
|
| 1012 | - * @param string table name of the table to optimize |
|
| 1013 | - * @param int mode optimization-mode |
|
| 1014 | - * <code>ADODB_OPT_HIGH</code> for full optimization |
|
| 1015 | - * <code>ADODB_OPT_LOW</code> for CPU-less optimization |
|
| 1016 | - * Default is LOW <code>ADODB_OPT_LOW</code> |
|
| 1017 | - * @author Markus Staab |
|
| 1018 | - * @return Returns <code>true</code> on success and <code>false</code> on error |
|
| 1019 | - */ |
|
| 1020 | - function OptimizeTable( $table, $mode = ADODB_OPT_LOW) |
|
| 1021 | - { |
|
| 1022 | - ADOConnection::outp( sprintf( "<p>%s: '%s' not implemented for driver '%s'</p>", __CLASS__, __FUNCTION__, $this->conn->databaseType)); |
|
| 1023 | - return false; |
|
| 1024 | - } |
|
| 1008 | + /** |
|
| 1009 | + * Reorganise the table-indices/statistics/.. depending on the given mode. |
|
| 1010 | + * Default Implementation throws an error. |
|
| 1011 | + * |
|
| 1012 | + * @param string table name of the table to optimize |
|
| 1013 | + * @param int mode optimization-mode |
|
| 1014 | + * <code>ADODB_OPT_HIGH</code> for full optimization |
|
| 1015 | + * <code>ADODB_OPT_LOW</code> for CPU-less optimization |
|
| 1016 | + * Default is LOW <code>ADODB_OPT_LOW</code> |
|
| 1017 | + * @author Markus Staab |
|
| 1018 | + * @return Returns <code>true</code> on success and <code>false</code> on error |
|
| 1019 | + */ |
|
| 1020 | + function OptimizeTable( $table, $mode = ADODB_OPT_LOW) |
|
| 1021 | + { |
|
| 1022 | + ADOConnection::outp( sprintf( "<p>%s: '%s' not implemented for driver '%s'</p>", __CLASS__, __FUNCTION__, $this->conn->databaseType)); |
|
| 1023 | + return false; |
|
| 1024 | + } |
|
| 1025 | 1025 | |
| 1026 | - /** |
|
| 1027 | - * Reorganise current database. |
|
| 1028 | - * Default implementation loops over all <code>MetaTables()</code> and |
|
| 1029 | - * optimize each using <code>optmizeTable()</code> |
|
| 1030 | - * |
|
| 1031 | - * @author Markus Staab |
|
| 1032 | - * @return Returns <code>true</code> on success and <code>false</code> on error |
|
| 1033 | - */ |
|
| 1034 | - function optimizeDatabase() |
|
| 1035 | - { |
|
| 1036 | - $conn = $this->conn; |
|
| 1037 | - if ( !$conn) return false; |
|
| 1026 | + /** |
|
| 1027 | + * Reorganise current database. |
|
| 1028 | + * Default implementation loops over all <code>MetaTables()</code> and |
|
| 1029 | + * optimize each using <code>optmizeTable()</code> |
|
| 1030 | + * |
|
| 1031 | + * @author Markus Staab |
|
| 1032 | + * @return Returns <code>true</code> on success and <code>false</code> on error |
|
| 1033 | + */ |
|
| 1034 | + function optimizeDatabase() |
|
| 1035 | + { |
|
| 1036 | + $conn = $this->conn; |
|
| 1037 | + if ( !$conn) return false; |
|
| 1038 | 1038 | |
| 1039 | - $tables = $conn->MetaTables( 'TABLES'); |
|
| 1040 | - if ( !$tables ) return false; |
|
| 1039 | + $tables = $conn->MetaTables( 'TABLES'); |
|
| 1040 | + if ( !$tables ) return false; |
|
| 1041 | 1041 | |
| 1042 | - foreach( $tables as $table) { |
|
| 1043 | - if ( !$this->optimizeTable( $table)) { |
|
| 1044 | - return false; |
|
| 1045 | - } |
|
| 1046 | - } |
|
| 1042 | + foreach( $tables as $table) { |
|
| 1043 | + if ( !$this->optimizeTable( $table)) { |
|
| 1044 | + return false; |
|
| 1045 | + } |
|
| 1046 | + } |
|
| 1047 | 1047 | |
| 1048 | - return true; |
|
| 1049 | - } |
|
| 1050 | - // end hack |
|
| 1048 | + return true; |
|
| 1049 | + } |
|
| 1050 | + // end hack |
|
| 1051 | 1051 | } |
| 1052 | 1052 | |
| 1053 | 1053 | ?> |
| 1054 | 1054 | \ No newline at end of file |
@@ -19,21 +19,21 @@ discard block |
||
| 19 | 19 | if (!defined(ADODB_DIR)) include_once(dirname(__FILE__).'/adodb.inc.php'); |
| 20 | 20 | include_once(ADODB_DIR.'/tohtml.inc.php'); |
| 21 | 21 | |
| 22 | -define( 'ADODB_OPT_HIGH', 2); |
|
| 23 | -define( 'ADODB_OPT_LOW', 1); |
|
| 22 | +define('ADODB_OPT_HIGH', 2); |
|
| 23 | +define('ADODB_OPT_LOW', 1); |
|
| 24 | 24 | |
| 25 | 25 | // returns in K the memory of current process, or 0 if not known |
| 26 | 26 | function adodb_getmem() |
| 27 | 27 | { |
| 28 | 28 | if (function_exists('memory_get_usage')) |
| 29 | - return (integer) ((memory_get_usage()+512)/1024); |
|
| 29 | + return (integer)((memory_get_usage() + 512) / 1024); |
|
| 30 | 30 | |
| 31 | 31 | $pid = getmypid(); |
| 32 | 32 | |
| 33 | - if ( strncmp(strtoupper(PHP_OS),'WIN',3)==0) { |
|
| 33 | + if (strncmp(strtoupper(PHP_OS), 'WIN', 3) == 0) { |
|
| 34 | 34 | $output = array(); |
| 35 | 35 | |
| 36 | - exec('tasklist /FI "PID eq ' . $pid. '" /FO LIST', $output); |
|
| 36 | + exec('tasklist /FI "PID eq '.$pid.'" /FO LIST', $output); |
|
| 37 | 37 | return substr($output[5], strpos($output[5], ':') + 1); |
| 38 | 38 | } |
| 39 | 39 | |
@@ -41,14 +41,14 @@ discard block |
||
| 41 | 41 | exec("ps --pid $pid --no-headers -o%mem,size", $output); |
| 42 | 42 | if (sizeof($output) == 0) return 0; |
| 43 | 43 | |
| 44 | - $memarr = explode(' ',$output[0]); |
|
| 45 | - if (sizeof($memarr)>=2) return (integer) $memarr[1]; |
|
| 44 | + $memarr = explode(' ', $output[0]); |
|
| 45 | + if (sizeof($memarr) >= 2) return (integer)$memarr[1]; |
|
| 46 | 46 | |
| 47 | 47 | return 0; |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | // avoids localization problems where , is used instead of . |
| 51 | -function adodb_round($n,$prec) |
|
| 51 | +function adodb_round($n, $prec) |
|
| 52 | 52 | { |
| 53 | 53 | return number_format($n, $prec, '.', ''); |
| 54 | 54 | } |
@@ -57,29 +57,29 @@ discard block |
||
| 57 | 57 | function adodb_microtime() |
| 58 | 58 | { |
| 59 | 59 | $t = microtime(); |
| 60 | - $t = explode(' ',$t); |
|
| 61 | - return (float)$t[1]+ (float)$t[0]; |
|
| 60 | + $t = explode(' ', $t); |
|
| 61 | + return (float)$t[1] + (float)$t[0]; |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | /* sql code timing */ |
| 65 | -function& adodb_log_sql(&$conn,$sql,$inputarr) |
|
| 65 | +function& adodb_log_sql(&$conn, $sql, $inputarr) |
|
| 66 | 66 | { |
| 67 | 67 | |
| 68 | 68 | $perf_table = adodb_perf::table(); |
| 69 | 69 | $conn->fnExecute = false; |
| 70 | 70 | $t0 = microtime(); |
| 71 | - $rs =& $conn->Execute($sql,$inputarr); |
|
| 71 | + $rs = & $conn->Execute($sql, $inputarr); |
|
| 72 | 72 | $t1 = microtime(); |
| 73 | 73 | |
| 74 | 74 | if (!empty($conn->_logsql)) { |
| 75 | 75 | $conn->_logsql = false; // disable logsql error simulation |
| 76 | 76 | $dbT = $conn->databaseType; |
| 77 | 77 | |
| 78 | - $a0 = explode(' ',$t0); |
|
| 79 | - $a0 = (float)$a0[1]+(float)$a0[0]; |
|
| 78 | + $a0 = explode(' ', $t0); |
|
| 79 | + $a0 = (float)$a0[1] + (float)$a0[0]; |
|
| 80 | 80 | |
| 81 | - $a1 = explode(' ',$t1); |
|
| 82 | - $a1 = (float)$a1[1]+(float)$a1[0]; |
|
| 81 | + $a1 = explode(' ', $t1); |
|
| 82 | + $a1 = (float)$a1[1] + (float)$a1[0]; |
|
| 83 | 83 | |
| 84 | 84 | $time = $a1 - $a0; |
| 85 | 85 | |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | $errM = $conn->ErrorMsg(); |
| 88 | 88 | $errN = $conn->ErrorNo(); |
| 89 | 89 | $conn->lastInsID = 0; |
| 90 | - $tracer = substr('ERROR: '.htmlspecialchars($errM),0,250); |
|
| 90 | + $tracer = substr('ERROR: '.htmlspecialchars($errM), 0, 250); |
|
| 91 | 91 | } else { |
| 92 | 92 | $tracer = ''; |
| 93 | 93 | $errM = ''; |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | if (isset($_SERVER['PHP_SELF'])) $tracer .= '<br>'.$_SERVER['PHP_SELF']; |
| 107 | 107 | //$tracer .= (string) adodb_backtrace(false); |
| 108 | 108 | |
| 109 | - $tracer = (string) substr($tracer,0,500); |
|
| 109 | + $tracer = (string)substr($tracer, 0, 500); |
|
| 110 | 110 | |
| 111 | 111 | if (is_array($inputarr)) { |
| 112 | 112 | if (is_array(reset($inputarr))) $params = 'Array sizeof='.sizeof($inputarr); |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | $xar_params = $inputarr; |
| 117 | 117 | foreach ($xar_params as $xar_param_key => $xar_param) { |
| 118 | 118 | if (gettype($xar_param) == 'string') |
| 119 | - $xar_params[$xar_param_key] = '"' . $xar_param . '"'; |
|
| 119 | + $xar_params[$xar_param_key] = '"'.$xar_param.'"'; |
|
| 120 | 120 | } |
| 121 | 121 | $params = implode(', ', $xar_params); |
| 122 | 122 | if (strlen($params) >= 3000) $params = substr($params, 0, 3000); |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | |
| 128 | 128 | if (is_array($sql)) $sql = $sql[0]; |
| 129 | 129 | $arr = array('b'=>strlen($sql).'.'.crc32($sql), |
| 130 | - 'c'=>substr($sql,0,3900), 'd'=>$params,'e'=>$tracer,'f'=>adodb_round($time,6)); |
|
| 130 | + 'c'=>substr($sql, 0, 3900), 'd'=>$params, 'e'=>$tracer, 'f'=>adodb_round($time, 6)); |
|
| 131 | 131 | //var_dump($arr); |
| 132 | 132 | $saved = $conn->debug; |
| 133 | 133 | $conn->debug = 0; |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | $isql = "insert into $perf_table values($d,:b,:c,:d,:e,:f)"; |
| 139 | 139 | } else if ($dbT == 'odbc_mssql' || $dbT == 'informix') { |
| 140 | 140 | $timer = $arr['f']; |
| 141 | - if ($dbT == 'informix') $sql2 = substr($sql2,0,230); |
|
| 141 | + if ($dbT == 'informix') $sql2 = substr($sql2, 0, 230); |
|
| 142 | 142 | |
| 143 | 143 | $sql1 = $conn->qstr($arr['b']); |
| 144 | 144 | $sql2 = $conn->qstr($arr['c']); |
@@ -146,13 +146,13 @@ discard block |
||
| 146 | 146 | $tracer = $conn->qstr($arr['e']); |
| 147 | 147 | |
| 148 | 148 | $isql = "insert into $perf_table (created,sql0,sql1,params,tracer,timer) values($d,$sql1,$sql2,$params,$tracer,$timer)"; |
| 149 | - if ($dbT == 'informix') $isql = str_replace(chr(10),' ',$isql); |
|
| 149 | + if ($dbT == 'informix') $isql = str_replace(chr(10), ' ', $isql); |
|
| 150 | 150 | $arr = false; |
| 151 | 151 | } else { |
| 152 | 152 | $isql = "insert into $perf_table (created,sql0,sql1,params,tracer,timer) values( $d,?,?,?,?,?)"; |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | - $ok = $conn->Execute($isql,$arr); |
|
| 155 | + $ok = $conn->Execute($isql, $arr); |
|
| 156 | 156 | $conn->debug = $saved; |
| 157 | 157 | |
| 158 | 158 | if ($ok) { |
@@ -160,9 +160,9 @@ discard block |
||
| 160 | 160 | } else { |
| 161 | 161 | $err2 = $conn->ErrorMsg(); |
| 162 | 162 | $conn->_logsql = true; // enable logsql error simulation |
| 163 | - $perf =& NewPerfMonitor($conn); |
|
| 163 | + $perf = & NewPerfMonitor($conn); |
|
| 164 | 164 | if ($perf) { |
| 165 | - if ($perf->CreateLogTable()) $ok = $conn->Execute($isql,$arr); |
|
| 165 | + if ($perf->CreateLogTable()) $ok = $conn->Execute($isql, $arr); |
|
| 166 | 166 | } else { |
| 167 | 167 | $ok = $conn->Execute("create table $perf_table ( |
| 168 | 168 | created varchar(50), |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | timer decimal(16,6))"); |
| 174 | 174 | } |
| 175 | 175 | if (!$ok) { |
| 176 | - ADOConnection::outp( "<p><b>LOGSQL Insert Failed</b>: $isql<br>$err2</p>"); |
|
| 176 | + ADOConnection::outp("<p><b>LOGSQL Insert Failed</b>: $isql<br>$err2</p>"); |
|
| 177 | 177 | $conn->_logsql = false; |
| 178 | 178 | } |
| 179 | 179 | } |
@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | var $warnRatio = 90; |
| 208 | 208 | var $tablesSQL = false; |
| 209 | 209 | var $cliFormat = "%32s => %s \r\n"; |
| 210 | - var $sql1 = 'sql1'; // used for casting sql1 to text for mssql |
|
| 210 | + var $sql1 = 'sql1'; // used for casting sql1 to text for mssql |
|
| 211 | 211 | var $explain = true; |
| 212 | 212 | var $helpurl = "<a href=http://phplens.com/adodb/reference.functions.fnexecute.and.fncacheexecute.properties.html#logsql>LogSQL help</a>"; |
| 213 | 213 | var $createTableSQL = false; |
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | */ |
| 243 | 243 | // Algorithm is taken from |
| 244 | 244 | // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/example__obtaining_raw_performance_data.asp |
| 245 | - if (strncmp(PHP_OS,'WIN',3)==0) { |
|
| 245 | + if (strncmp(PHP_OS, 'WIN', 3) == 0) { |
|
| 246 | 246 | if (PHP_VERSION == '5.0.0') return false; |
| 247 | 247 | if (PHP_VERSION == '5.0.1') return false; |
| 248 | 248 | if (PHP_VERSION == '5.0.2') return false; |
@@ -264,16 +264,16 @@ discard block |
||
| 264 | 264 | $statfile = '/proc/stat'; |
| 265 | 265 | if (!file_exists($statfile)) return false; |
| 266 | 266 | |
| 267 | - $fd = fopen($statfile,"r"); |
|
| 267 | + $fd = fopen($statfile, "r"); |
|
| 268 | 268 | if (!$fd) return false; |
| 269 | 269 | |
| 270 | - $statinfo = explode("\n",fgets($fd, 1024)); |
|
| 270 | + $statinfo = explode("\n", fgets($fd, 1024)); |
|
| 271 | 271 | fclose($fd); |
| 272 | - foreach($statinfo as $line) { |
|
| 273 | - $info = explode(" ",$line); |
|
| 274 | - if($info[0]=="cpu") { |
|
| 275 | - array_shift($info); // pop off "cpu" |
|
| 276 | - if(!$info[0]) array_shift($info); // pop off blank space (if any) |
|
| 272 | + foreach ($statinfo as $line) { |
|
| 273 | + $info = explode(" ", $line); |
|
| 274 | + if ($info[0] == "cpu") { |
|
| 275 | + array_shift($info); // pop off "cpu" |
|
| 276 | + if (!$info[0]) array_shift($info); // pop off blank space (if any) |
|
| 277 | 277 | return $info; |
| 278 | 278 | } |
| 279 | 279 | } |
@@ -336,13 +336,13 @@ discard block |
||
| 336 | 336 | |
| 337 | 337 | //printf("Delta - User: %f Nice: %f System: %f Idle: %f<br>",$d_user,$d_nice,$d_system,$d_idle); |
| 338 | 338 | |
| 339 | - if (strncmp(PHP_OS,'WIN',3)==0) { |
|
| 339 | + if (strncmp(PHP_OS, 'WIN', 3) == 0) { |
|
| 340 | 340 | if ($d_idle < 1) $d_idle = 1; |
| 341 | - return 100*(1-$d_user/$d_idle); |
|
| 342 | - }else { |
|
| 343 | - $total=$d_user+$d_nice+$d_system+$d_idle; |
|
| 344 | - if ($total<1) $total=1; |
|
| 345 | - return 100*($d_user+$d_nice+$d_system)/$total; |
|
| 341 | + return 100 * (1 - $d_user / $d_idle); |
|
| 342 | + } else { |
|
| 343 | + $total = $d_user + $d_nice + $d_system + $d_idle; |
|
| 344 | + if ($total < 1) $total = 1; |
|
| 345 | + return 100 * ($d_user + $d_nice + $d_system) / $total; |
|
| 346 | 346 | } |
| 347 | 347 | } |
| 348 | 348 | |
@@ -366,8 +366,8 @@ discard block |
||
| 366 | 366 | $s = ''; |
| 367 | 367 | if ($arr) { |
| 368 | 368 | $s .= '<h3>Scripts Affected</h3>'; |
| 369 | - foreach($arr as $k) { |
|
| 370 | - $s .= sprintf("%4d",$k[0]).' '.strip_tags($k[1]).'<br>'; |
|
| 369 | + foreach ($arr as $k) { |
|
| 370 | + $s .= sprintf("%4d", $k[0]).' '.strip_tags($k[1]).'<br>'; |
|
| 371 | 371 | } |
| 372 | 372 | } |
| 373 | 373 | |
@@ -382,7 +382,7 @@ discard block |
||
| 382 | 382 | If only a snippet of the $sql is passed in, then $partial will hold the crc32 of the |
| 383 | 383 | actual sql. |
| 384 | 384 | */ |
| 385 | - function Explain($sql,$partial=false) |
|
| 385 | + function Explain($sql, $partial = false) |
|
| 386 | 386 | { |
| 387 | 387 | return false; |
| 388 | 388 | } |
@@ -395,10 +395,10 @@ discard block |
||
| 395 | 395 | $saveE = $this->conn->fnExecute; |
| 396 | 396 | $this->conn->fnExecute = false; |
| 397 | 397 | $perf_table = adodb_perf::table(); |
| 398 | - $rs =& $this->conn->SelectLimit("select distinct count(*),sql1,tracer as error_msg from $perf_table where tracer like 'ERROR:%' group by sql1,tracer order by 1 desc",$numsql);//,$numsql); |
|
| 398 | + $rs = & $this->conn->SelectLimit("select distinct count(*),sql1,tracer as error_msg from $perf_table where tracer like 'ERROR:%' group by sql1,tracer order by 1 desc", $numsql); //,$numsql); |
|
| 399 | 399 | $this->conn->fnExecute = $saveE; |
| 400 | 400 | if ($rs) { |
| 401 | - $s .= rs2html($rs,false,false,false,false); |
|
| 401 | + $s .= rs2html($rs, false, false, false, false); |
|
| 402 | 402 | } else |
| 403 | 403 | return "<p>$this->helpurl. ".$this->conn->ErrorMsg()."</p>"; |
| 404 | 404 | |
@@ -419,7 +419,7 @@ discard block |
||
| 419 | 419 | |
| 420 | 420 | if (isset($_GET['exps']) && isset($_GET['sql'])) { |
| 421 | 421 | $partial = !empty($_GET['part']); |
| 422 | - echo "<a name=explain></a>".$this->Explain($_GET['sql'],$partial)."\n"; |
|
| 422 | + echo "<a name=explain></a>".$this->Explain($_GET['sql'], $partial)."\n"; |
|
| 423 | 423 | } |
| 424 | 424 | |
| 425 | 425 | if (isset($_GET['sql'])) return; |
@@ -429,13 +429,13 @@ discard block |
||
| 429 | 429 | $ADODB_FETCH_MODE = ADODB_FETCH_NUM; |
| 430 | 430 | if ($this->conn->fetchMode !== false) $savem = $this->conn->SetFetchMode(false); |
| 431 | 431 | //$this->conn->debug=1; |
| 432 | - $rs =& $this->conn->SelectLimit( |
|
| 432 | + $rs = & $this->conn->SelectLimit( |
|
| 433 | 433 | "select avg(timer) as avg_timer,$sql1,count(*),max(timer) as max_timer,min(timer) as min_timer |
| 434 | 434 | from $perf_table |
| 435 | 435 | where {$this->conn->upperCase}({$this->conn->substr}(sql0,1,5)) not in ('DROP ','INSER','COMMI','CREAT') |
| 436 | 436 | and (tracer is null or tracer not like 'ERROR:%') |
| 437 | 437 | group by sql1 |
| 438 | - order by 1 desc",$numsql); |
|
| 438 | + order by 1 desc", $numsql); |
|
| 439 | 439 | if (isset($savem)) $this->conn->SetFetchMode($savem); |
| 440 | 440 | $ADODB_FETCH_MODE = $save; |
| 441 | 441 | $this->conn->fnExecute = $saveE; |
@@ -448,17 +448,17 @@ discard block |
||
| 448 | 448 | while (!$rs->EOF) { |
| 449 | 449 | $sql = $rs->fields[1]; |
| 450 | 450 | $raw = urlencode($sql); |
| 451 | - if (strlen($raw)>$max-100) { |
|
| 452 | - $sql2 = substr($sql,0,$max-500); |
|
| 451 | + if (strlen($raw) > $max - 100) { |
|
| 452 | + $sql2 = substr($sql, 0, $max - 500); |
|
| 453 | 453 | $raw = urlencode($sql2).'&part='.crc32($sql); |
| 454 | 454 | } |
| 455 | 455 | $prefix = "<a target=sql".rand()." href=\"?hidem=1&exps=1&sql=".$raw."&x#explain\">"; |
| 456 | 456 | $suffix = "</a>"; |
| 457 | - if ($this->explain == false || strlen($prefix)>$max) { |
|
| 457 | + if ($this->explain == false || strlen($prefix) > $max) { |
|
| 458 | 458 | $suffix = ' ... <i>String too long for GET parameter: '.strlen($prefix).'</i>'; |
| 459 | 459 | $prefix = ''; |
| 460 | 460 | } |
| 461 | - $s .= "<tr><td>".adodb_round($rs->fields[0],6)."<td align=right>".$rs->fields[2]."<td><font size=-1>".$prefix.htmlspecialchars($sql).$suffix."</font>". |
|
| 461 | + $s .= "<tr><td>".adodb_round($rs->fields[0], 6)."<td align=right>".$rs->fields[2]."<td><font size=-1>".$prefix.htmlspecialchars($sql).$suffix."</font>". |
|
| 462 | 462 | "<td>".$rs->fields[3]."<td>".$rs->fields[4]."</tr>"; |
| 463 | 463 | $rs->MoveNext(); |
| 464 | 464 | } |
@@ -472,12 +472,12 @@ discard block |
||
| 472 | 472 | } |
| 473 | 473 | |
| 474 | 474 | |
| 475 | - function SuspiciousSQL($numsql=10) |
|
| 475 | + function SuspiciousSQL($numsql = 10) |
|
| 476 | 476 | { |
| 477 | 477 | return adodb_perf::_SuspiciousSQL($numsql); |
| 478 | 478 | } |
| 479 | 479 | |
| 480 | - function ExpensiveSQL($numsql=10) |
|
| 480 | + function ExpensiveSQL($numsql = 10) |
|
| 481 | 481 | { |
| 482 | 482 | return adodb_perf::_ExpensiveSQL($numsql); |
| 483 | 483 | } |
@@ -498,7 +498,7 @@ discard block |
||
| 498 | 498 | |
| 499 | 499 | if (isset($_GET['expe']) && isset($_GET['sql'])) { |
| 500 | 500 | $partial = !empty($_GET['part']); |
| 501 | - echo "<a name=explain></a>".$this->Explain($_GET['sql'],$partial)."\n"; |
|
| 501 | + echo "<a name=explain></a>".$this->Explain($_GET['sql'], $partial)."\n"; |
|
| 502 | 502 | } |
| 503 | 503 | |
| 504 | 504 | if (isset($_GET['sql'])) return; |
@@ -508,14 +508,14 @@ discard block |
||
| 508 | 508 | $ADODB_FETCH_MODE = ADODB_FETCH_NUM; |
| 509 | 509 | if ($this->conn->fetchMode !== false) $savem = $this->conn->SetFetchMode(false); |
| 510 | 510 | |
| 511 | - $rs =& $this->conn->SelectLimit( |
|
| 511 | + $rs = & $this->conn->SelectLimit( |
|
| 512 | 512 | "select sum(timer) as total,$sql1,count(*),max(timer) as max_timer,min(timer) as min_timer |
| 513 | 513 | from $perf_table |
| 514 | 514 | where {$this->conn->upperCase}({$this->conn->substr}(sql0,1,5)) not in ('DROP ','INSER','COMMI','CREAT') |
| 515 | 515 | and (tracer is null or tracer not like 'ERROR:%') |
| 516 | 516 | group by sql1 |
| 517 | 517 | having count(*)>1 |
| 518 | - order by 1 desc",$numsql); |
|
| 518 | + order by 1 desc", $numsql); |
|
| 519 | 519 | if (isset($savem)) $this->conn->SetFetchMode($savem); |
| 520 | 520 | $this->conn->fnExecute = $saveE; |
| 521 | 521 | $ADODB_FETCH_MODE = $save; |
@@ -527,17 +527,17 @@ discard block |
||
| 527 | 527 | while (!$rs->EOF) { |
| 528 | 528 | $sql = $rs->fields[1]; |
| 529 | 529 | $raw = urlencode($sql); |
| 530 | - if (strlen($raw)>$max-100) { |
|
| 531 | - $sql2 = substr($sql,0,$max-500); |
|
| 530 | + if (strlen($raw) > $max - 100) { |
|
| 531 | + $sql2 = substr($sql, 0, $max - 500); |
|
| 532 | 532 | $raw = urlencode($sql2).'&part='.crc32($sql); |
| 533 | 533 | } |
| 534 | 534 | $prefix = "<a target=sqle".rand()." href=\"?hidem=1&expe=1&sql=".$raw."&x#explain\">"; |
| 535 | 535 | $suffix = "</a>"; |
| 536 | - if($this->explain == false || strlen($prefix>$max)) { |
|
| 536 | + if ($this->explain == false || strlen($prefix > $max)) { |
|
| 537 | 537 | $prefix = ''; |
| 538 | 538 | $suffix = ''; |
| 539 | 539 | } |
| 540 | - $s .= "<tr><td>".adodb_round($rs->fields[0],6)."<td align=right>".$rs->fields[2]."<td><font size=-1>".$prefix.htmlspecialchars($sql).$suffix."</font>". |
|
| 540 | + $s .= "<tr><td>".adodb_round($rs->fields[0], 6)."<td align=right>".$rs->fields[2]."<td><font size=-1>".$prefix.htmlspecialchars($sql).$suffix."</font>". |
|
| 541 | 541 | "<td>".$rs->fields[3]."<td>".$rs->fields[4]."</tr>"; |
| 542 | 542 | $rs->MoveNext(); |
| 543 | 543 | } |
@@ -562,7 +562,7 @@ discard block |
||
| 562 | 562 | $arr[0] = (float)$this->DBParameter('data cache hit ratio'); |
| 563 | 563 | $arr[1] = (float)$this->DBParameter('data reads'); |
| 564 | 564 | $arr[2] = (float)$this->DBParameter('data writes'); |
| 565 | - $arr[3] = (integer) $this->DBParameter('current connections'); |
|
| 565 | + $arr[3] = (integer)$this->DBParameter('current connections'); |
|
| 566 | 566 | return $arr; |
| 567 | 567 | } |
| 568 | 568 | |
@@ -577,9 +577,9 @@ discard block |
||
| 577 | 577 | |
| 578 | 578 | $sql1 = $sql[0]; |
| 579 | 579 | $key = $sql[1]; |
| 580 | - if (sizeof($sql)>2) $pos = $sql[2]; |
|
| 580 | + if (sizeof($sql) > 2) $pos = $sql[2]; |
|
| 581 | 581 | else $pos = 1; |
| 582 | - if (sizeof($sql)>3) $coef = $sql[3]; |
|
| 582 | + if (sizeof($sql) > 3) $coef = $sql[3]; |
|
| 583 | 583 | else $coef = false; |
| 584 | 584 | $ret = false; |
| 585 | 585 | $save = $ADODB_FETCH_MODE; |
@@ -605,11 +605,11 @@ discard block |
||
| 605 | 605 | $this->conn->LogSQL($savelog); |
| 606 | 606 | return $ret; |
| 607 | 607 | } else { |
| 608 | - if (strncmp($sql,'=',1) == 0) { |
|
| 609 | - $fn = substr($sql,1); |
|
| 608 | + if (strncmp($sql, '=', 1) == 0) { |
|
| 609 | + $fn = substr($sql, 1); |
|
| 610 | 610 | return $this->$fn(); |
| 611 | 611 | } |
| 612 | - $sql = str_replace('$DATABASE',$this->conn->database,$sql); |
|
| 612 | + $sql = str_replace('$DATABASE', $this->conn->database, $sql); |
|
| 613 | 613 | $ret = $this->conn->GetOne($sql); |
| 614 | 614 | $this->conn->LogSQL($savelog); |
| 615 | 615 | |
@@ -632,7 +632,7 @@ discard block |
||
| 632 | 632 | /***********************************************************************************************/ |
| 633 | 633 | |
| 634 | 634 | |
| 635 | - function UI($pollsecs=5) |
|
| 635 | + function UI($pollsecs = 5) |
|
| 636 | 636 | { |
| 637 | 637 | |
| 638 | 638 | $perf_table = adodb_perf::table(); |
@@ -653,7 +653,7 @@ discard block |
||
| 653 | 653 | // magic quotes |
| 654 | 654 | |
| 655 | 655 | if (isset($_GET['sql']) && get_magic_quotes_gpc()) { |
| 656 | - $_GET['sql'] = $_GET['sql'] = str_replace(array("\\'",'\"'),array("'",'"'),$_GET['sql']); |
|
| 656 | + $_GET['sql'] = $_GET['sql'] = str_replace(array("\\'", '\"'), array("'", '"'), $_GET['sql']); |
|
| 657 | 657 | } |
| 658 | 658 | |
| 659 | 659 | if (!isset($_SESSION['ADODB_PERF_SQL'])) $nsql = $_SESSION['ADODB_PERF_SQL'] = 10; |
@@ -668,7 +668,7 @@ discard block |
||
| 668 | 668 | else $do = 'stats'; |
| 669 | 669 | |
| 670 | 670 | if (isset($_GET['nsql'])) { |
| 671 | - if ($_GET['nsql'] > 0) $nsql = $_SESSION['ADODB_PERF_SQL'] = (integer) $_GET['nsql']; |
|
| 671 | + if ($_GET['nsql'] > 0) $nsql = $_SESSION['ADODB_PERF_SQL'] = (integer)$_GET['nsql']; |
|
| 672 | 672 | } |
| 673 | 673 | echo "<title>ADOdb Performance Monitor on $app</title><body bgcolor=white>"; |
| 674 | 674 | if ($do == 'viewsql') $form = "<td><form># SQL:<input type=hidden value=viewsql name=do> <input type=text size=4 name=nsql value=$nsql><input type=submit value=Go></td></form>"; |
@@ -676,7 +676,7 @@ discard block |
||
| 676 | 676 | |
| 677 | 677 | $allowsql = !defined('ADODB_PERF_NO_RUN_SQL'); |
| 678 | 678 | |
| 679 | - if (empty($_GET['hidem'])) |
|
| 679 | + if (empty($_GET['hidem'])) |
|
| 680 | 680 | echo "<table border=1 width=100% bgcolor=lightyellow><tr><td colspan=2> |
| 681 | 681 | <b><a href=http://adodb.sourceforge.net/?perf=1>ADOdb</a> Performance Monitor</b> <font size=1>for $app</font></tr><tr><td> |
| 682 | 682 | <a href=?do=stats><b>Performance Stats</b></a> <a href=?do=viewsql><b>View SQL</b></a> |
@@ -724,30 +724,30 @@ discard block |
||
| 724 | 724 | /* |
| 725 | 725 | Runs in infinite loop, returning real-time statistics |
| 726 | 726 | */ |
| 727 | - function Poll($secs=5) |
|
| 727 | + function Poll($secs = 5) |
|
| 728 | 728 | { |
| 729 | 729 | $this->conn->fnExecute = false; |
| 730 | 730 | //$this->conn->debug=1; |
| 731 | 731 | if ($secs <= 1) $secs = 1; |
| 732 | - echo "Accumulating statistics, every $secs seconds...\n";flush(); |
|
| 733 | - $arro =& $this->PollParameters(); |
|
| 732 | + echo "Accumulating statistics, every $secs seconds...\n"; flush(); |
|
| 733 | + $arro = & $this->PollParameters(); |
|
| 734 | 734 | $cnt = 0; |
| 735 | 735 | set_time_limit(0); |
| 736 | 736 | sleep($secs); |
| 737 | 737 | while (1) { |
| 738 | 738 | |
| 739 | - $arr =& $this->PollParameters(); |
|
| 739 | + $arr = & $this->PollParameters(); |
|
| 740 | 740 | |
| 741 | - $hits = sprintf('%2.2f',$arr[0]); |
|
| 742 | - $reads = sprintf('%12.4f',($arr[1]-$arro[1])/$secs); |
|
| 743 | - $writes = sprintf('%12.4f',($arr[2]-$arro[2])/$secs); |
|
| 744 | - $sess = sprintf('%5d',$arr[3]); |
|
| 741 | + $hits = sprintf('%2.2f', $arr[0]); |
|
| 742 | + $reads = sprintf('%12.4f', ($arr[1] - $arro[1]) / $secs); |
|
| 743 | + $writes = sprintf('%12.4f', ($arr[2] - $arro[2]) / $secs); |
|
| 744 | + $sess = sprintf('%5d', $arr[3]); |
|
| 745 | 745 | |
| 746 | 746 | $load = $this->CPULoad(); |
| 747 | 747 | if ($load !== false) { |
| 748 | 748 | $oslabel = 'WS-CPU%'; |
| 749 | - $osval = sprintf(" %2.1f ",(float) $load); |
|
| 750 | - }else { |
|
| 749 | + $osval = sprintf(" %2.1f ", (float)$load); |
|
| 750 | + } else { |
|
| 751 | 751 | $oslabel = ''; |
| 752 | 752 | $osval = ''; |
| 753 | 753 | } |
@@ -775,7 +775,7 @@ discard block |
||
| 775 | 775 | /* |
| 776 | 776 | Returns basic health check as HTML |
| 777 | 777 | */ |
| 778 | - function HealthCheck($cli=false) |
|
| 778 | + function HealthCheck($cli = false) |
|
| 779 | 779 | { |
| 780 | 780 | $saveE = $this->conn->fnExecute; |
| 781 | 781 | $this->conn->fnExecute = false; |
@@ -784,7 +784,7 @@ discard block |
||
| 784 | 784 | |
| 785 | 785 | $oldc = false; |
| 786 | 786 | $bgc = ''; |
| 787 | - foreach($this->settings as $name => $arr) { |
|
| 787 | + foreach ($this->settings as $name => $arr) { |
|
| 788 | 788 | if ($arr === false) break; |
| 789 | 789 | |
| 790 | 790 | if (!is_string($name)) { |
@@ -796,7 +796,7 @@ discard block |
||
| 796 | 796 | if (!is_array($arr)) break; |
| 797 | 797 | $category = $arr[0]; |
| 798 | 798 | $how = $arr[1]; |
| 799 | - if (sizeof($arr)>2) $desc = $arr[2]; |
|
| 799 | + if (sizeof($arr) > 2) $desc = $arr[2]; |
|
| 800 | 800 | else $desc = ' '; |
| 801 | 801 | |
| 802 | 802 | |
@@ -804,8 +804,8 @@ discard block |
||
| 804 | 804 | |
| 805 | 805 | $val = $this->_DBParameter($how); |
| 806 | 806 | |
| 807 | - if ($desc && strncmp($desc,"=",1) === 0) { |
|
| 808 | - $fn = substr($desc,1); |
|
| 807 | + if ($desc && strncmp($desc, "=", 1) === 0) { |
|
| 808 | + $fn = substr($desc, 1); |
|
| 809 | 809 | $desc = $this->$fn($val); |
| 810 | 810 | } |
| 811 | 811 | |
@@ -813,9 +813,9 @@ discard block |
||
| 813 | 813 | $m = $this->conn->ErrorMsg(); |
| 814 | 814 | $val = "Error: $m"; |
| 815 | 815 | } else { |
| 816 | - if (is_numeric($val) && $val >= 256*1024) { |
|
| 817 | - if ($val % (1024*1024) == 0) { |
|
| 818 | - $val /= (1024*1024); |
|
| 816 | + if (is_numeric($val) && $val >= 256 * 1024) { |
|
| 817 | + if ($val % (1024 * 1024) == 0) { |
|
| 818 | + $val /= (1024 * 1024); |
|
| 819 | 819 | $val .= 'M'; |
| 820 | 820 | } else if ($val % 1024 == 0) { |
| 821 | 821 | $val /= 1024; |
@@ -828,12 +828,12 @@ discard block |
||
| 828 | 828 | $oldc = $category; |
| 829 | 829 | //$bgc = ($bgc == ' bgcolor='.$this->color) ? ' bgcolor=white' : ' bgcolor='.$this->color; |
| 830 | 830 | } |
| 831 | - if (strlen($desc)==0) $desc = ' '; |
|
| 832 | - if (strlen($val)==0) $val = ' '; |
|
| 831 | + if (strlen($desc) == 0) $desc = ' '; |
|
| 832 | + if (strlen($val) == 0) $val = ' '; |
|
| 833 | 833 | if ($cli) { |
| 834 | - $html .= str_replace(' ','',sprintf($this->cliFormat,strip_tags($name),strip_tags($val),strip_tags($desc))); |
|
| 834 | + $html .= str_replace(' ', '', sprintf($this->cliFormat, strip_tags($name), strip_tags($val), strip_tags($desc))); |
|
| 835 | 835 | |
| 836 | - }else { |
|
| 836 | + } else { |
|
| 837 | 837 | $html .= "<tr$bgc><td>".$name.'</td><td>'.$val.'</td><td>'.$desc."</td></tr>\n"; |
| 838 | 838 | } |
| 839 | 839 | } |
@@ -844,14 +844,14 @@ discard block |
||
| 844 | 844 | return $html; |
| 845 | 845 | } |
| 846 | 846 | |
| 847 | - function Tables($orderby='1') |
|
| 847 | + function Tables($orderby = '1') |
|
| 848 | 848 | { |
| 849 | 849 | if (!$this->tablesSQL) return false; |
| 850 | 850 | |
| 851 | 851 | $savelog = $this->conn->LogSQL(false); |
| 852 | 852 | $rs = $this->conn->Execute($this->tablesSQL.' order by '.$orderby); |
| 853 | 853 | $this->conn->LogSQL($savelog); |
| 854 | - $html = rs2html($rs,false,false,false,false); |
|
| 854 | + $html = rs2html($rs, false, false, false, false); |
|
| 855 | 855 | return $html; |
| 856 | 856 | } |
| 857 | 857 | |
@@ -906,14 +906,14 @@ discard block |
||
| 906 | 906 | if (!isset($_REQUEST['sql'])) return; |
| 907 | 907 | |
| 908 | 908 | $sql = $this->undomq(trim($sql)); |
| 909 | - if (substr($sql,strlen($sql)-1) === ';') { |
|
| 909 | + if (substr($sql, strlen($sql) - 1) === ';') { |
|
| 910 | 910 | $print = true; |
| 911 | 911 | $sqla = $this->SplitSQL($sql); |
| 912 | - } else { |
|
| 912 | + } else { |
|
| 913 | 913 | $print = false; |
| 914 | 914 | $sqla = array($sql); |
| 915 | 915 | } |
| 916 | - foreach($sqla as $sqls) { |
|
| 916 | + foreach ($sqla as $sqls) { |
|
| 917 | 917 | |
| 918 | 918 | if (!$sqls) continue; |
| 919 | 919 | |
@@ -931,7 +931,7 @@ discard block |
||
| 931 | 931 | rs2html($rs); |
| 932 | 932 | } |
| 933 | 933 | } else { |
| 934 | - $e1 = (integer) $this->conn->ErrorNo(); |
|
| 934 | + $e1 = (integer)$this->conn->ErrorNo(); |
|
| 935 | 935 | $e2 = $this->conn->ErrorMsg(); |
| 936 | 936 | if (($e1) || ($e2)) { |
| 937 | 937 | if (empty($e1)) $e1 = '-1'; // postgresql fix |
@@ -945,7 +945,7 @@ discard block |
||
| 945 | 945 | |
| 946 | 946 | function SplitSQL($sql) |
| 947 | 947 | { |
| 948 | - $arr = explode(';',$sql); |
|
| 948 | + $arr = explode(';', $sql); |
|
| 949 | 949 | return $arr; |
| 950 | 950 | } |
| 951 | 951 | |
@@ -953,9 +953,9 @@ discard block |
||
| 953 | 953 | { |
| 954 | 954 | if (get_magic_quotes_gpc()) { |
| 955 | 955 | // undo the damage |
| 956 | - $m = str_replace('\\\\','\\',$m); |
|
| 957 | - $m = str_replace('\"','"',$m); |
|
| 958 | - $m = str_replace('\\\'','\'',$m); |
|
| 956 | + $m = str_replace('\\\\', '\\', $m); |
|
| 957 | + $m = str_replace('\"', '"', $m); |
|
| 958 | + $m = str_replace('\\\'', '\'', $m); |
|
| 959 | 959 | } |
| 960 | 960 | return $m; |
| 961 | 961 | } |
@@ -991,17 +991,17 @@ discard block |
||
| 991 | 991 | $args = func_get_args(); |
| 992 | 992 | $numArgs = func_num_args(); |
| 993 | 993 | |
| 994 | - if ( $numArgs == 0) return false; |
|
| 994 | + if ($numArgs == 0) return false; |
|
| 995 | 995 | |
| 996 | 996 | $mode = ADODB_OPT_LOW; |
| 997 | - $lastArg = $args[ $numArgs - 1]; |
|
| 998 | - if ( !is_string($lastArg)) { |
|
| 997 | + $lastArg = $args[$numArgs - 1]; |
|
| 998 | + if (!is_string($lastArg)) { |
|
| 999 | 999 | $mode = $lastArg; |
| 1000 | - unset( $args[ $numArgs - 1]); |
|
| 1000 | + unset($args[$numArgs - 1]); |
|
| 1001 | 1001 | } |
| 1002 | 1002 | |
| 1003 | - foreach( $args as $table) { |
|
| 1004 | - $this->optimizeTable( $table, $mode); |
|
| 1003 | + foreach ($args as $table) { |
|
| 1004 | + $this->optimizeTable($table, $mode); |
|
| 1005 | 1005 | } |
| 1006 | 1006 | } |
| 1007 | 1007 | |
@@ -1017,9 +1017,9 @@ discard block |
||
| 1017 | 1017 | * @author Markus Staab |
| 1018 | 1018 | * @return Returns <code>true</code> on success and <code>false</code> on error |
| 1019 | 1019 | */ |
| 1020 | - function OptimizeTable( $table, $mode = ADODB_OPT_LOW) |
|
| 1020 | + function OptimizeTable($table, $mode = ADODB_OPT_LOW) |
|
| 1021 | 1021 | { |
| 1022 | - ADOConnection::outp( sprintf( "<p>%s: '%s' not implemented for driver '%s'</p>", __CLASS__, __FUNCTION__, $this->conn->databaseType)); |
|
| 1022 | + ADOConnection::outp(sprintf("<p>%s: '%s' not implemented for driver '%s'</p>", __CLASS__, __FUNCTION__, $this->conn->databaseType)); |
|
| 1023 | 1023 | return false; |
| 1024 | 1024 | } |
| 1025 | 1025 | |
@@ -1034,13 +1034,13 @@ discard block |
||
| 1034 | 1034 | function optimizeDatabase() |
| 1035 | 1035 | { |
| 1036 | 1036 | $conn = $this->conn; |
| 1037 | - if ( !$conn) return false; |
|
| 1037 | + if (!$conn) return false; |
|
| 1038 | 1038 | |
| 1039 | - $tables = $conn->MetaTables( 'TABLES'); |
|
| 1040 | - if ( !$tables ) return false; |
|
| 1039 | + $tables = $conn->MetaTables('TABLES'); |
|
| 1040 | + if (!$tables) return false; |
|
| 1041 | 1041 | |
| 1042 | - foreach( $tables as $table) { |
|
| 1043 | - if ( !$this->optimizeTable( $table)) { |
|
| 1042 | + foreach ($tables as $table) { |
|
| 1043 | + if (!$this->optimizeTable($table)) { |
|
| 1044 | 1044 | return false; |
| 1045 | 1045 | } |
| 1046 | 1046 | } |
@@ -16,7 +16,10 @@ discard block |
||
| 16 | 16 | |
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | -if (!defined(ADODB_DIR)) include_once(dirname(__FILE__).'/adodb.inc.php'); |
|
| 19 | +if (!defined(ADODB_DIR)) |
|
| 20 | +{ |
|
| 21 | + include_once(dirname(__FILE__).'/adodb.inc.php'); |
|
| 22 | +} |
|
| 20 | 23 | include_once(ADODB_DIR.'/tohtml.inc.php'); |
| 21 | 24 | |
| 22 | 25 | define( 'ADODB_OPT_HIGH', 2); |
@@ -26,11 +29,14 @@ discard block |
||
| 26 | 29 | function adodb_getmem() |
| 27 | 30 | { |
| 28 | 31 | if (function_exists('memory_get_usage')) |
| 29 | - return (integer) ((memory_get_usage()+512)/1024); |
|
| 32 | + { |
|
| 33 | + return (integer) ((memory_get_usage()+512)/1024); |
|
| 34 | + } |
|
| 30 | 35 | |
| 31 | 36 | $pid = getmypid(); |
| 32 | 37 | |
| 33 | - if ( strncmp(strtoupper(PHP_OS),'WIN',3)==0) { |
|
| 38 | + if ( strncmp(strtoupper(PHP_OS),'WIN',3)==0) |
|
| 39 | + { |
|
| 34 | 40 | $output = array(); |
| 35 | 41 | |
| 36 | 42 | exec('tasklist /FI "PID eq ' . $pid. '" /FO LIST', $output); |
@@ -39,10 +45,16 @@ discard block |
||
| 39 | 45 | |
| 40 | 46 | /* Hopefully UNIX */ |
| 41 | 47 | exec("ps --pid $pid --no-headers -o%mem,size", $output); |
| 42 | - if (sizeof($output) == 0) return 0; |
|
| 48 | + if (sizeof($output) == 0) |
|
| 49 | + { |
|
| 50 | + return 0; |
|
| 51 | + } |
|
| 43 | 52 | |
| 44 | 53 | $memarr = explode(' ',$output[0]); |
| 45 | - if (sizeof($memarr)>=2) return (integer) $memarr[1]; |
|
| 54 | + if (sizeof($memarr)>=2) |
|
| 55 | + { |
|
| 56 | + return (integer) $memarr[1]; |
|
| 57 | + } |
|
| 46 | 58 | |
| 47 | 59 | return 0; |
| 48 | 60 | } |
@@ -71,7 +83,8 @@ discard block |
||
| 71 | 83 | $rs =& $conn->Execute($sql,$inputarr); |
| 72 | 84 | $t1 = microtime(); |
| 73 | 85 | |
| 74 | - if (!empty($conn->_logsql)) { |
|
| 86 | + if (!empty($conn->_logsql)) |
|
| 87 | + { |
|
| 75 | 88 | $conn->_logsql = false; // disable logsql error simulation |
| 76 | 89 | $dbT = $conn->databaseType; |
| 77 | 90 | |
@@ -83,49 +96,78 @@ discard block |
||
| 83 | 96 | |
| 84 | 97 | $time = $a1 - $a0; |
| 85 | 98 | |
| 86 | - if (!$rs) { |
|
| 99 | + if (!$rs) |
|
| 100 | + { |
|
| 87 | 101 | $errM = $conn->ErrorMsg(); |
| 88 | 102 | $errN = $conn->ErrorNo(); |
| 89 | 103 | $conn->lastInsID = 0; |
| 90 | 104 | $tracer = substr('ERROR: '.htmlspecialchars($errM),0,250); |
| 91 | - } else { |
|
| 105 | + } |
|
| 106 | + else |
|
| 107 | + { |
|
| 92 | 108 | $tracer = ''; |
| 93 | 109 | $errM = ''; |
| 94 | 110 | $errN = 0; |
| 95 | 111 | $dbg = $conn->debug; |
| 96 | 112 | $conn->debug = false; |
| 97 | - if (!is_object($rs) || $rs->dataProvider == 'empty') |
|
| 98 | - $conn->_affected = $conn->affected_rows(true); |
|
| 113 | + if (!is_object($rs) || $rs->dataProvider == 'empty') |
|
| 114 | + { |
|
| 115 | + $conn->_affected = $conn->affected_rows(true); |
|
| 116 | + } |
|
| 99 | 117 | $conn->lastInsID = @$conn->Insert_ID(); |
| 100 | 118 | $conn->debug = $dbg; |
| 101 | 119 | } |
| 102 | - if (isset($_SERVER['HTTP_HOST'])) { |
|
| 120 | + if (isset($_SERVER['HTTP_HOST'])) |
|
| 121 | + { |
|
| 103 | 122 | $tracer .= '<br>'.$_SERVER['HTTP_HOST']; |
| 104 | - if (isset($_SERVER['PHP_SELF'])) $tracer .= $_SERVER['PHP_SELF']; |
|
| 105 | - } else |
|
| 106 | - if (isset($_SERVER['PHP_SELF'])) $tracer .= '<br>'.$_SERVER['PHP_SELF']; |
|
| 123 | + if (isset($_SERVER['PHP_SELF'])) |
|
| 124 | + { |
|
| 125 | + $tracer .= $_SERVER['PHP_SELF']; |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | + else |
|
| 129 | + if (isset($_SERVER['PHP_SELF'])) |
|
| 130 | + { |
|
| 131 | + $tracer .= '<br>'.$_SERVER['PHP_SELF']; |
|
| 132 | + } |
|
| 107 | 133 | //$tracer .= (string) adodb_backtrace(false); |
| 108 | 134 | |
| 109 | 135 | $tracer = (string) substr($tracer,0,500); |
| 110 | 136 | |
| 111 | - if (is_array($inputarr)) { |
|
| 112 | - if (is_array(reset($inputarr))) $params = 'Array sizeof='.sizeof($inputarr); |
|
| 113 | - else { |
|
| 137 | + if (is_array($inputarr)) |
|
| 138 | + { |
|
| 139 | + if (is_array(reset($inputarr))) |
|
| 140 | + { |
|
| 141 | + $params = 'Array sizeof='.sizeof($inputarr); |
|
| 142 | + } |
|
| 143 | + else |
|
| 144 | + { |
|
| 114 | 145 | // Quote string parameters so we can see them in the |
| 115 | 146 | // performance stats. This helps spot disabled indexes. |
| 116 | 147 | $xar_params = $inputarr; |
| 117 | - foreach ($xar_params as $xar_param_key => $xar_param) { |
|
| 148 | + foreach ($xar_params as $xar_param_key => $xar_param) |
|
| 149 | + { |
|
| 118 | 150 | if (gettype($xar_param) == 'string') |
| 119 | - $xar_params[$xar_param_key] = '"' . $xar_param . '"'; |
|
| 151 | + { |
|
| 152 | + $xar_params[$xar_param_key] = '"' . $xar_param . '"'; |
|
| 153 | + } |
|
| 120 | 154 | } |
| 121 | 155 | $params = implode(', ', $xar_params); |
| 122 | - if (strlen($params) >= 3000) $params = substr($params, 0, 3000); |
|
| 156 | + if (strlen($params) >= 3000) |
|
| 157 | + { |
|
| 158 | + $params = substr($params, 0, 3000); |
|
| 159 | + } |
|
| 123 | 160 | } |
| 124 | - } else { |
|
| 161 | + } |
|
| 162 | + else |
|
| 163 | + { |
|
| 125 | 164 | $params = ''; |
| 126 | 165 | } |
| 127 | 166 | |
| 128 | - if (is_array($sql)) $sql = $sql[0]; |
|
| 167 | + if (is_array($sql)) |
|
| 168 | + { |
|
| 169 | + $sql = $sql[0]; |
|
| 170 | + } |
|
| 129 | 171 | $arr = array('b'=>strlen($sql).'.'.crc32($sql), |
| 130 | 172 | 'c'=>substr($sql,0,3900), 'd'=>$params,'e'=>$tracer,'f'=>adodb_round($time,6)); |
| 131 | 173 | //var_dump($arr); |
@@ -133,12 +175,21 @@ discard block |
||
| 133 | 175 | $conn->debug = 0; |
| 134 | 176 | |
| 135 | 177 | $d = $conn->sysTimeStamp; |
| 136 | - if (empty($d)) $d = date("'Y-m-d H:i:s'"); |
|
| 137 | - if ($conn->dataProvider == 'oci8' && $dbT != 'oci8po') { |
|
| 178 | + if (empty($d)) |
|
| 179 | + { |
|
| 180 | + $d = date("'Y-m-d H:i:s'"); |
|
| 181 | + } |
|
| 182 | + if ($conn->dataProvider == 'oci8' && $dbT != 'oci8po') |
|
| 183 | + { |
|
| 138 | 184 | $isql = "insert into $perf_table values($d,:b,:c,:d,:e,:f)"; |
| 139 | - } else if ($dbT == 'odbc_mssql' || $dbT == 'informix') { |
|
| 185 | + } |
|
| 186 | + else if ($dbT == 'odbc_mssql' || $dbT == 'informix') |
|
| 187 | + { |
|
| 140 | 188 | $timer = $arr['f']; |
| 141 | - if ($dbT == 'informix') $sql2 = substr($sql2,0,230); |
|
| 189 | + if ($dbT == 'informix') |
|
| 190 | + { |
|
| 191 | + $sql2 = substr($sql2,0,230); |
|
| 192 | + } |
|
| 142 | 193 | |
| 143 | 194 | $sql1 = $conn->qstr($arr['b']); |
| 144 | 195 | $sql2 = $conn->qstr($arr['c']); |
@@ -146,24 +197,38 @@ discard block |
||
| 146 | 197 | $tracer = $conn->qstr($arr['e']); |
| 147 | 198 | |
| 148 | 199 | $isql = "insert into $perf_table (created,sql0,sql1,params,tracer,timer) values($d,$sql1,$sql2,$params,$tracer,$timer)"; |
| 149 | - if ($dbT == 'informix') $isql = str_replace(chr(10),' ',$isql); |
|
| 200 | + if ($dbT == 'informix') |
|
| 201 | + { |
|
| 202 | + $isql = str_replace(chr(10),' ',$isql); |
|
| 203 | + } |
|
| 150 | 204 | $arr = false; |
| 151 | - } else { |
|
| 205 | + } |
|
| 206 | + else |
|
| 207 | + { |
|
| 152 | 208 | $isql = "insert into $perf_table (created,sql0,sql1,params,tracer,timer) values( $d,?,?,?,?,?)"; |
| 153 | 209 | } |
| 154 | 210 | |
| 155 | 211 | $ok = $conn->Execute($isql,$arr); |
| 156 | 212 | $conn->debug = $saved; |
| 157 | 213 | |
| 158 | - if ($ok) { |
|
| 214 | + if ($ok) |
|
| 215 | + { |
|
| 159 | 216 | $conn->_logsql = true; |
| 160 | - } else { |
|
| 217 | + } |
|
| 218 | + else |
|
| 219 | + { |
|
| 161 | 220 | $err2 = $conn->ErrorMsg(); |
| 162 | 221 | $conn->_logsql = true; // enable logsql error simulation |
| 163 | 222 | $perf =& NewPerfMonitor($conn); |
| 164 | - if ($perf) { |
|
| 165 | - if ($perf->CreateLogTable()) $ok = $conn->Execute($isql,$arr); |
|
| 166 | - } else { |
|
| 223 | + if ($perf) |
|
| 224 | + { |
|
| 225 | + if ($perf->CreateLogTable()) |
|
| 226 | + { |
|
| 227 | + $ok = $conn->Execute($isql,$arr); |
|
| 228 | + } |
|
| 229 | + } |
|
| 230 | + else |
|
| 231 | + { |
|
| 167 | 232 | $ok = $conn->Execute("create table $perf_table ( |
| 168 | 233 | created varchar(50), |
| 169 | 234 | sql0 varchar(250), |
@@ -172,7 +237,8 @@ discard block |
||
| 172 | 237 | tracer varchar(500), |
| 173 | 238 | timer decimal(16,6))"); |
| 174 | 239 | } |
| 175 | - if (!$ok) { |
|
| 240 | + if (!$ok) |
|
| 241 | + { |
|
| 176 | 242 | ADOConnection::outp( "<p><b>LOGSQL Insert Failed</b>: $isql<br>$err2</p>"); |
| 177 | 243 | $conn->_logsql = false; |
| 178 | 244 | } |
@@ -199,7 +265,8 @@ discard block |
||
| 199 | 265 | 2: description of the database parameter |
| 200 | 266 | */ |
| 201 | 267 | |
| 202 | -class adodb_perf { |
|
| 268 | +class adodb_perf |
|
| 269 | +{ |
|
| 203 | 270 | var $conn; |
| 204 | 271 | var $color = '#F0F0F0'; |
| 205 | 272 | var $table = '<table border=1 bgcolor=white>'; |
@@ -218,8 +285,14 @@ discard block |
||
| 218 | 285 | { |
| 219 | 286 | static $_table; |
| 220 | 287 | |
| 221 | - if (!empty($newtable)) $_table = $newtable; |
|
| 222 | - if (empty($_table)) $_table = 'adodb_logsql'; |
|
| 288 | + if (!empty($newtable)) |
|
| 289 | + { |
|
| 290 | + $_table = $newtable; |
|
| 291 | + } |
|
| 292 | + if (empty($_table)) |
|
| 293 | + { |
|
| 294 | + $_table = 'adodb_logsql'; |
|
| 295 | + } |
|
| 223 | 296 | return $_table; |
| 224 | 297 | } |
| 225 | 298 | |
@@ -242,15 +315,35 @@ discard block |
||
| 242 | 315 | */ |
| 243 | 316 | // Algorithm is taken from |
| 244 | 317 | // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/example__obtaining_raw_performance_data.asp |
| 245 | - if (strncmp(PHP_OS,'WIN',3)==0) { |
|
| 246 | - if (PHP_VERSION == '5.0.0') return false; |
|
| 247 | - if (PHP_VERSION == '5.0.1') return false; |
|
| 248 | - if (PHP_VERSION == '5.0.2') return false; |
|
| 249 | - if (PHP_VERSION == '5.0.3') return false; |
|
| 250 | - if (PHP_VERSION == '4.3.10') return false; # see http://bugs.php.net/bug.php?id=31737 |
|
| 318 | + if (strncmp(PHP_OS,'WIN',3)==0) |
|
| 319 | + { |
|
| 320 | + if (PHP_VERSION == '5.0.0') |
|
| 321 | + { |
|
| 322 | + return false; |
|
| 323 | + } |
|
| 324 | + if (PHP_VERSION == '5.0.1') |
|
| 325 | + { |
|
| 326 | + return false; |
|
| 327 | + } |
|
| 328 | + if (PHP_VERSION == '5.0.2') |
|
| 329 | + { |
|
| 330 | + return false; |
|
| 331 | + } |
|
| 332 | + if (PHP_VERSION == '5.0.3') |
|
| 333 | + { |
|
| 334 | + return false; |
|
| 335 | + } |
|
| 336 | + if (PHP_VERSION == '4.3.10') |
|
| 337 | + { |
|
| 338 | + return false; |
|
| 339 | + } |
|
| 340 | + # see http://bugs.php.net/bug.php?id=31737 |
|
| 251 | 341 | |
| 252 | 342 | @$c = new COM("WinMgmts:{impersonationLevel=impersonate}!Win32_PerfRawData_PerfOS_Processor.Name='_Total'"); |
| 253 | - if (!$c) return false; |
|
| 343 | + if (!$c) |
|
| 344 | + { |
|
| 345 | + return false; |
|
| 346 | + } |
|
| 254 | 347 | |
| 255 | 348 | $info[0] = $c->PercentProcessorTime; |
| 256 | 349 | $info[1] = 0; |
@@ -262,18 +355,30 @@ discard block |
||
| 262 | 355 | |
| 263 | 356 | // Algorithm - Steve Blinch (BlitzAffe Online, http://www.blitzaffe.com) |
| 264 | 357 | $statfile = '/proc/stat'; |
| 265 | - if (!file_exists($statfile)) return false; |
|
| 358 | + if (!file_exists($statfile)) |
|
| 359 | + { |
|
| 360 | + return false; |
|
| 361 | + } |
|
| 266 | 362 | |
| 267 | 363 | $fd = fopen($statfile,"r"); |
| 268 | - if (!$fd) return false; |
|
| 364 | + if (!$fd) |
|
| 365 | + { |
|
| 366 | + return false; |
|
| 367 | + } |
|
| 269 | 368 | |
| 270 | 369 | $statinfo = explode("\n",fgets($fd, 1024)); |
| 271 | 370 | fclose($fd); |
| 272 | - foreach($statinfo as $line) { |
|
| 371 | + foreach($statinfo as $line) |
|
| 372 | + { |
|
| 273 | 373 | $info = explode(" ",$line); |
| 274 | - if($info[0]=="cpu") { |
|
| 374 | + if($info[0]=="cpu") |
|
| 375 | + { |
|
| 275 | 376 | array_shift($info); // pop off "cpu" |
| 276 | - if(!$info[0]) array_shift($info); // pop off blank space (if any) |
|
| 377 | + if(!$info[0]) |
|
| 378 | + { |
|
| 379 | + array_shift($info); |
|
| 380 | + } |
|
| 381 | + // pop off blank space (if any) |
|
| 277 | 382 | return $info; |
| 278 | 383 | } |
| 279 | 384 | } |
@@ -318,9 +423,13 @@ discard block |
||
| 318 | 423 | function CPULoad() |
| 319 | 424 | { |
| 320 | 425 | $info = $this->_CPULoad(); |
| 321 | - if (!$info) return false; |
|
| 426 | + if (!$info) |
|
| 427 | + { |
|
| 428 | + return false; |
|
| 429 | + } |
|
| 322 | 430 | |
| 323 | - if (empty($this->_lastLoad)) { |
|
| 431 | + if (empty($this->_lastLoad)) |
|
| 432 | + { |
|
| 324 | 433 | sleep(1); |
| 325 | 434 | $this->_lastLoad = $info; |
| 326 | 435 | $info = $this->_CPULoad(); |
@@ -336,12 +445,21 @@ discard block |
||
| 336 | 445 | |
| 337 | 446 | //printf("Delta - User: %f Nice: %f System: %f Idle: %f<br>",$d_user,$d_nice,$d_system,$d_idle); |
| 338 | 447 | |
| 339 | - if (strncmp(PHP_OS,'WIN',3)==0) { |
|
| 340 | - if ($d_idle < 1) $d_idle = 1; |
|
| 448 | + if (strncmp(PHP_OS,'WIN',3)==0) |
|
| 449 | + { |
|
| 450 | + if ($d_idle < 1) |
|
| 451 | + { |
|
| 452 | + $d_idle = 1; |
|
| 453 | + } |
|
| 341 | 454 | return 100*(1-$d_user/$d_idle); |
| 342 | - }else { |
|
| 455 | + } |
|
| 456 | + else |
|
| 457 | + { |
|
| 343 | 458 | $total=$d_user+$d_nice+$d_system+$d_idle; |
| 344 | - if ($total<1) $total=1; |
|
| 459 | + if ($total<1) |
|
| 460 | + { |
|
| 461 | + $total=1; |
|
| 462 | + } |
|
| 345 | 463 | return 100*($d_user+$d_nice+$d_system)/$total; |
| 346 | 464 | } |
| 347 | 465 | } |
@@ -355,7 +473,10 @@ discard block |
||
| 355 | 473 | global $ADODB_FETCH_MODE; |
| 356 | 474 | $save = $ADODB_FETCH_MODE; |
| 357 | 475 | $ADODB_FETCH_MODE = ADODB_FETCH_NUM; |
| 358 | - if ($this->conn->fetchMode !== false) $savem = $this->conn->SetFetchMode(false); |
|
| 476 | + if ($this->conn->fetchMode !== false) |
|
| 477 | + { |
|
| 478 | + $savem = $this->conn->SetFetchMode(false); |
|
| 479 | + } |
|
| 359 | 480 | |
| 360 | 481 | $sqlq = $this->conn->qstr($sql); |
| 361 | 482 | $arr = $this->conn->GetArray( |
@@ -364,14 +485,19 @@ discard block |
||
| 364 | 485 | group by tracer |
| 365 | 486 | order by 1 desc"); |
| 366 | 487 | $s = ''; |
| 367 | - if ($arr) { |
|
| 488 | + if ($arr) |
|
| 489 | + { |
|
| 368 | 490 | $s .= '<h3>Scripts Affected</h3>'; |
| 369 | - foreach($arr as $k) { |
|
| 491 | + foreach($arr as $k) |
|
| 492 | + { |
|
| 370 | 493 | $s .= sprintf("%4d",$k[0]).' '.strip_tags($k[1]).'<br>'; |
| 371 | 494 | } |
| 372 | 495 | } |
| 373 | 496 | |
| 374 | - if (isset($savem)) $this->conn->SetFetchMode($savem); |
|
| 497 | + if (isset($savem)) |
|
| 498 | + { |
|
| 499 | + $this->conn->SetFetchMode($savem); |
|
| 500 | + } |
|
| 375 | 501 | $ADODB_CACHE_MODE = $save; |
| 376 | 502 | $this->conn->fnExecute = $saveE; |
| 377 | 503 | return $s; |
@@ -383,24 +509,30 @@ discard block |
||
| 383 | 509 | actual sql. |
| 384 | 510 | */ |
| 385 | 511 | function Explain($sql,$partial=false) |
| 386 | - { |
|
| 512 | + { |
|
| 387 | 513 | return false; |
| 388 | 514 | } |
| 389 | 515 | |
| 390 | 516 | function InvalidSQL($numsql = 10) |
| 391 | 517 | { |
| 392 | 518 | |
| 393 | - if (isset($_GET['sql'])) return; |
|
| 519 | + if (isset($_GET['sql'])) |
|
| 520 | + { |
|
| 521 | + return; |
|
| 522 | + } |
|
| 394 | 523 | $s = '<h3>Invalid SQL</h3>'; |
| 395 | 524 | $saveE = $this->conn->fnExecute; |
| 396 | 525 | $this->conn->fnExecute = false; |
| 397 | 526 | $perf_table = adodb_perf::table(); |
| 398 | 527 | $rs =& $this->conn->SelectLimit("select distinct count(*),sql1,tracer as error_msg from $perf_table where tracer like 'ERROR:%' group by sql1,tracer order by 1 desc",$numsql);//,$numsql); |
| 399 | 528 | $this->conn->fnExecute = $saveE; |
| 400 | - if ($rs) { |
|
| 529 | + if ($rs) |
|
| 530 | + { |
|
| 401 | 531 | $s .= rs2html($rs,false,false,false,false); |
| 402 | - } else |
|
| 403 | - return "<p>$this->helpurl. ".$this->conn->ErrorMsg()."</p>"; |
|
| 532 | + } |
|
| 533 | + else { |
|
| 534 | + return "<p>$this->helpurl. ".$this->conn->ErrorMsg()."</p>"; |
|
| 535 | + } |
|
| 404 | 536 | |
| 405 | 537 | return $s; |
| 406 | 538 | } |
@@ -417,17 +549,24 @@ discard block |
||
| 417 | 549 | $saveE = $this->conn->fnExecute; |
| 418 | 550 | $this->conn->fnExecute = false; |
| 419 | 551 | |
| 420 | - if (isset($_GET['exps']) && isset($_GET['sql'])) { |
|
| 552 | + if (isset($_GET['exps']) && isset($_GET['sql'])) |
|
| 553 | + { |
|
| 421 | 554 | $partial = !empty($_GET['part']); |
| 422 | 555 | echo "<a name=explain></a>".$this->Explain($_GET['sql'],$partial)."\n"; |
| 423 | 556 | } |
| 424 | 557 | |
| 425 | - if (isset($_GET['sql'])) return; |
|
| 558 | + if (isset($_GET['sql'])) |
|
| 559 | + { |
|
| 560 | + return; |
|
| 561 | + } |
|
| 426 | 562 | $sql1 = $this->sql1; |
| 427 | 563 | |
| 428 | 564 | $save = $ADODB_FETCH_MODE; |
| 429 | 565 | $ADODB_FETCH_MODE = ADODB_FETCH_NUM; |
| 430 | - if ($this->conn->fetchMode !== false) $savem = $this->conn->SetFetchMode(false); |
|
| 566 | + if ($this->conn->fetchMode !== false) |
|
| 567 | + { |
|
| 568 | + $savem = $this->conn->SetFetchMode(false); |
|
| 569 | + } |
|
| 431 | 570 | //$this->conn->debug=1; |
| 432 | 571 | $rs =& $this->conn->SelectLimit( |
| 433 | 572 | "select avg(timer) as avg_timer,$sql1,count(*),max(timer) as max_timer,min(timer) as min_timer |
@@ -436,25 +575,34 @@ discard block |
||
| 436 | 575 | and (tracer is null or tracer not like 'ERROR:%') |
| 437 | 576 | group by sql1 |
| 438 | 577 | order by 1 desc",$numsql); |
| 439 | - if (isset($savem)) $this->conn->SetFetchMode($savem); |
|
| 578 | + if (isset($savem)) |
|
| 579 | + { |
|
| 580 | + $this->conn->SetFetchMode($savem); |
|
| 581 | + } |
|
| 440 | 582 | $ADODB_FETCH_MODE = $save; |
| 441 | 583 | $this->conn->fnExecute = $saveE; |
| 442 | 584 | |
| 443 | - if (!$rs) return "<p>$this->helpurl. ".$this->conn->ErrorMsg()."</p>"; |
|
| 585 | + if (!$rs) |
|
| 586 | + { |
|
| 587 | + return "<p>$this->helpurl. ".$this->conn->ErrorMsg()."</p>"; |
|
| 588 | + } |
|
| 444 | 589 | $s = "<h3>Suspicious SQL</h3> |
| 445 | 590 | <font size=1>The following SQL have high average execution times</font><br> |
| 446 | 591 | <table border=1 bgcolor=white><tr><td><b>Avg Time</b><td><b>Count</b><td><b>SQL</b><td><b>Max</b><td><b>Min</b></tr>\n"; |
| 447 | 592 | $max = $this->maxLength; |
| 448 | - while (!$rs->EOF) { |
|
| 593 | + while (!$rs->EOF) |
|
| 594 | + { |
|
| 449 | 595 | $sql = $rs->fields[1]; |
| 450 | 596 | $raw = urlencode($sql); |
| 451 | - if (strlen($raw)>$max-100) { |
|
| 597 | + if (strlen($raw)>$max-100) |
|
| 598 | + { |
|
| 452 | 599 | $sql2 = substr($sql,0,$max-500); |
| 453 | 600 | $raw = urlencode($sql2).'&part='.crc32($sql); |
| 454 | 601 | } |
| 455 | 602 | $prefix = "<a target=sql".rand()." href=\"?hidem=1&exps=1&sql=".$raw."&x#explain\">"; |
| 456 | 603 | $suffix = "</a>"; |
| 457 | - if ($this->explain == false || strlen($prefix)>$max) { |
|
| 604 | + if ($this->explain == false || strlen($prefix)>$max) |
|
| 605 | + { |
|
| 458 | 606 | $suffix = ' ... <i>String too long for GET parameter: '.strlen($prefix).'</i>'; |
| 459 | 607 | $prefix = ''; |
| 460 | 608 | } |
@@ -496,17 +644,24 @@ discard block |
||
| 496 | 644 | $saveE = $this->conn->fnExecute; |
| 497 | 645 | $this->conn->fnExecute = false; |
| 498 | 646 | |
| 499 | - if (isset($_GET['expe']) && isset($_GET['sql'])) { |
|
| 647 | + if (isset($_GET['expe']) && isset($_GET['sql'])) |
|
| 648 | + { |
|
| 500 | 649 | $partial = !empty($_GET['part']); |
| 501 | 650 | echo "<a name=explain></a>".$this->Explain($_GET['sql'],$partial)."\n"; |
| 502 | 651 | } |
| 503 | 652 | |
| 504 | - if (isset($_GET['sql'])) return; |
|
| 653 | + if (isset($_GET['sql'])) |
|
| 654 | + { |
|
| 655 | + return; |
|
| 656 | + } |
|
| 505 | 657 | |
| 506 | 658 | $sql1 = $this->sql1; |
| 507 | 659 | $save = $ADODB_FETCH_MODE; |
| 508 | 660 | $ADODB_FETCH_MODE = ADODB_FETCH_NUM; |
| 509 | - if ($this->conn->fetchMode !== false) $savem = $this->conn->SetFetchMode(false); |
|
| 661 | + if ($this->conn->fetchMode !== false) |
|
| 662 | + { |
|
| 663 | + $savem = $this->conn->SetFetchMode(false); |
|
| 664 | + } |
|
| 510 | 665 | |
| 511 | 666 | $rs =& $this->conn->SelectLimit( |
| 512 | 667 | "select sum(timer) as total,$sql1,count(*),max(timer) as max_timer,min(timer) as min_timer |
@@ -516,24 +671,33 @@ discard block |
||
| 516 | 671 | group by sql1 |
| 517 | 672 | having count(*)>1 |
| 518 | 673 | order by 1 desc",$numsql); |
| 519 | - if (isset($savem)) $this->conn->SetFetchMode($savem); |
|
| 674 | + if (isset($savem)) |
|
| 675 | + { |
|
| 676 | + $this->conn->SetFetchMode($savem); |
|
| 677 | + } |
|
| 520 | 678 | $this->conn->fnExecute = $saveE; |
| 521 | 679 | $ADODB_FETCH_MODE = $save; |
| 522 | - if (!$rs) return "<p>$this->helpurl. ".$this->conn->ErrorMsg()."</p>"; |
|
| 680 | + if (!$rs) |
|
| 681 | + { |
|
| 682 | + return "<p>$this->helpurl. ".$this->conn->ErrorMsg()."</p>"; |
|
| 683 | + } |
|
| 523 | 684 | $s = "<h3>Expensive SQL</h3> |
| 524 | 685 | <font size=1>Tuning the following SQL could reduce the server load substantially</font><br> |
| 525 | 686 | <table border=1 bgcolor=white><tr><td><b>Load</b><td><b>Count</b><td><b>SQL</b><td><b>Max</b><td><b>Min</b></tr>\n"; |
| 526 | 687 | $max = $this->maxLength; |
| 527 | - while (!$rs->EOF) { |
|
| 688 | + while (!$rs->EOF) |
|
| 689 | + { |
|
| 528 | 690 | $sql = $rs->fields[1]; |
| 529 | 691 | $raw = urlencode($sql); |
| 530 | - if (strlen($raw)>$max-100) { |
|
| 692 | + if (strlen($raw)>$max-100) |
|
| 693 | + { |
|
| 531 | 694 | $sql2 = substr($sql,0,$max-500); |
| 532 | 695 | $raw = urlencode($sql2).'&part='.crc32($sql); |
| 533 | 696 | } |
| 534 | 697 | $prefix = "<a target=sqle".rand()." href=\"?hidem=1&expe=1&sql=".$raw."&x#explain\">"; |
| 535 | 698 | $suffix = "</a>"; |
| 536 | - if($this->explain == false || strlen($prefix>$max)) { |
|
| 699 | + if($this->explain == false || strlen($prefix>$max)) |
|
| 700 | + { |
|
| 537 | 701 | $prefix = ''; |
| 538 | 702 | $suffix = ''; |
| 539 | 703 | } |
@@ -549,7 +713,10 @@ discard block |
||
| 549 | 713 | */ |
| 550 | 714 | function DBParameter($param) |
| 551 | 715 | { |
| 552 | - if (empty($this->settings[$param])) return false; |
|
| 716 | + if (empty($this->settings[$param])) |
|
| 717 | + { |
|
| 718 | + return false; |
|
| 719 | + } |
|
| 553 | 720 | $sql = $this->settings[$param][1]; |
| 554 | 721 | return $this->_DBParameter($sql); |
| 555 | 722 | } |
@@ -572,30 +739,53 @@ discard block |
||
| 572 | 739 | function _DBParameter($sql) |
| 573 | 740 | { |
| 574 | 741 | $savelog = $this->conn->LogSQL(false); |
| 575 | - if (is_array($sql)) { |
|
| 742 | + if (is_array($sql)) |
|
| 743 | + { |
|
| 576 | 744 | global $ADODB_FETCH_MODE; |
| 577 | 745 | |
| 578 | 746 | $sql1 = $sql[0]; |
| 579 | 747 | $key = $sql[1]; |
| 580 | - if (sizeof($sql)>2) $pos = $sql[2]; |
|
| 581 | - else $pos = 1; |
|
| 582 | - if (sizeof($sql)>3) $coef = $sql[3]; |
|
| 583 | - else $coef = false; |
|
| 748 | + if (sizeof($sql)>2) |
|
| 749 | + { |
|
| 750 | + $pos = $sql[2]; |
|
| 751 | + } |
|
| 752 | + else { |
|
| 753 | + $pos = 1; |
|
| 754 | + } |
|
| 755 | + if (sizeof($sql)>3) |
|
| 756 | + { |
|
| 757 | + $coef = $sql[3]; |
|
| 758 | + } |
|
| 759 | + else { |
|
| 760 | + $coef = false; |
|
| 761 | + } |
|
| 584 | 762 | $ret = false; |
| 585 | 763 | $save = $ADODB_FETCH_MODE; |
| 586 | 764 | $ADODB_FETCH_MODE = ADODB_FETCH_NUM; |
| 587 | - if ($this->conn->fetchMode !== false) $savem = $this->conn->SetFetchMode(false); |
|
| 765 | + if ($this->conn->fetchMode !== false) |
|
| 766 | + { |
|
| 767 | + $savem = $this->conn->SetFetchMode(false); |
|
| 768 | + } |
|
| 588 | 769 | |
| 589 | 770 | $rs = $this->conn->Execute($sql1); |
| 590 | 771 | |
| 591 | - if (isset($savem)) $this->SetFetchMode($savem); |
|
| 772 | + if (isset($savem)) |
|
| 773 | + { |
|
| 774 | + $this->SetFetchMode($savem); |
|
| 775 | + } |
|
| 592 | 776 | $ADODB_FETCH_MODE = $save; |
| 593 | - if ($rs) { |
|
| 594 | - while (!$rs->EOF) { |
|
| 777 | + if ($rs) |
|
| 778 | + { |
|
| 779 | + while (!$rs->EOF) |
|
| 780 | + { |
|
| 595 | 781 | $keyf = reset($rs->fields); |
| 596 | - if (trim($keyf) == $key) { |
|
| 782 | + if (trim($keyf) == $key) |
|
| 783 | + { |
|
| 597 | 784 | $ret = $rs->fields[$pos]; |
| 598 | - if ($coef) $ret *= $coef; |
|
| 785 | + if ($coef) |
|
| 786 | + { |
|
| 787 | + $ret *= $coef; |
|
| 788 | + } |
|
| 599 | 789 | break; |
| 600 | 790 | } |
| 601 | 791 | $rs->MoveNext(); |
@@ -604,8 +794,11 @@ discard block |
||
| 604 | 794 | } |
| 605 | 795 | $this->conn->LogSQL($savelog); |
| 606 | 796 | return $ret; |
| 607 | - } else { |
|
| 608 | - if (strncmp($sql,'=',1) == 0) { |
|
| 797 | + } |
|
| 798 | + else |
|
| 799 | + { |
|
| 800 | + if (strncmp($sql,'=',1) == 0) |
|
| 801 | + { |
|
| 609 | 802 | $fn = substr($sql,1); |
| 610 | 803 | return $this->$fn(); |
| 611 | 804 | } |
@@ -622,9 +815,13 @@ discard block |
||
| 622 | 815 | */ |
| 623 | 816 | function WarnCacheRatio($val) |
| 624 | 817 | { |
| 625 | - if ($val < $this->warnRatio) |
|
| 626 | - return '<font color=red><b>Cache ratio should be at least '.$this->warnRatio.'%</b></font>'; |
|
| 627 | - else return ''; |
|
| 818 | + if ($val < $this->warnRatio) |
|
| 819 | + { |
|
| 820 | + return '<font color=red><b>Cache ratio should be at least '.$this->warnRatio.'%</b></font>'; |
|
| 821 | + } |
|
| 822 | + else { |
|
| 823 | + return ''; |
|
| 824 | + } |
|
| 628 | 825 | } |
| 629 | 826 | |
| 630 | 827 | /***********************************************************************************************/ |
@@ -639,54 +836,90 @@ discard block |
||
| 639 | 836 | $conn = $this->conn; |
| 640 | 837 | |
| 641 | 838 | $app = $conn->host; |
| 642 | - if ($conn->host && $conn->database) $app .= ', db='; |
|
| 839 | + if ($conn->host && $conn->database) |
|
| 840 | + { |
|
| 841 | + $app .= ', db='; |
|
| 842 | + } |
|
| 643 | 843 | $app .= $conn->database; |
| 644 | 844 | |
| 645 | - if ($app) $app .= ', '; |
|
| 845 | + if ($app) |
|
| 846 | + { |
|
| 847 | + $app .= ', '; |
|
| 848 | + } |
|
| 646 | 849 | $savelog = $this->conn->LogSQL(false); |
| 647 | 850 | $info = $conn->ServerInfo(); |
| 648 | - if (isset($_GET['clearsql'])) { |
|
| 851 | + if (isset($_GET['clearsql'])) |
|
| 852 | + { |
|
| 649 | 853 | $this->conn->Execute("delete from $perf_table"); |
| 650 | 854 | } |
| 651 | 855 | $this->conn->LogSQL($savelog); |
| 652 | 856 | |
| 653 | 857 | // magic quotes |
| 654 | 858 | |
| 655 | - if (isset($_GET['sql']) && get_magic_quotes_gpc()) { |
|
| 859 | + if (isset($_GET['sql']) && get_magic_quotes_gpc()) |
|
| 860 | + { |
|
| 656 | 861 | $_GET['sql'] = $_GET['sql'] = str_replace(array("\\'",'\"'),array("'",'"'),$_GET['sql']); |
| 657 | 862 | } |
| 658 | 863 | |
| 659 | - if (!isset($_SESSION['ADODB_PERF_SQL'])) $nsql = $_SESSION['ADODB_PERF_SQL'] = 10; |
|
| 660 | - else $nsql = $_SESSION['ADODB_PERF_SQL']; |
|
| 864 | + if (!isset($_SESSION['ADODB_PERF_SQL'])) |
|
| 865 | + { |
|
| 866 | + $nsql = $_SESSION['ADODB_PERF_SQL'] = 10; |
|
| 867 | + } |
|
| 868 | + else { |
|
| 869 | + $nsql = $_SESSION['ADODB_PERF_SQL']; |
|
| 870 | + } |
|
| 661 | 871 | |
| 662 | 872 | $app .= $info['description']; |
| 663 | 873 | |
| 664 | 874 | |
| 665 | - if (isset($_GET['do'])) $do = $_GET['do']; |
|
| 666 | - else if (isset($_POST['do'])) $do = $_POST['do']; |
|
| 667 | - else if (isset($_GET['sql'])) $do = 'viewsql'; |
|
| 668 | - else $do = 'stats'; |
|
| 875 | + if (isset($_GET['do'])) |
|
| 876 | + { |
|
| 877 | + $do = $_GET['do']; |
|
| 878 | + } |
|
| 879 | + else if (isset($_POST['do'])) |
|
| 880 | + { |
|
| 881 | + $do = $_POST['do']; |
|
| 882 | + } |
|
| 883 | + else if (isset($_GET['sql'])) |
|
| 884 | + { |
|
| 885 | + $do = 'viewsql'; |
|
| 886 | + } |
|
| 887 | + else { |
|
| 888 | + $do = 'stats'; |
|
| 889 | + } |
|
| 669 | 890 | |
| 670 | - if (isset($_GET['nsql'])) { |
|
| 671 | - if ($_GET['nsql'] > 0) $nsql = $_SESSION['ADODB_PERF_SQL'] = (integer) $_GET['nsql']; |
|
| 891 | + if (isset($_GET['nsql'])) |
|
| 892 | + { |
|
| 893 | + if ($_GET['nsql'] > 0) |
|
| 894 | + { |
|
| 895 | + $nsql = $_SESSION['ADODB_PERF_SQL'] = (integer) $_GET['nsql']; |
|
| 896 | + } |
|
| 672 | 897 | } |
| 673 | 898 | echo "<title>ADOdb Performance Monitor on $app</title><body bgcolor=white>"; |
| 674 | - if ($do == 'viewsql') $form = "<td><form># SQL:<input type=hidden value=viewsql name=do> <input type=text size=4 name=nsql value=$nsql><input type=submit value=Go></td></form>"; |
|
| 675 | - else $form = "<td> </td>"; |
|
| 899 | + if ($do == 'viewsql') |
|
| 900 | + { |
|
| 901 | + $form = "<td><form># SQL:<input type=hidden value=viewsql name=do> <input type=text size=4 name=nsql value=$nsql><input type=submit value=Go></td></form>"; |
|
| 902 | + } |
|
| 903 | + else { |
|
| 904 | + $form = "<td> </td>"; |
|
| 905 | + } |
|
| 676 | 906 | |
| 677 | 907 | $allowsql = !defined('ADODB_PERF_NO_RUN_SQL'); |
| 678 | 908 | |
| 679 | 909 | if (empty($_GET['hidem'])) |
| 680 | - echo "<table border=1 width=100% bgcolor=lightyellow><tr><td colspan=2> |
|
| 910 | + { |
|
| 911 | + echo "<table border=1 width=100% bgcolor=lightyellow><tr><td colspan=2> |
|
| 681 | 912 | <b><a href=http://adodb.sourceforge.net/?perf=1>ADOdb</a> Performance Monitor</b> <font size=1>for $app</font></tr><tr><td> |
| 682 | 913 | <a href=?do=stats><b>Performance Stats</b></a> <a href=?do=viewsql><b>View SQL</b></a> |
| 683 | 914 | <a href=?do=tables><b>View Tables</b></a> <a href=?do=poll><b>Poll Stats</b></a>", |
| 684 | 915 | $allowsql ? ' <a href=?do=dosql><b>Run SQL</b></a>' : '', |
| 685 | 916 | "$form", |
| 686 | 917 | "</tr></table>"; |
| 918 | + } |
|
| 687 | 919 | |
| 688 | 920 | |
| 689 | - switch ($do) { |
|
| 921 | + switch ($do) |
|
| 922 | + { |
|
| 690 | 923 | default: |
| 691 | 924 | case 'stats': |
| 692 | 925 | echo $this->HealthCheck(); |
@@ -703,13 +936,18 @@ discard block |
||
| 703 | 936 | break; |
| 704 | 937 | |
| 705 | 938 | case 'dosql': |
| 706 | - if (!$allowsql) break; |
|
| 939 | + if (!$allowsql) |
|
| 940 | + { |
|
| 941 | + break; |
|
| 942 | + } |
|
| 707 | 943 | |
| 708 | 944 | $this->DoSQLForm(); |
| 709 | 945 | break; |
| 710 | 946 | case 'viewsql': |
| 711 | 947 | if (empty($_GET['hidem'])) |
| 712 | - echo " <a href=\"?do=viewsql&clearsql=1\">Clear SQL Log</a><br>"; |
|
| 948 | + { |
|
| 949 | + echo " <a href=\"?do=viewsql&clearsql=1\">Clear SQL Log</a><br>"; |
|
| 950 | + } |
|
| 713 | 951 | echo($this->SuspiciousSQL($nsql)); |
| 714 | 952 | echo($this->ExpensiveSQL($nsql)); |
| 715 | 953 | echo($this->InvalidSQL($nsql)); |
@@ -728,13 +966,17 @@ discard block |
||
| 728 | 966 | { |
| 729 | 967 | $this->conn->fnExecute = false; |
| 730 | 968 | //$this->conn->debug=1; |
| 731 | - if ($secs <= 1) $secs = 1; |
|
| 969 | + if ($secs <= 1) |
|
| 970 | + { |
|
| 971 | + $secs = 1; |
|
| 972 | + } |
|
| 732 | 973 | echo "Accumulating statistics, every $secs seconds...\n";flush(); |
| 733 | 974 | $arro =& $this->PollParameters(); |
| 734 | 975 | $cnt = 0; |
| 735 | 976 | set_time_limit(0); |
| 736 | 977 | sleep($secs); |
| 737 | - while (1) { |
|
| 978 | + while (1) |
|
| 979 | + { |
|
| 738 | 980 | |
| 739 | 981 | $arr =& $this->PollParameters(); |
| 740 | 982 | |
@@ -744,19 +986,28 @@ discard block |
||
| 744 | 986 | $sess = sprintf('%5d',$arr[3]); |
| 745 | 987 | |
| 746 | 988 | $load = $this->CPULoad(); |
| 747 | - if ($load !== false) { |
|
| 989 | + if ($load !== false) |
|
| 990 | + { |
|
| 748 | 991 | $oslabel = 'WS-CPU%'; |
| 749 | 992 | $osval = sprintf(" %2.1f ",(float) $load); |
| 750 | - }else { |
|
| 993 | + } |
|
| 994 | + else |
|
| 995 | + { |
|
| 751 | 996 | $oslabel = ''; |
| 752 | 997 | $osval = ''; |
| 753 | 998 | } |
| 754 | - if ($cnt % 10 == 0) echo " Time ".$oslabel." Hit% Sess Reads/s Writes/s\n"; |
|
| 999 | + if ($cnt % 10 == 0) |
|
| 1000 | + { |
|
| 1001 | + echo " Time ".$oslabel." Hit% Sess Reads/s Writes/s\n"; |
|
| 1002 | + } |
|
| 755 | 1003 | $cnt += 1; |
| 756 | 1004 | echo date('H:i:s').' '.$osval."$hits $sess $reads $writes\n"; |
| 757 | 1005 | flush(); |
| 758 | 1006 | |
| 759 | - if (connection_aborted()) return; |
|
| 1007 | + if (connection_aborted()) |
|
| 1008 | + { |
|
| 1009 | + return; |
|
| 1010 | + } |
|
| 760 | 1011 | |
| 761 | 1012 | sleep($secs); |
| 762 | 1013 | $arro = $arr; |
@@ -779,66 +1030,113 @@ discard block |
||
| 779 | 1030 | { |
| 780 | 1031 | $saveE = $this->conn->fnExecute; |
| 781 | 1032 | $this->conn->fnExecute = false; |
| 782 | - if ($cli) $html = ''; |
|
| 783 | - else $html = $this->table.'<tr><td colspan=3><h3>'.$this->conn->databaseType.'</h3></td></tr>'.$this->titles; |
|
| 1033 | + if ($cli) |
|
| 1034 | + { |
|
| 1035 | + $html = ''; |
|
| 1036 | + } |
|
| 1037 | + else { |
|
| 1038 | + $html = $this->table.'<tr><td colspan=3><h3>'.$this->conn->databaseType.'</h3></td></tr>'.$this->titles; |
|
| 1039 | + } |
|
| 784 | 1040 | |
| 785 | 1041 | $oldc = false; |
| 786 | 1042 | $bgc = ''; |
| 787 | - foreach($this->settings as $name => $arr) { |
|
| 788 | - if ($arr === false) break; |
|
| 1043 | + foreach($this->settings as $name => $arr) |
|
| 1044 | + { |
|
| 1045 | + if ($arr === false) |
|
| 1046 | + { |
|
| 1047 | + break; |
|
| 1048 | + } |
|
| 789 | 1049 | |
| 790 | - if (!is_string($name)) { |
|
| 791 | - if ($cli) $html .= " -- $arr -- \n"; |
|
| 792 | - else $html .= "<tr bgcolor=$this->color><td colspan=3><i>$arr</i> </td></tr>"; |
|
| 1050 | + if (!is_string($name)) |
|
| 1051 | + { |
|
| 1052 | + if ($cli) |
|
| 1053 | + { |
|
| 1054 | + $html .= " -- $arr -- \n"; |
|
| 1055 | + } |
|
| 1056 | + else { |
|
| 1057 | + $html .= "<tr bgcolor=$this->color><td colspan=3><i>$arr</i> </td></tr>"; |
|
| 1058 | + } |
|
| 793 | 1059 | continue; |
| 794 | 1060 | } |
| 795 | 1061 | |
| 796 | - if (!is_array($arr)) break; |
|
| 1062 | + if (!is_array($arr)) |
|
| 1063 | + { |
|
| 1064 | + break; |
|
| 1065 | + } |
|
| 797 | 1066 | $category = $arr[0]; |
| 798 | 1067 | $how = $arr[1]; |
| 799 | - if (sizeof($arr)>2) $desc = $arr[2]; |
|
| 800 | - else $desc = ' '; |
|
| 1068 | + if (sizeof($arr)>2) |
|
| 1069 | + { |
|
| 1070 | + $desc = $arr[2]; |
|
| 1071 | + } |
|
| 1072 | + else { |
|
| 1073 | + $desc = ' '; |
|
| 1074 | + } |
|
| 801 | 1075 | |
| 802 | 1076 | |
| 803 | - if ($category == 'HIDE') continue; |
|
| 1077 | + if ($category == 'HIDE') |
|
| 1078 | + { |
|
| 1079 | + continue; |
|
| 1080 | + } |
|
| 804 | 1081 | |
| 805 | 1082 | $val = $this->_DBParameter($how); |
| 806 | 1083 | |
| 807 | - if ($desc && strncmp($desc,"=",1) === 0) { |
|
| 1084 | + if ($desc && strncmp($desc,"=",1) === 0) |
|
| 1085 | + { |
|
| 808 | 1086 | $fn = substr($desc,1); |
| 809 | 1087 | $desc = $this->$fn($val); |
| 810 | 1088 | } |
| 811 | 1089 | |
| 812 | - if ($val === false) { |
|
| 1090 | + if ($val === false) |
|
| 1091 | + { |
|
| 813 | 1092 | $m = $this->conn->ErrorMsg(); |
| 814 | 1093 | $val = "Error: $m"; |
| 815 | - } else { |
|
| 816 | - if (is_numeric($val) && $val >= 256*1024) { |
|
| 817 | - if ($val % (1024*1024) == 0) { |
|
| 1094 | + } |
|
| 1095 | + else |
|
| 1096 | + { |
|
| 1097 | + if (is_numeric($val) && $val >= 256*1024) |
|
| 1098 | + { |
|
| 1099 | + if ($val % (1024*1024) == 0) |
|
| 1100 | + { |
|
| 818 | 1101 | $val /= (1024*1024); |
| 819 | 1102 | $val .= 'M'; |
| 820 | - } else if ($val % 1024 == 0) { |
|
| 1103 | + } |
|
| 1104 | + else if ($val % 1024 == 0) |
|
| 1105 | + { |
|
| 821 | 1106 | $val /= 1024; |
| 822 | 1107 | $val .= 'K'; |
| 823 | 1108 | } |
| 824 | 1109 | //$val = htmlspecialchars($val); |
| 825 | 1110 | } |
| 826 | 1111 | } |
| 827 | - if ($category != $oldc) { |
|
| 1112 | + if ($category != $oldc) |
|
| 1113 | + { |
|
| 828 | 1114 | $oldc = $category; |
| 829 | 1115 | //$bgc = ($bgc == ' bgcolor='.$this->color) ? ' bgcolor=white' : ' bgcolor='.$this->color; |
| 830 | 1116 | } |
| 831 | - if (strlen($desc)==0) $desc = ' '; |
|
| 832 | - if (strlen($val)==0) $val = ' '; |
|
| 833 | - if ($cli) { |
|
| 1117 | + if (strlen($desc)==0) |
|
| 1118 | + { |
|
| 1119 | + $desc = ' '; |
|
| 1120 | + } |
|
| 1121 | + if (strlen($val)==0) |
|
| 1122 | + { |
|
| 1123 | + $val = ' '; |
|
| 1124 | + } |
|
| 1125 | + if ($cli) |
|
| 1126 | + { |
|
| 834 | 1127 | $html .= str_replace(' ','',sprintf($this->cliFormat,strip_tags($name),strip_tags($val),strip_tags($desc))); |
| 835 | 1128 | |
| 836 | - }else { |
|
| 1129 | + } |
|
| 1130 | + else |
|
| 1131 | + { |
|
| 837 | 1132 | $html .= "<tr$bgc><td>".$name.'</td><td>'.$val.'</td><td>'.$desc."</td></tr>\n"; |
| 838 | 1133 | } |
| 839 | 1134 | } |
| 840 | 1135 | |
| 841 | - if (!$cli) $html .= "</table>\n"; |
|
| 1136 | + if (!$cli) |
|
| 1137 | + { |
|
| 1138 | + $html .= "</table>\n"; |
|
| 1139 | + } |
|
| 842 | 1140 | $this->conn->fnExecute = $saveE; |
| 843 | 1141 | |
| 844 | 1142 | return $html; |
@@ -846,7 +1144,10 @@ discard block |
||
| 846 | 1144 | |
| 847 | 1145 | function Tables($orderby='1') |
| 848 | 1146 | { |
| 849 | - if (!$this->tablesSQL) return false; |
|
| 1147 | + if (!$this->tablesSQL) |
|
| 1148 | + { |
|
| 1149 | + return false; |
|
| 1150 | + } |
|
| 850 | 1151 | |
| 851 | 1152 | $savelog = $this->conn->LogSQL(false); |
| 852 | 1153 | $rs = $this->conn->Execute($this->tablesSQL.' order by '.$orderby); |
@@ -858,7 +1159,10 @@ discard block |
||
| 858 | 1159 | |
| 859 | 1160 | function CreateLogTable() |
| 860 | 1161 | { |
| 861 | - if (!$this->createTableSQL) return false; |
|
| 1162 | + if (!$this->createTableSQL) |
|
| 1163 | + { |
|
| 1164 | + return false; |
|
| 1165 | + } |
|
| 862 | 1166 | |
| 863 | 1167 | $savelog = $this->conn->LogSQL(false); |
| 864 | 1168 | $ok = $this->conn->Execute($this->createTableSQL); |
@@ -873,15 +1177,25 @@ discard block |
||
| 873 | 1177 | $PHP_SELF = $_SERVER['PHP_SELF']; |
| 874 | 1178 | $sql = isset($_REQUEST['sql']) ? $_REQUEST['sql'] : ''; |
| 875 | 1179 | |
| 876 | - if (isset($_SESSION['phplens_sqlrows'])) $rows = $_SESSION['phplens_sqlrows']; |
|
| 877 | - else $rows = 3; |
|
| 1180 | + if (isset($_SESSION['phplens_sqlrows'])) |
|
| 1181 | + { |
|
| 1182 | + $rows = $_SESSION['phplens_sqlrows']; |
|
| 1183 | + } |
|
| 1184 | + else { |
|
| 1185 | + $rows = 3; |
|
| 1186 | + } |
|
| 878 | 1187 | |
| 879 | - if (isset($_REQUEST['SMALLER'])) { |
|
| 1188 | + if (isset($_REQUEST['SMALLER'])) |
|
| 1189 | + { |
|
| 880 | 1190 | $rows /= 2; |
| 881 | - if ($rows < 3) $rows = 3; |
|
| 1191 | + if ($rows < 3) |
|
| 1192 | + { |
|
| 1193 | + $rows = 3; |
|
| 1194 | + } |
|
| 882 | 1195 | $_SESSION['phplens_sqlrows'] = $rows; |
| 883 | 1196 | } |
| 884 | - if (isset($_REQUEST['BIGGER'])) { |
|
| 1197 | + if (isset($_REQUEST['BIGGER'])) |
|
| 1198 | + { |
|
| 885 | 1199 | $rows *= 2; |
| 886 | 1200 | $_SESSION['phplens_sqlrows'] = $rows; |
| 887 | 1201 | } |
@@ -903,40 +1217,62 @@ discard block |
||
| 903 | 1217 | </form> |
| 904 | 1218 | |
| 905 | 1219 | <?php |
| 906 | - if (!isset($_REQUEST['sql'])) return; |
|
| 1220 | + if (!isset($_REQUEST['sql'])) |
|
| 1221 | + { |
|
| 1222 | + return; |
|
| 1223 | + } |
|
| 907 | 1224 | |
| 908 | 1225 | $sql = $this->undomq(trim($sql)); |
| 909 | - if (substr($sql,strlen($sql)-1) === ';') { |
|
| 1226 | + if (substr($sql,strlen($sql)-1) === ';') |
|
| 1227 | + { |
|
| 910 | 1228 | $print = true; |
| 911 | 1229 | $sqla = $this->SplitSQL($sql); |
| 912 | - } else { |
|
| 1230 | + } |
|
| 1231 | + else |
|
| 1232 | + { |
|
| 913 | 1233 | $print = false; |
| 914 | 1234 | $sqla = array($sql); |
| 915 | 1235 | } |
| 916 | - foreach($sqla as $sqls) { |
|
| 1236 | + foreach($sqla as $sqls) |
|
| 1237 | + { |
|
| 917 | 1238 | |
| 918 | - if (!$sqls) continue; |
|
| 1239 | + if (!$sqls) |
|
| 1240 | + { |
|
| 1241 | + continue; |
|
| 1242 | + } |
|
| 919 | 1243 | |
| 920 | - if ($print) { |
|
| 1244 | + if ($print) |
|
| 1245 | + { |
|
| 921 | 1246 | print "<p>".htmlspecialchars($sqls)."</p>"; |
| 922 | 1247 | flush(); |
| 923 | 1248 | } |
| 924 | 1249 | $savelog = $this->conn->LogSQL(false); |
| 925 | 1250 | $rs = $this->conn->Execute($sqls); |
| 926 | 1251 | $this->conn->LogSQL($savelog); |
| 927 | - if ($rs && is_object($rs) && !$rs->EOF) { |
|
| 1252 | + if ($rs && is_object($rs) && !$rs->EOF) |
|
| 1253 | + { |
|
| 928 | 1254 | rs2html($rs); |
| 929 | - while ($rs->NextRecordSet()) { |
|
| 1255 | + while ($rs->NextRecordSet()) |
|
| 1256 | + { |
|
| 930 | 1257 | print "<table width=98% bgcolor=#C0C0FF><tr><td> </td></tr></table>"; |
| 931 | 1258 | rs2html($rs); |
| 932 | 1259 | } |
| 933 | - } else { |
|
| 1260 | + } |
|
| 1261 | + else |
|
| 1262 | + { |
|
| 934 | 1263 | $e1 = (integer) $this->conn->ErrorNo(); |
| 935 | 1264 | $e2 = $this->conn->ErrorMsg(); |
| 936 | - if (($e1) || ($e2)) { |
|
| 937 | - if (empty($e1)) $e1 = '-1'; // postgresql fix |
|
| 1265 | + if (($e1) || ($e2)) |
|
| 1266 | + { |
|
| 1267 | + if (empty($e1)) |
|
| 1268 | + { |
|
| 1269 | + $e1 = '-1'; |
|
| 1270 | + } |
|
| 1271 | + // postgresql fix |
|
| 938 | 1272 | print ' '.$e1.': '.$e2; |
| 939 | - } else { |
|
| 1273 | + } |
|
| 1274 | + else |
|
| 1275 | + { |
|
| 940 | 1276 | print "<p>No Recordset returned<br></p>"; |
| 941 | 1277 | } |
| 942 | 1278 | } |
@@ -949,9 +1285,10 @@ discard block |
||
| 949 | 1285 | return $arr; |
| 950 | 1286 | } |
| 951 | 1287 | |
| 952 | - function undomq(&$m) |
|
| 1288 | + function undomq(&$m) |
|
| 1289 | + { |
|
| 1290 | + if (get_magic_quotes_gpc()) |
|
| 953 | 1291 | { |
| 954 | - if (get_magic_quotes_gpc()) { |
|
| 955 | 1292 | // undo the damage |
| 956 | 1293 | $m = str_replace('\\\\','\\',$m); |
| 957 | 1294 | $m = str_replace('\"','"',$m); |
@@ -991,16 +1328,21 @@ discard block |
||
| 991 | 1328 | $args = func_get_args(); |
| 992 | 1329 | $numArgs = func_num_args(); |
| 993 | 1330 | |
| 994 | - if ( $numArgs == 0) return false; |
|
| 1331 | + if ( $numArgs == 0) |
|
| 1332 | + { |
|
| 1333 | + return false; |
|
| 1334 | + } |
|
| 995 | 1335 | |
| 996 | 1336 | $mode = ADODB_OPT_LOW; |
| 997 | 1337 | $lastArg = $args[ $numArgs - 1]; |
| 998 | - if ( !is_string($lastArg)) { |
|
| 1338 | + if ( !is_string($lastArg)) |
|
| 1339 | + { |
|
| 999 | 1340 | $mode = $lastArg; |
| 1000 | 1341 | unset( $args[ $numArgs - 1]); |
| 1001 | 1342 | } |
| 1002 | 1343 | |
| 1003 | - foreach( $args as $table) { |
|
| 1344 | + foreach( $args as $table) |
|
| 1345 | + { |
|
| 1004 | 1346 | $this->optimizeTable( $table, $mode); |
| 1005 | 1347 | } |
| 1006 | 1348 | } |
@@ -1017,7 +1359,7 @@ discard block |
||
| 1017 | 1359 | * @author Markus Staab |
| 1018 | 1360 | * @return Returns <code>true</code> on success and <code>false</code> on error |
| 1019 | 1361 | */ |
| 1020 | - function OptimizeTable( $table, $mode = ADODB_OPT_LOW) |
|
| 1362 | + function OptimizeTable( $table, $mode = ADODB_OPT_LOW) |
|
| 1021 | 1363 | { |
| 1022 | 1364 | ADOConnection::outp( sprintf( "<p>%s: '%s' not implemented for driver '%s'</p>", __CLASS__, __FUNCTION__, $this->conn->databaseType)); |
| 1023 | 1365 | return false; |
@@ -1031,16 +1373,24 @@ discard block |
||
| 1031 | 1373 | * @author Markus Staab |
| 1032 | 1374 | * @return Returns <code>true</code> on success and <code>false</code> on error |
| 1033 | 1375 | */ |
| 1034 | - function optimizeDatabase() |
|
| 1376 | + function optimizeDatabase() |
|
| 1035 | 1377 | { |
| 1036 | 1378 | $conn = $this->conn; |
| 1037 | - if ( !$conn) return false; |
|
| 1379 | + if ( !$conn) |
|
| 1380 | + { |
|
| 1381 | + return false; |
|
| 1382 | + } |
|
| 1038 | 1383 | |
| 1039 | 1384 | $tables = $conn->MetaTables( 'TABLES'); |
| 1040 | - if ( !$tables ) return false; |
|
| 1385 | + if ( !$tables ) |
|
| 1386 | + { |
|
| 1387 | + return false; |
|
| 1388 | + } |
|
| 1041 | 1389 | |
| 1042 | - foreach( $tables as $table) { |
|
| 1043 | - if ( !$this->optimizeTable( $table)) { |
|
| 1390 | + foreach( $tables as $table) |
|
| 1391 | + { |
|
| 1392 | + if ( !$this->optimizeTable( $table)) |
|
| 1393 | + { |
|
| 1044 | 1394 | return false; |
| 1045 | 1395 | } |
| 1046 | 1396 | } |
@@ -376,6 +376,10 @@ discard block |
||
| 376 | 376 | |
| 377 | 377 | if (!defined('ADODB_ALLOW_NEGATIVE_TS')) define('ADODB_NO_NEGATIVE_TS',1); |
| 378 | 378 | |
| 379 | +/** |
|
| 380 | + * @param integer $y1 |
|
| 381 | + * @param integer $m |
|
| 382 | + */ |
|
| 379 | 383 | function adodb_date_test_date($y1,$m,$d=13) |
| 380 | 384 | { |
| 381 | 385 | $t = adodb_mktime(0,0,0,$m,$d,$y1); |
@@ -387,6 +391,9 @@ discard block |
||
| 387 | 391 | return true; |
| 388 | 392 | } |
| 389 | 393 | |
| 394 | +/** |
|
| 395 | + * @param string $fmt |
|
| 396 | + */ |
|
| 390 | 397 | function adodb_date_test_strftime($fmt) |
| 391 | 398 | { |
| 392 | 399 | $s1 = strftime($fmt); |
@@ -72,16 +72,12 @@ discard block |
||
| 72 | 72 | ============================================================================= |
| 73 | 73 | |
| 74 | 74 | FUNCTION DESCRIPTIONS |
| 75 | - |
|
| 76 | - |
|
| 77 | -** FUNCTION adodb_getdate($date=false) |
|
| 75 | + ** FUNCTION adodb_getdate($date=false) |
|
| 78 | 76 | |
| 79 | 77 | Returns an array containing date information, as getdate(), but supports |
| 80 | 78 | dates greater than 1901 to 2038. The local date/time format is derived from a |
| 81 | 79 | heuristic the first time adodb_getdate is called. |
| 82 | - |
|
| 83 | - |
|
| 84 | -** FUNCTION adodb_date($fmt, $timestamp = false) |
|
| 80 | + ** FUNCTION adodb_date($fmt, $timestamp = false) |
|
| 85 | 81 | |
| 86 | 82 | Convert a timestamp to a formatted local date. If $timestamp is not defined, the |
| 87 | 83 | current timestamp is used. Unlike the function date(), it supports dates |
@@ -131,37 +127,27 @@ discard block |
||
| 131 | 127 | W - ISO-8601 week number of year, weeks starting on Monday |
| 132 | 128 | |
| 133 | 129 | </pre> |
| 134 | - |
|
| 135 | - |
|
| 136 | -** FUNCTION adodb_date2($fmt, $isoDateString = false) |
|
| 130 | + ** FUNCTION adodb_date2($fmt, $isoDateString = false) |
|
| 137 | 131 | Same as adodb_date, but 2nd parameter accepts iso date, eg. |
| 138 | 132 | |
| 139 | 133 | adodb_date2('d-M-Y H:i','2003-12-25 13:01:34'); |
| 140 | - |
|
| 141 | - |
|
| 142 | -** FUNCTION adodb_gmdate($fmt, $timestamp = false) |
|
| 134 | + ** FUNCTION adodb_gmdate($fmt, $timestamp = false) |
|
| 143 | 135 | |
| 144 | 136 | Convert a timestamp to a formatted GMT date. If $timestamp is not defined, the |
| 145 | 137 | current timestamp is used. Unlike the function date(), it supports dates |
| 146 | 138 | outside the 1901 to 2038 range. |
| 147 | - |
|
| 148 | - |
|
| 149 | -** FUNCTION adodb_mktime($hr, $min, $sec[, $month, $day, $year]) |
|
| 139 | + ** FUNCTION adodb_mktime($hr, $min, $sec[, $month, $day, $year]) |
|
| 150 | 140 | |
| 151 | 141 | Converts a local date to a unix timestamp. Unlike the function mktime(), it supports |
| 152 | 142 | dates outside the 1901 to 2038 range. All parameters are optional. |
| 153 | - |
|
| 154 | - |
|
| 155 | -** FUNCTION adodb_gmmktime($hr, $min, $sec [, $month, $day, $year]) |
|
| 143 | + ** FUNCTION adodb_gmmktime($hr, $min, $sec [, $month, $day, $year]) |
|
| 156 | 144 | |
| 157 | 145 | Converts a gmt date to a unix timestamp. Unlike the function gmmktime(), it supports |
| 158 | 146 | dates outside the 1901 to 2038 range. Differs from gmmktime() in that all parameters |
| 159 | 147 | are currently compulsory. |
| 160 | - |
|
| 161 | -** FUNCTION adodb_gmstrftime($fmt, $timestamp = false) |
|
| 148 | + ** FUNCTION adodb_gmstrftime($fmt, $timestamp = false) |
|
| 162 | 149 | Convert a timestamp to a formatted GMT date. |
| 163 | - |
|
| 164 | -** FUNCTION adodb_strftime($fmt, $timestamp = false) |
|
| 150 | + ** FUNCTION adodb_strftime($fmt, $timestamp = false) |
|
| 165 | 151 | |
| 166 | 152 | Convert a timestamp to a formatted local date. Internally converts $fmt into |
| 167 | 153 | adodb_date format, then echo result. |
@@ -578,17 +564,17 @@ discard block |
||
| 578 | 564 | $greg_correction = 0; |
| 579 | 565 | |
| 580 | 566 | if($month > 2) |
| 581 | - $month -= 2; |
|
| 567 | + $month -= 2; |
|
| 582 | 568 | else { |
| 583 | - $month += 10; |
|
| 584 | - $year--; |
|
| 569 | + $month += 10; |
|
| 570 | + $year--; |
|
| 585 | 571 | } |
| 586 | 572 | |
| 587 | 573 | $day = floor((13 * $month - 1) / 5) + |
| 588 | - $day + ($year % 100) + |
|
| 589 | - floor(($year % 100) / 4) + |
|
| 590 | - floor(($year / 100) / 4) - 2 * |
|
| 591 | - floor($year / 100) + 77 + $greg_correction; |
|
| 574 | + $day + ($year % 100) + |
|
| 575 | + floor(($year % 100) / 4) + |
|
| 576 | + floor(($year / 100) / 4) - 2 * |
|
| 577 | + floor($year / 100) + 77 + $greg_correction; |
|
| 592 | 578 | |
| 593 | 579 | return $day - 7 * floor($day / 7); |
| 594 | 580 | } |
@@ -958,105 +958,105 @@ discard block |
||
| 958 | 958 | */ |
| 959 | 959 | for ($i=0; $i < $max; $i++) { |
| 960 | 960 | switch($fmt[$i]) { |
| 961 | - case 'T': $dates .= date('T');break; |
|
| 962 | - // YEAR |
|
| 963 | - case 'L': $dates .= $arr['leap'] ? '1' : '0'; break; |
|
| 964 | - case 'r': // Thu, 21 Dec 2000 16:01:07 +0200 |
|
| 961 | + case 'T': $dates .= date('T');break; |
|
| 962 | + // YEAR |
|
| 963 | + case 'L': $dates .= $arr['leap'] ? '1' : '0'; break; |
|
| 964 | + case 'r': // Thu, 21 Dec 2000 16:01:07 +0200 |
|
| 965 | 965 | |
| 966 | - // 4.3.11 uses '04 Jun 2004' |
|
| 967 | - // 4.3.8 uses ' 4 Jun 2004' |
|
| 968 | - $dates .= gmdate('D',$_day_power*(3+adodb_dow($year,$month,$day))).', ' |
|
| 969 | - . ($day<10?'0'.$day:$day) . ' '.date('M',mktime(0,0,0,$month,2,1971)).' '.$year.' '; |
|
| 966 | + // 4.3.11 uses '04 Jun 2004' |
|
| 967 | + // 4.3.8 uses ' 4 Jun 2004' |
|
| 968 | + $dates .= gmdate('D',$_day_power*(3+adodb_dow($year,$month,$day))).', ' |
|
| 969 | + . ($day<10?'0'.$day:$day) . ' '.date('M',mktime(0,0,0,$month,2,1971)).' '.$year.' '; |
|
| 970 | 970 | |
| 971 | - if ($hour < 10) $dates .= '0'.$hour; else $dates .= $hour; |
|
| 971 | + if ($hour < 10) $dates .= '0'.$hour; else $dates .= $hour; |
|
| 972 | 972 | |
| 973 | - if ($min < 10) $dates .= ':0'.$min; else $dates .= ':'.$min; |
|
| 973 | + if ($min < 10) $dates .= ':0'.$min; else $dates .= ':'.$min; |
|
| 974 | 974 | |
| 975 | - if ($secs < 10) $dates .= ':0'.$secs; else $dates .= ':'.$secs; |
|
| 975 | + if ($secs < 10) $dates .= ':0'.$secs; else $dates .= ':'.$secs; |
|
| 976 | 976 | |
| 977 | - $gmt = adodb_get_gmt_diff(); |
|
| 978 | - $dates .= sprintf(' %s%04d',($gmt<0)?'+':'-',abs($gmt)/36); break; |
|
| 977 | + $gmt = adodb_get_gmt_diff(); |
|
| 978 | + $dates .= sprintf(' %s%04d',($gmt<0)?'+':'-',abs($gmt)/36); break; |
|
| 979 | 979 | |
| 980 | - case 'Y': $dates .= $year; break; |
|
| 981 | - case 'y': $dates .= substr($year,strlen($year)-2,2); break; |
|
| 982 | - // MONTH |
|
| 983 | - case 'm': if ($month<10) $dates .= '0'.$month; else $dates .= $month; break; |
|
| 984 | - case 'Q': $dates .= ($month+3)>>2; break; |
|
| 985 | - case 'n': $dates .= $month; break; |
|
| 986 | - case 'M': $dates .= date('M',mktime(0,0,0,$month,2,1971)); break; |
|
| 987 | - case 'F': $dates .= date('F',mktime(0,0,0,$month,2,1971)); break; |
|
| 988 | - // DAY |
|
| 989 | - case 't': $dates .= $arr['ndays']; break; |
|
| 990 | - case 'z': $dates .= $arr['yday']; break; |
|
| 991 | - case 'w': $dates .= adodb_dow($year,$month,$day); break; |
|
| 992 | - case 'l': $dates .= gmdate('l',$_day_power*(3+adodb_dow($year,$month,$day))); break; |
|
| 993 | - case 'D': $dates .= gmdate('D',$_day_power*(3+adodb_dow($year,$month,$day))); break; |
|
| 994 | - case 'j': $dates .= $day; break; |
|
| 995 | - case 'd': if ($day<10) $dates .= '0'.$day; else $dates .= $day; break; |
|
| 996 | - case 'S': |
|
| 997 | - $d10 = $day % 10; |
|
| 998 | - if ($d10 == 1) $dates .= 'st'; |
|
| 999 | - else if ($d10 == 2 && $day != 12) $dates .= 'nd'; |
|
| 1000 | - else if ($d10 == 3) $dates .= 'rd'; |
|
| 1001 | - else $dates .= 'th'; |
|
| 1002 | - break; |
|
| 980 | + case 'Y': $dates .= $year; break; |
|
| 981 | + case 'y': $dates .= substr($year,strlen($year)-2,2); break; |
|
| 982 | + // MONTH |
|
| 983 | + case 'm': if ($month<10) $dates .= '0'.$month; else $dates .= $month; break; |
|
| 984 | + case 'Q': $dates .= ($month+3)>>2; break; |
|
| 985 | + case 'n': $dates .= $month; break; |
|
| 986 | + case 'M': $dates .= date('M',mktime(0,0,0,$month,2,1971)); break; |
|
| 987 | + case 'F': $dates .= date('F',mktime(0,0,0,$month,2,1971)); break; |
|
| 988 | + // DAY |
|
| 989 | + case 't': $dates .= $arr['ndays']; break; |
|
| 990 | + case 'z': $dates .= $arr['yday']; break; |
|
| 991 | + case 'w': $dates .= adodb_dow($year,$month,$day); break; |
|
| 992 | + case 'l': $dates .= gmdate('l',$_day_power*(3+adodb_dow($year,$month,$day))); break; |
|
| 993 | + case 'D': $dates .= gmdate('D',$_day_power*(3+adodb_dow($year,$month,$day))); break; |
|
| 994 | + case 'j': $dates .= $day; break; |
|
| 995 | + case 'd': if ($day<10) $dates .= '0'.$day; else $dates .= $day; break; |
|
| 996 | + case 'S': |
|
| 997 | + $d10 = $day % 10; |
|
| 998 | + if ($d10 == 1) $dates .= 'st'; |
|
| 999 | + else if ($d10 == 2 && $day != 12) $dates .= 'nd'; |
|
| 1000 | + else if ($d10 == 3) $dates .= 'rd'; |
|
| 1001 | + else $dates .= 'th'; |
|
| 1002 | + break; |
|
| 1003 | 1003 | |
| 1004 | - // HOUR |
|
| 1005 | - case 'Z': |
|
| 1006 | - $dates .= ($is_gmt) ? 0 : -adodb_get_gmt_diff(); break; |
|
| 1007 | - case 'O': |
|
| 1008 | - $gmt = ($is_gmt) ? 0 : adodb_get_gmt_diff(); |
|
| 1009 | - $dates .= sprintf('%s%04d',($gmt<0)?'+':'-',abs($gmt)/36); break; |
|
| 1004 | + // HOUR |
|
| 1005 | + case 'Z': |
|
| 1006 | + $dates .= ($is_gmt) ? 0 : -adodb_get_gmt_diff(); break; |
|
| 1007 | + case 'O': |
|
| 1008 | + $gmt = ($is_gmt) ? 0 : adodb_get_gmt_diff(); |
|
| 1009 | + $dates .= sprintf('%s%04d',($gmt<0)?'+':'-',abs($gmt)/36); break; |
|
| 1010 | 1010 | |
| 1011 | - case 'H': |
|
| 1012 | - if ($hour < 10) $dates .= '0'.$hour; |
|
| 1013 | - else $dates .= $hour; |
|
| 1014 | - break; |
|
| 1015 | - case 'h': |
|
| 1016 | - if ($hour > 12) $hh = $hour - 12; |
|
| 1017 | - else { |
|
| 1018 | - if ($hour == 0) $hh = '12'; |
|
| 1019 | - else $hh = $hour; |
|
| 1020 | - } |
|
| 1011 | + case 'H': |
|
| 1012 | + if ($hour < 10) $dates .= '0'.$hour; |
|
| 1013 | + else $dates .= $hour; |
|
| 1014 | + break; |
|
| 1015 | + case 'h': |
|
| 1016 | + if ($hour > 12) $hh = $hour - 12; |
|
| 1017 | + else { |
|
| 1018 | + if ($hour == 0) $hh = '12'; |
|
| 1019 | + else $hh = $hour; |
|
| 1020 | + } |
|
| 1021 | 1021 | |
| 1022 | - if ($hh < 10) $dates .= '0'.$hh; |
|
| 1023 | - else $dates .= $hh; |
|
| 1024 | - break; |
|
| 1022 | + if ($hh < 10) $dates .= '0'.$hh; |
|
| 1023 | + else $dates .= $hh; |
|
| 1024 | + break; |
|
| 1025 | 1025 | |
| 1026 | - case 'G': |
|
| 1027 | - $dates .= $hour; |
|
| 1028 | - break; |
|
| 1026 | + case 'G': |
|
| 1027 | + $dates .= $hour; |
|
| 1028 | + break; |
|
| 1029 | 1029 | |
| 1030 | - case 'g': |
|
| 1031 | - if ($hour > 12) $hh = $hour - 12; |
|
| 1032 | - else { |
|
| 1033 | - if ($hour == 0) $hh = '12'; |
|
| 1034 | - else $hh = $hour; |
|
| 1035 | - } |
|
| 1036 | - $dates .= $hh; |
|
| 1037 | - break; |
|
| 1038 | - // MINUTES |
|
| 1039 | - case 'i': if ($min < 10) $dates .= '0'.$min; else $dates .= $min; break; |
|
| 1040 | - // SECONDS |
|
| 1041 | - case 'U': $dates .= $d; break; |
|
| 1042 | - case 's': if ($secs < 10) $dates .= '0'.$secs; else $dates .= $secs; break; |
|
| 1043 | - // AM/PM |
|
| 1044 | - // Note 00:00 to 11:59 is AM, while 12:00 to 23:59 is PM |
|
| 1045 | - case 'a': |
|
| 1046 | - if ($hour>=12) $dates .= 'pm'; |
|
| 1047 | - else $dates .= 'am'; |
|
| 1048 | - break; |
|
| 1049 | - case 'A': |
|
| 1050 | - if ($hour>=12) $dates .= 'PM'; |
|
| 1051 | - else $dates .= 'AM'; |
|
| 1052 | - break; |
|
| 1053 | - default: |
|
| 1054 | - $dates .= $fmt[$i]; break; |
|
| 1055 | - // ESCAPE |
|
| 1056 | - case "\\": |
|
| 1057 | - $i++; |
|
| 1058 | - if ($i < $max) $dates .= $fmt[$i]; |
|
| 1059 | - break; |
|
| 1030 | + case 'g': |
|
| 1031 | + if ($hour > 12) $hh = $hour - 12; |
|
| 1032 | + else { |
|
| 1033 | + if ($hour == 0) $hh = '12'; |
|
| 1034 | + else $hh = $hour; |
|
| 1035 | + } |
|
| 1036 | + $dates .= $hh; |
|
| 1037 | + break; |
|
| 1038 | + // MINUTES |
|
| 1039 | + case 'i': if ($min < 10) $dates .= '0'.$min; else $dates .= $min; break; |
|
| 1040 | + // SECONDS |
|
| 1041 | + case 'U': $dates .= $d; break; |
|
| 1042 | + case 's': if ($secs < 10) $dates .= '0'.$secs; else $dates .= $secs; break; |
|
| 1043 | + // AM/PM |
|
| 1044 | + // Note 00:00 to 11:59 is AM, while 12:00 to 23:59 is PM |
|
| 1045 | + case 'a': |
|
| 1046 | + if ($hour>=12) $dates .= 'pm'; |
|
| 1047 | + else $dates .= 'am'; |
|
| 1048 | + break; |
|
| 1049 | + case 'A': |
|
| 1050 | + if ($hour>=12) $dates .= 'PM'; |
|
| 1051 | + else $dates .= 'AM'; |
|
| 1052 | + break; |
|
| 1053 | + default: |
|
| 1054 | + $dates .= $fmt[$i]; break; |
|
| 1055 | + // ESCAPE |
|
| 1056 | + case "\\": |
|
| 1057 | + $i++; |
|
| 1058 | + if ($i < $max) $dates .= $fmt[$i]; |
|
| 1059 | + break; |
|
| 1060 | 1060 | } |
| 1061 | 1061 | } |
| 1062 | 1062 | return $dates; |
@@ -1222,55 +1222,55 @@ discard block |
||
| 1222 | 1222 | |
| 1223 | 1223 | $inpct = false; |
| 1224 | 1224 | switch($ch) { |
| 1225 | - case '0': |
|
| 1226 | - case '1': |
|
| 1227 | - case '2': |
|
| 1228 | - case '3': |
|
| 1229 | - case '4': |
|
| 1230 | - case '5': |
|
| 1231 | - case '6': |
|
| 1232 | - case '7': |
|
| 1233 | - case '8': |
|
| 1234 | - case '9': |
|
| 1235 | - case 'E': |
|
| 1236 | - case 'O': |
|
| 1237 | - /* ignore format modifiers */ |
|
| 1238 | - $inpct = true; |
|
| 1239 | - break; |
|
| 1225 | + case '0': |
|
| 1226 | + case '1': |
|
| 1227 | + case '2': |
|
| 1228 | + case '3': |
|
| 1229 | + case '4': |
|
| 1230 | + case '5': |
|
| 1231 | + case '6': |
|
| 1232 | + case '7': |
|
| 1233 | + case '8': |
|
| 1234 | + case '9': |
|
| 1235 | + case 'E': |
|
| 1236 | + case 'O': |
|
| 1237 | + /* ignore format modifiers */ |
|
| 1238 | + $inpct = true; |
|
| 1239 | + break; |
|
| 1240 | 1240 | |
| 1241 | - case 'a': $fmtdate .= 'D'; break; |
|
| 1242 | - case 'A': $fmtdate .= 'l'; break; |
|
| 1243 | - case 'h': |
|
| 1244 | - case 'b': $fmtdate .= 'M'; break; |
|
| 1245 | - case 'B': $fmtdate .= 'F'; break; |
|
| 1246 | - case 'c': $fmtdate .= $ADODB_DATE_LOCALE[0].$ADODB_DATE_LOCALE[1]; break; |
|
| 1247 | - case 'C': $fmtdate .= '\C?'; break; // century |
|
| 1248 | - case 'd': $fmtdate .= 'd'; break; |
|
| 1249 | - case 'D': $fmtdate .= 'm/d/y'; break; |
|
| 1250 | - case 'e': $fmtdate .= 'j'; break; |
|
| 1251 | - case 'g': $fmtdate .= '\g?'; break; //? |
|
| 1252 | - case 'G': $fmtdate .= '\G?'; break; //? |
|
| 1253 | - case 'H': $fmtdate .= 'H'; break; |
|
| 1254 | - case 'I': $fmtdate .= 'h'; break; |
|
| 1255 | - case 'j': $fmtdate .= '?z'; $parsej = true; break; // wrong as j=1-based, z=0-basd |
|
| 1256 | - case 'm': $fmtdate .= 'm'; break; |
|
| 1257 | - case 'M': $fmtdate .= 'i'; break; |
|
| 1258 | - case 'n': $fmtdate .= "\n"; break; |
|
| 1259 | - case 'p': $fmtdate .= 'a'; break; |
|
| 1260 | - case 'r': $fmtdate .= 'h:i:s a'; break; |
|
| 1261 | - case 'R': $fmtdate .= 'H:i:s'; break; |
|
| 1262 | - case 'S': $fmtdate .= 's'; break; |
|
| 1263 | - case 't': $fmtdate .= "\t"; break; |
|
| 1264 | - case 'T': $fmtdate .= 'H:i:s'; break; |
|
| 1265 | - case 'u': $fmtdate .= '?u'; $parseu = true; break; // wrong strftime=1-based, date=0-basde |
|
| 1266 | - case 'U': $fmtdate .= '?U'; $parseU = true; break;// wrong strftime=1-based, date=0-based |
|
| 1267 | - case 'x': $fmtdate .= $ADODB_DATE_LOCALE[0]; break; |
|
| 1268 | - case 'X': $fmtdate .= $ADODB_DATE_LOCALE[1]; break; |
|
| 1269 | - case 'w': $fmtdate .= '?w'; $parseu = true; break; // wrong strftime=1-based, date=0-basde |
|
| 1270 | - case 'W': $fmtdate .= '?W'; $parseU = true; break;// wrong strftime=1-based, date=0-based |
|
| 1271 | - case 'y': $fmtdate .= 'y'; break; |
|
| 1272 | - case 'Y': $fmtdate .= 'Y'; break; |
|
| 1273 | - case 'Z': $fmtdate .= 'T'; break; |
|
| 1241 | + case 'a': $fmtdate .= 'D'; break; |
|
| 1242 | + case 'A': $fmtdate .= 'l'; break; |
|
| 1243 | + case 'h': |
|
| 1244 | + case 'b': $fmtdate .= 'M'; break; |
|
| 1245 | + case 'B': $fmtdate .= 'F'; break; |
|
| 1246 | + case 'c': $fmtdate .= $ADODB_DATE_LOCALE[0].$ADODB_DATE_LOCALE[1]; break; |
|
| 1247 | + case 'C': $fmtdate .= '\C?'; break; // century |
|
| 1248 | + case 'd': $fmtdate .= 'd'; break; |
|
| 1249 | + case 'D': $fmtdate .= 'm/d/y'; break; |
|
| 1250 | + case 'e': $fmtdate .= 'j'; break; |
|
| 1251 | + case 'g': $fmtdate .= '\g?'; break; //? |
|
| 1252 | + case 'G': $fmtdate .= '\G?'; break; //? |
|
| 1253 | + case 'H': $fmtdate .= 'H'; break; |
|
| 1254 | + case 'I': $fmtdate .= 'h'; break; |
|
| 1255 | + case 'j': $fmtdate .= '?z'; $parsej = true; break; // wrong as j=1-based, z=0-basd |
|
| 1256 | + case 'm': $fmtdate .= 'm'; break; |
|
| 1257 | + case 'M': $fmtdate .= 'i'; break; |
|
| 1258 | + case 'n': $fmtdate .= "\n"; break; |
|
| 1259 | + case 'p': $fmtdate .= 'a'; break; |
|
| 1260 | + case 'r': $fmtdate .= 'h:i:s a'; break; |
|
| 1261 | + case 'R': $fmtdate .= 'H:i:s'; break; |
|
| 1262 | + case 'S': $fmtdate .= 's'; break; |
|
| 1263 | + case 't': $fmtdate .= "\t"; break; |
|
| 1264 | + case 'T': $fmtdate .= 'H:i:s'; break; |
|
| 1265 | + case 'u': $fmtdate .= '?u'; $parseu = true; break; // wrong strftime=1-based, date=0-basde |
|
| 1266 | + case 'U': $fmtdate .= '?U'; $parseU = true; break;// wrong strftime=1-based, date=0-based |
|
| 1267 | + case 'x': $fmtdate .= $ADODB_DATE_LOCALE[0]; break; |
|
| 1268 | + case 'X': $fmtdate .= $ADODB_DATE_LOCALE[1]; break; |
|
| 1269 | + case 'w': $fmtdate .= '?w'; $parseu = true; break; // wrong strftime=1-based, date=0-basde |
|
| 1270 | + case 'W': $fmtdate .= '?W'; $parseU = true; break;// wrong strftime=1-based, date=0-based |
|
| 1271 | + case 'y': $fmtdate .= 'y'; break; |
|
| 1272 | + case 'Y': $fmtdate .= 'Y'; break; |
|
| 1273 | + case 'Z': $fmtdate .= 'T'; break; |
|
| 1274 | 1274 | } |
| 1275 | 1275 | } else if (('A' <= ($ch) && ($ch) <= 'Z' ) || ('a' <= ($ch) && ($ch) <= 'z' )) |
| 1276 | 1276 | $fmtdate .= "\\".$ch; |
@@ -359,7 +359,7 @@ discard block |
||
| 359 | 359 | /* |
| 360 | 360 | Version Number |
| 361 | 361 | */ |
| 362 | -define('ADODB_DATE_VERSION',0.21); |
|
| 362 | +define('ADODB_DATE_VERSION', 0.21); |
|
| 363 | 363 | |
| 364 | 364 | /* |
| 365 | 365 | This code was originally for windows. But apparently this problem happens |
@@ -374,12 +374,12 @@ discard block |
||
| 374 | 374 | http://lists.debian.org/debian-glibc/2002/debian-glibc-200205/msg00010.html |
| 375 | 375 | */ |
| 376 | 376 | |
| 377 | -if (!defined('ADODB_ALLOW_NEGATIVE_TS')) define('ADODB_NO_NEGATIVE_TS',1); |
|
| 377 | +if (!defined('ADODB_ALLOW_NEGATIVE_TS')) define('ADODB_NO_NEGATIVE_TS', 1); |
|
| 378 | 378 | |
| 379 | -function adodb_date_test_date($y1,$m,$d=13) |
|
| 379 | +function adodb_date_test_date($y1, $m, $d = 13) |
|
| 380 | 380 | { |
| 381 | - $t = adodb_mktime(0,0,0,$m,$d,$y1); |
|
| 382 | - $rez = adodb_date('Y-n-j H:i:s',$t); |
|
| 381 | + $t = adodb_mktime(0, 0, 0, $m, $d, $y1); |
|
| 382 | + $rez = adodb_date('Y-n-j H:i:s', $t); |
|
| 383 | 383 | if ("$y1-$m-$d 00:00:00" != $rez) { |
| 384 | 384 | print "<b>$y1 error, expected=$y1-$m-$d 00:00:00, adodb=$rez</b><br>"; |
| 385 | 385 | return false; |
@@ -410,55 +410,55 @@ discard block |
||
| 410 | 410 | $fail = false; |
| 411 | 411 | |
| 412 | 412 | // This flag disables calling of PHP native functions, so we can properly test the code |
| 413 | - if (!defined('ADODB_TEST_DATES')) define('ADODB_TEST_DATES',1); |
|
| 413 | + if (!defined('ADODB_TEST_DATES')) define('ADODB_TEST_DATES', 1); |
|
| 414 | 414 | |
| 415 | 415 | adodb_date_test_strftime('%Y %m %x %X'); |
| 416 | 416 | adodb_date_test_strftime("%A %d %B %Y"); |
| 417 | 417 | adodb_date_test_strftime("%H %M S"); |
| 418 | 418 | |
| 419 | - $t = adodb_mktime(0,0,0); |
|
| 420 | - if (!(adodb_date('Y-m-d') == date('Y-m-d'))) print 'Error in '.adodb_mktime(0,0,0).'<br>'; |
|
| 419 | + $t = adodb_mktime(0, 0, 0); |
|
| 420 | + if (!(adodb_date('Y-m-d') == date('Y-m-d'))) print 'Error in '.adodb_mktime(0, 0, 0).'<br>'; |
|
| 421 | 421 | |
| 422 | - $t = adodb_mktime(0,0,0,6,1,2102); |
|
| 423 | - if (!(adodb_date('Y-m-d',$t) == '2102-06-01')) print 'Error in '.adodb_date('Y-m-d',$t).'<br>'; |
|
| 422 | + $t = adodb_mktime(0, 0, 0, 6, 1, 2102); |
|
| 423 | + if (!(adodb_date('Y-m-d', $t) == '2102-06-01')) print 'Error in '.adodb_date('Y-m-d', $t).'<br>'; |
|
| 424 | 424 | |
| 425 | - $t = adodb_mktime(0,0,0,2,1,2102); |
|
| 426 | - if (!(adodb_date('Y-m-d',$t) == '2102-02-01')) print 'Error in '.adodb_date('Y-m-d',$t).'<br>'; |
|
| 425 | + $t = adodb_mktime(0, 0, 0, 2, 1, 2102); |
|
| 426 | + if (!(adodb_date('Y-m-d', $t) == '2102-02-01')) print 'Error in '.adodb_date('Y-m-d', $t).'<br>'; |
|
| 427 | 427 | |
| 428 | 428 | |
| 429 | 429 | print "<p>Testing gregorian <=> julian conversion<p>"; |
| 430 | - $t = adodb_mktime(0,0,0,10,11,1492); |
|
| 430 | + $t = adodb_mktime(0, 0, 0, 10, 11, 1492); |
|
| 431 | 431 | //http://www.holidayorigins.com/html/columbus_day.html - Friday check |
| 432 | - if (!(adodb_date('D Y-m-d',$t) == 'Fri 1492-10-11')) print 'Error in Columbus landing<br>'; |
|
| 432 | + if (!(adodb_date('D Y-m-d', $t) == 'Fri 1492-10-11')) print 'Error in Columbus landing<br>'; |
|
| 433 | 433 | |
| 434 | - $t = adodb_mktime(0,0,0,2,29,1500); |
|
| 435 | - if (!(adodb_date('Y-m-d',$t) == '1500-02-29')) print 'Error in julian leap years<br>'; |
|
| 434 | + $t = adodb_mktime(0, 0, 0, 2, 29, 1500); |
|
| 435 | + if (!(adodb_date('Y-m-d', $t) == '1500-02-29')) print 'Error in julian leap years<br>'; |
|
| 436 | 436 | |
| 437 | - $t = adodb_mktime(0,0,0,2,29,1700); |
|
| 438 | - if (!(adodb_date('Y-m-d',$t) == '1700-03-01')) print 'Error in gregorian leap years<br>'; |
|
| 437 | + $t = adodb_mktime(0, 0, 0, 2, 29, 1700); |
|
| 438 | + if (!(adodb_date('Y-m-d', $t) == '1700-03-01')) print 'Error in gregorian leap years<br>'; |
|
| 439 | 439 | |
| 440 | - print adodb_mktime(0,0,0,10,4,1582).' '; |
|
| 441 | - print adodb_mktime(0,0,0,10,15,1582); |
|
| 442 | - $diff = (adodb_mktime(0,0,0,10,15,1582) - adodb_mktime(0,0,0,10,4,1582)); |
|
| 443 | - if ($diff != 3600*24) print " <b>Error in gregorian correction = ".($diff/3600/24)." days </b><br>"; |
|
| 440 | + print adodb_mktime(0, 0, 0, 10, 4, 1582).' '; |
|
| 441 | + print adodb_mktime(0, 0, 0, 10, 15, 1582); |
|
| 442 | + $diff = (adodb_mktime(0, 0, 0, 10, 15, 1582) - adodb_mktime(0, 0, 0, 10, 4, 1582)); |
|
| 443 | + if ($diff != 3600 * 24) print " <b>Error in gregorian correction = ".($diff / 3600 / 24)." days </b><br>"; |
|
| 444 | 444 | |
| 445 | - print " 15 Oct 1582, Fri=".(adodb_dow(1582,10,15) == 5 ? 'Fri' : '<b>Error</b>')."<br>"; |
|
| 446 | - print " 4 Oct 1582, Thu=".(adodb_dow(1582,10,4) == 4 ? 'Thu' : '<b>Error</b>')."<br>"; |
|
| 445 | + print " 15 Oct 1582, Fri=".(adodb_dow(1582, 10, 15) == 5 ? 'Fri' : '<b>Error</b>')."<br>"; |
|
| 446 | + print " 4 Oct 1582, Thu=".(adodb_dow(1582, 10, 4) == 4 ? 'Thu' : '<b>Error</b>')."<br>"; |
|
| 447 | 447 | |
| 448 | 448 | print "<p>Testing overflow<p>"; |
| 449 | 449 | |
| 450 | - $t = adodb_mktime(0,0,0,3,33,1965); |
|
| 451 | - if (!(adodb_date('Y-m-d',$t) == '1965-04-02')) print 'Error in day overflow 1 <br>'; |
|
| 452 | - $t = adodb_mktime(0,0,0,4,33,1971); |
|
| 453 | - if (!(adodb_date('Y-m-d',$t) == '1971-05-03')) print 'Error in day overflow 2 <br>'; |
|
| 454 | - $t = adodb_mktime(0,0,0,1,60,1965); |
|
| 455 | - if (!(adodb_date('Y-m-d',$t) == '1965-03-01')) print 'Error in day overflow 3 '.adodb_date('Y-m-d',$t).' <br>'; |
|
| 456 | - $t = adodb_mktime(0,0,0,12,32,1965); |
|
| 457 | - if (!(adodb_date('Y-m-d',$t) == '1966-01-01')) print 'Error in day overflow 4 '.adodb_date('Y-m-d',$t).' <br>'; |
|
| 458 | - $t = adodb_mktime(0,0,0,12,63,1965); |
|
| 459 | - if (!(adodb_date('Y-m-d',$t) == '1966-02-01')) print 'Error in day overflow 5 '.adodb_date('Y-m-d',$t).' <br>'; |
|
| 460 | - $t = adodb_mktime(0,0,0,13,3,1965); |
|
| 461 | - if (!(adodb_date('Y-m-d',$t) == '1966-01-03')) print 'Error in mth overflow 1 <br>'; |
|
| 450 | + $t = adodb_mktime(0, 0, 0, 3, 33, 1965); |
|
| 451 | + if (!(adodb_date('Y-m-d', $t) == '1965-04-02')) print 'Error in day overflow 1 <br>'; |
|
| 452 | + $t = adodb_mktime(0, 0, 0, 4, 33, 1971); |
|
| 453 | + if (!(adodb_date('Y-m-d', $t) == '1971-05-03')) print 'Error in day overflow 2 <br>'; |
|
| 454 | + $t = adodb_mktime(0, 0, 0, 1, 60, 1965); |
|
| 455 | + if (!(adodb_date('Y-m-d', $t) == '1965-03-01')) print 'Error in day overflow 3 '.adodb_date('Y-m-d', $t).' <br>'; |
|
| 456 | + $t = adodb_mktime(0, 0, 0, 12, 32, 1965); |
|
| 457 | + if (!(adodb_date('Y-m-d', $t) == '1966-01-01')) print 'Error in day overflow 4 '.adodb_date('Y-m-d', $t).' <br>'; |
|
| 458 | + $t = adodb_mktime(0, 0, 0, 12, 63, 1965); |
|
| 459 | + if (!(adodb_date('Y-m-d', $t) == '1966-02-01')) print 'Error in day overflow 5 '.adodb_date('Y-m-d', $t).' <br>'; |
|
| 460 | + $t = adodb_mktime(0, 0, 0, 13, 3, 1965); |
|
| 461 | + if (!(adodb_date('Y-m-d', $t) == '1966-01-03')) print 'Error in mth overflow 1 <br>'; |
|
| 462 | 462 | |
| 463 | 463 | print "Testing 2-digit => 4-digit year conversion<p>"; |
| 464 | 464 | if (adodb_year_digit_check(00) != 2000) print "Err 2-digit 2000<br>"; |
@@ -472,24 +472,24 @@ discard block |
||
| 472 | 472 | // Test string formating |
| 473 | 473 | print "<p>Testing date formating</p>"; |
| 474 | 474 | $fmt = '\d\a\t\e T Y-m-d H:i:s a A d D F g G h H i j l L m M n O \R\F\C822 r s t U w y Y z Z 2003'; |
| 475 | - $s1 = date($fmt,0); |
|
| 476 | - $s2 = adodb_date($fmt,0); |
|
| 475 | + $s1 = date($fmt, 0); |
|
| 476 | + $s2 = adodb_date($fmt, 0); |
|
| 477 | 477 | if ($s1 != $s2) { |
| 478 | 478 | print " date() 0 failed<br>$s1<br>$s2<br>"; |
| 479 | 479 | } |
| 480 | 480 | flush(); |
| 481 | - for ($i=100; --$i > 0; ) { |
|
| 481 | + for ($i = 100; --$i > 0;) { |
|
| 482 | 482 | |
| 483 | - $ts = 3600.0*((rand()%60000)+(rand()%60000))+(rand()%60000); |
|
| 484 | - $s1 = date($fmt,$ts); |
|
| 485 | - $s2 = adodb_date($fmt,$ts); |
|
| 483 | + $ts = 3600.0 * ((rand() % 60000) + (rand() % 60000)) + (rand() % 60000); |
|
| 484 | + $s1 = date($fmt, $ts); |
|
| 485 | + $s2 = adodb_date($fmt, $ts); |
|
| 486 | 486 | //print "$s1 <br>$s2 <p>"; |
| 487 | - $pos = strcmp($s1,$s2); |
|
| 487 | + $pos = strcmp($s1, $s2); |
|
| 488 | 488 | |
| 489 | 489 | if (($s1) != ($s2)) { |
| 490 | - for ($j=0,$k=strlen($s1); $j < $k; $j++) { |
|
| 490 | + for ($j = 0, $k = strlen($s1); $j < $k; $j++) { |
|
| 491 | 491 | if ($s1[$j] != $s2[$j]) { |
| 492 | - print substr($s1,$j).' '; |
|
| 492 | + print substr($s1, $j).' '; |
|
| 493 | 493 | break; |
| 494 | 494 | } |
| 495 | 495 | } |
@@ -501,8 +501,8 @@ discard block |
||
| 501 | 501 | |
| 502 | 502 | $a1 = getdate($ts); |
| 503 | 503 | $a2 = adodb_getdate($ts); |
| 504 | - $rez = array_diff($a1,$a2); |
|
| 505 | - if (sizeof($rez)>0) { |
|
| 504 | + $rez = array_diff($a1, $a2); |
|
| 505 | + if (sizeof($rez) > 0) { |
|
| 506 | 506 | print "<b>Error getdate() $ts</b><br>"; |
| 507 | 507 | print_r($a1); |
| 508 | 508 | print "<br>"; |
@@ -514,36 +514,36 @@ discard block |
||
| 514 | 514 | |
| 515 | 515 | // Test generation of dates outside 1901-2038 |
| 516 | 516 | print "<p>Testing random dates between 100 and 4000</p>"; |
| 517 | - adodb_date_test_date(100,1); |
|
| 518 | - for ($i=100; --$i >= 0;) { |
|
| 519 | - $y1 = 100+rand(0,1970-100); |
|
| 520 | - $m = rand(1,12); |
|
| 521 | - adodb_date_test_date($y1,$m); |
|
| 517 | + adodb_date_test_date(100, 1); |
|
| 518 | + for ($i = 100; --$i >= 0;) { |
|
| 519 | + $y1 = 100 + rand(0, 1970 - 100); |
|
| 520 | + $m = rand(1, 12); |
|
| 521 | + adodb_date_test_date($y1, $m); |
|
| 522 | 522 | |
| 523 | - $y1 = 3000-rand(0,3000-1970); |
|
| 524 | - adodb_date_test_date($y1,$m); |
|
| 523 | + $y1 = 3000 - rand(0, 3000 - 1970); |
|
| 524 | + adodb_date_test_date($y1, $m); |
|
| 525 | 525 | } |
| 526 | 526 | print '<p>'; |
| 527 | - $start = 1960+rand(0,10); |
|
| 527 | + $start = 1960 + rand(0, 10); |
|
| 528 | 528 | $yrs = 12; |
| 529 | - $i = 365.25*86400*($start-1970); |
|
| 530 | - $offset = 36000+rand(10000,60000); |
|
| 531 | - $max = 365*$yrs*86400; |
|
| 529 | + $i = 365.25 * 86400 * ($start - 1970); |
|
| 530 | + $offset = 36000 + rand(10000, 60000); |
|
| 531 | + $max = 365 * $yrs * 86400; |
|
| 532 | 532 | $lastyear = 0; |
| 533 | 533 | |
| 534 | 534 | // we generate a timestamp, convert it to a date, and convert it back to a timestamp |
| 535 | 535 | // and check if the roundtrip broke the original timestamp value. |
| 536 | - print "Testing $start to ".($start+$yrs).", or $max seconds, offset=$offset: "; |
|
| 536 | + print "Testing $start to ".($start + $yrs).", or $max seconds, offset=$offset: "; |
|
| 537 | 537 | $cnt = 0; |
| 538 | 538 | for ($max += $i; $i < $max; $i += $offset) { |
| 539 | - $ret = adodb_date('m,d,Y,H,i,s',$i); |
|
| 540 | - $arr = explode(',',$ret); |
|
| 539 | + $ret = adodb_date('m,d,Y,H,i,s', $i); |
|
| 540 | + $arr = explode(',', $ret); |
|
| 541 | 541 | if ($lastyear != $arr[2]) { |
| 542 | 542 | $lastyear = $arr[2]; |
| 543 | 543 | print " $lastyear "; |
| 544 | 544 | flush(); |
| 545 | 545 | } |
| 546 | - $newi = adodb_mktime($arr[3],$arr[4],$arr[5],$arr[0],$arr[1],$arr[2]); |
|
| 546 | + $newi = adodb_mktime($arr[3], $arr[4], $arr[5], $arr[0], $arr[1], $arr[2]); |
|
| 547 | 547 | if ($i != $newi) { |
| 548 | 548 | print "Error at $i, adodb_mktime returned $newi ($ret)"; |
| 549 | 549 | $fail = true; |
@@ -577,14 +577,14 @@ discard block |
||
| 577 | 577 | } else |
| 578 | 578 | $greg_correction = 0; |
| 579 | 579 | |
| 580 | - if($month > 2) |
|
| 580 | + if ($month > 2) |
|
| 581 | 581 | $month -= 2; |
| 582 | 582 | else { |
| 583 | 583 | $month += 10; |
| 584 | 584 | $year--; |
| 585 | 585 | } |
| 586 | 586 | |
| 587 | - $day = floor((13 * $month - 1) / 5) + |
|
| 587 | + $day = floor((13 * $month - 1) / 5) + |
|
| 588 | 588 | $day + ($year % 100) + |
| 589 | 589 | floor(($year % 100) / 4) + |
| 590 | 590 | floor(($year / 100) / 4) - 2 * |
@@ -605,7 +605,7 @@ discard block |
||
| 605 | 605 | if ($year % 400 == 0) { |
| 606 | 606 | return true; |
| 607 | 607 | // if gregorian calendar (>1582), century not-divisible by 400 is not leap |
| 608 | - } else if ($year > 1582 && $year % 100 == 0 ) { |
|
| 608 | + } else if ($year > 1582 && $year % 100 == 0) { |
|
| 609 | 609 | return false; |
| 610 | 610 | } |
| 611 | 611 | |
@@ -629,10 +629,10 @@ discard block |
||
| 629 | 629 | { |
| 630 | 630 | if ($y < 100) { |
| 631 | 631 | |
| 632 | - $yr = (integer) date("Y"); |
|
| 633 | - $century = (integer) ($yr /100); |
|
| 632 | + $yr = (integer)date("Y"); |
|
| 633 | + $century = (integer)($yr / 100); |
|
| 634 | 634 | |
| 635 | - if ($yr%100 > 50) { |
|
| 635 | + if ($yr % 100 > 50) { |
|
| 636 | 636 | $c1 = $century + 1; |
| 637 | 637 | $c0 = $century; |
| 638 | 638 | } else { |
@@ -642,8 +642,8 @@ discard block |
||
| 642 | 642 | $c1 *= 100; |
| 643 | 643 | // if 2-digit year is less than 30 years in future, set it to this century |
| 644 | 644 | // otherwise if more than 30 years in future, then we set 2-digit year to the prev century. |
| 645 | - if (($y + $c1) < $yr+30) $y = $y + $c1; |
|
| 646 | - else $y = $y + $c0*100; |
|
| 645 | + if (($y + $c1) < $yr + 30) $y = $y + $c1; |
|
| 646 | + else $y = $y + $c0 * 100; |
|
| 647 | 647 | } |
| 648 | 648 | return $y; |
| 649 | 649 | } |
@@ -656,14 +656,14 @@ discard block |
||
| 656 | 656 | static $TZ; |
| 657 | 657 | if (isset($TZ)) return $TZ; |
| 658 | 658 | |
| 659 | - $TZ = mktime(0,0,0,1,2,1970) - gmmktime(0,0,0,1,2,1970); |
|
| 659 | + $TZ = mktime(0, 0, 0, 1, 2, 1970) - gmmktime(0, 0, 0, 1, 2, 1970); |
|
| 660 | 660 | return $TZ; |
| 661 | 661 | } |
| 662 | 662 | |
| 663 | 663 | /** |
| 664 | 664 | Returns an array with date info. |
| 665 | 665 | */ |
| 666 | -function adodb_getdate($d=false,$fast=false) |
|
| 666 | +function adodb_getdate($d = false, $fast = false) |
|
| 667 | 667 | { |
| 668 | 668 | if ($d === false) return getdate(); |
| 669 | 669 | if (!defined('ADODB_TEST_DATES')) { |
@@ -700,20 +700,20 @@ discard block |
||
| 700 | 700 | $fast flag, which if set to true, will return fewer array values, |
| 701 | 701 | and is much faster as it does not calculate dow, etc. |
| 702 | 702 | */ |
| 703 | -function _adodb_getdate($origd=false,$fast=false,$is_gmt=false) |
|
| 703 | +function _adodb_getdate($origd = false, $fast = false, $is_gmt = false) |
|
| 704 | 704 | { |
| 705 | 705 | static $YRS; |
| 706 | 706 | |
| 707 | - $d = $origd - ($is_gmt ? 0 : adodb_get_gmt_diff()); |
|
| 707 | + $d = $origd - ($is_gmt ? 0 : adodb_get_gmt_diff()); |
|
| 708 | 708 | |
| 709 | 709 | $_day_power = 86400; |
| 710 | 710 | $_hour_power = 3600; |
| 711 | 711 | $_min_power = 60; |
| 712 | 712 | |
| 713 | - if ($d < -12219321600) $d -= 86400*10; // if 15 Oct 1582 or earlier, gregorian correction |
|
| 713 | + if ($d < -12219321600) $d -= 86400 * 10; // if 15 Oct 1582 or earlier, gregorian correction |
|
| 714 | 714 | |
| 715 | - $_month_table_normal = array("",31,28,31,30,31,30,31,31,30,31,30,31); |
|
| 716 | - $_month_table_leaf = array("",31,29,31,30,31,30,31,31,30,31,30,31); |
|
| 715 | + $_month_table_normal = array("", 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); |
|
| 716 | + $_month_table_leaf = array("", 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); |
|
| 717 | 717 | |
| 718 | 718 | $d366 = $_day_power * 366; |
| 719 | 719 | $d365 = $_day_power * 365; |
@@ -785,7 +785,7 @@ discard block |
||
| 785 | 785 | |
| 786 | 786 | $lastsecs = 0; |
| 787 | 787 | $lastyear = 1970; |
| 788 | - foreach($YRS as $year => $secs) { |
|
| 788 | + foreach ($YRS as $year => $secs) { |
|
| 789 | 789 | if ($d >= $secs) { |
| 790 | 790 | $a = $lastyear; |
| 791 | 791 | break; |
@@ -816,7 +816,7 @@ discard block |
||
| 816 | 816 | |
| 817 | 817 | $d = $lastd; |
| 818 | 818 | $mtab = ($leaf) ? $_month_table_leaf : $_month_table_normal; |
| 819 | - for ($a = 13 ; --$a > 0;) { |
|
| 819 | + for ($a = 13; --$a > 0;) { |
|
| 820 | 820 | $lastd = $d; |
| 821 | 821 | $d += $mtab[$a] * $_day_power; |
| 822 | 822 | if ($d >= 0) { |
@@ -827,13 +827,13 @@ discard block |
||
| 827 | 827 | } |
| 828 | 828 | |
| 829 | 829 | $d = $lastd; |
| 830 | - $day = $ndays + ceil(($d+1) / ($_day_power)); |
|
| 830 | + $day = $ndays + ceil(($d + 1) / ($_day_power)); |
|
| 831 | 831 | |
| 832 | - $d += ($ndays - $day+1)* $_day_power; |
|
| 833 | - $hour = floor($d/$_hour_power); |
|
| 832 | + $d += ($ndays - $day + 1) * $_day_power; |
|
| 833 | + $hour = floor($d / $_hour_power); |
|
| 834 | 834 | |
| 835 | 835 | } else { |
| 836 | - for ($a = 1970 ;; $a++) { |
|
| 836 | + for ($a = 1970; ; $a++) { |
|
| 837 | 837 | $lastd = $d; |
| 838 | 838 | |
| 839 | 839 | if ($leaf = _adodb_is_leap_year($a)) $d -= $d366; |
@@ -846,7 +846,7 @@ discard block |
||
| 846 | 846 | $secsInYear = $lastd; |
| 847 | 847 | $d = $lastd; |
| 848 | 848 | $mtab = ($leaf) ? $_month_table_leaf : $_month_table_normal; |
| 849 | - for ($a = 1 ; $a <= 12; $a++) { |
|
| 849 | + for ($a = 1; $a <= 12; $a++) { |
|
| 850 | 850 | $lastd = $d; |
| 851 | 851 | $d -= $mtab[$a] * $_day_power; |
| 852 | 852 | if ($d < 0) { |
@@ -856,13 +856,13 @@ discard block |
||
| 856 | 856 | } |
| 857 | 857 | } |
| 858 | 858 | $d = $lastd; |
| 859 | - $day = ceil(($d+1) / $_day_power); |
|
| 860 | - $d = $d - ($day-1) * $_day_power; |
|
| 861 | - $hour = floor($d /$_hour_power); |
|
| 859 | + $day = ceil(($d + 1) / $_day_power); |
|
| 860 | + $d = $d - ($day - 1) * $_day_power; |
|
| 861 | + $hour = floor($d / $_hour_power); |
|
| 862 | 862 | } |
| 863 | 863 | |
| 864 | 864 | $d -= $hour * $_hour_power; |
| 865 | - $min = floor($d/$_min_power); |
|
| 865 | + $min = floor($d / $_min_power); |
|
| 866 | 866 | $secs = $d - $min * $_min_power; |
| 867 | 867 | if ($fast) { |
| 868 | 868 | return array( |
@@ -872,14 +872,14 @@ discard block |
||
| 872 | 872 | 'mday' => $day, |
| 873 | 873 | 'mon' => $month, |
| 874 | 874 | 'year' => $year, |
| 875 | - 'yday' => floor($secsInYear/$_day_power), |
|
| 875 | + 'yday' => floor($secsInYear / $_day_power), |
|
| 876 | 876 | 'leap' => $leaf, |
| 877 | 877 | 'ndays' => $ndays |
| 878 | 878 | ); |
| 879 | 879 | } |
| 880 | 880 | |
| 881 | 881 | |
| 882 | - $dow = adodb_dow($year,$month,$day); |
|
| 882 | + $dow = adodb_dow($year, $month, $day); |
|
| 883 | 883 | |
| 884 | 884 | return array( |
| 885 | 885 | 'seconds' => $secs, |
@@ -889,55 +889,55 @@ discard block |
||
| 889 | 889 | 'wday' => $dow, |
| 890 | 890 | 'mon' => $month, |
| 891 | 891 | 'year' => $year, |
| 892 | - 'yday' => floor($secsInYear/$_day_power), |
|
| 893 | - 'weekday' => gmdate('l',$_day_power*(3+$dow)), |
|
| 894 | - 'month' => gmdate('F',mktime(0,0,0,$month,2,1971)), |
|
| 892 | + 'yday' => floor($secsInYear / $_day_power), |
|
| 893 | + 'weekday' => gmdate('l', $_day_power * (3 + $dow)), |
|
| 894 | + 'month' => gmdate('F', mktime(0, 0, 0, $month, 2, 1971)), |
|
| 895 | 895 | 0 => $origd |
| 896 | 896 | ); |
| 897 | 897 | } |
| 898 | 898 | |
| 899 | -function adodb_gmdate($fmt,$d=false) |
|
| 899 | +function adodb_gmdate($fmt, $d = false) |
|
| 900 | 900 | { |
| 901 | - return adodb_date($fmt,$d,true); |
|
| 901 | + return adodb_date($fmt, $d, true); |
|
| 902 | 902 | } |
| 903 | 903 | |
| 904 | 904 | // accepts unix timestamp and iso date format in $d |
| 905 | -function adodb_date2($fmt, $d=false, $is_gmt=false) |
|
| 905 | +function adodb_date2($fmt, $d = false, $is_gmt = false) |
|
| 906 | 906 | { |
| 907 | 907 | if ($d !== false) { |
| 908 | 908 | if (!preg_match( |
| 909 | 909 | "|^([0-9]{4})[-/\.]?([0-9]{1,2})[-/\.]?([0-9]{1,2})[ -]?(([0-9]{1,2}):?([0-9]{1,2}):?([0-9\.]{1,4}))?|", |
| 910 | - ($d), $rr)) return adodb_date($fmt,false,$is_gmt); |
|
| 910 | + ($d), $rr)) return adodb_date($fmt, false, $is_gmt); |
|
| 911 | 911 | |
| 912 | - if ($rr[1] <= 100 && $rr[2]<= 1) return adodb_date($fmt,false,$is_gmt); |
|
| 912 | + if ($rr[1] <= 100 && $rr[2] <= 1) return adodb_date($fmt, false, $is_gmt); |
|
| 913 | 913 | |
| 914 | 914 | // h-m-s-MM-DD-YY |
| 915 | - if (!isset($rr[5])) $d = adodb_mktime(0,0,0,$rr[2],$rr[3],$rr[1]); |
|
| 916 | - else $d = @adodb_mktime($rr[5],$rr[6],$rr[7],$rr[2],$rr[3],$rr[1]); |
|
| 915 | + if (!isset($rr[5])) $d = adodb_mktime(0, 0, 0, $rr[2], $rr[3], $rr[1]); |
|
| 916 | + else $d = @adodb_mktime($rr[5], $rr[6], $rr[7], $rr[2], $rr[3], $rr[1]); |
|
| 917 | 917 | } |
| 918 | 918 | |
| 919 | - return adodb_date($fmt,$d,$is_gmt); |
|
| 919 | + return adodb_date($fmt, $d, $is_gmt); |
|
| 920 | 920 | } |
| 921 | 921 | |
| 922 | 922 | |
| 923 | 923 | /** |
| 924 | 924 | Return formatted date based on timestamp $d |
| 925 | 925 | */ |
| 926 | -function adodb_date($fmt,$d=false,$is_gmt=false) |
|
| 926 | +function adodb_date($fmt, $d = false, $is_gmt = false) |
|
| 927 | 927 | { |
| 928 | 928 | static $daylight; |
| 929 | 929 | |
| 930 | - if ($d === false) return ($is_gmt)? @gmdate($fmt): @date($fmt); |
|
| 930 | + if ($d === false) return ($is_gmt) ? @gmdate($fmt) : @date($fmt); |
|
| 931 | 931 | if (!defined('ADODB_TEST_DATES')) { |
| 932 | 932 | if ((abs($d) <= 0x7FFFFFFF)) { // check if number in 32-bit signed range |
| 933 | 933 | if (!defined('ADODB_NO_NEGATIVE_TS') || $d >= 0) // if windows, must be +ve integer |
| 934 | - return ($is_gmt)? @gmdate($fmt,$d): @date($fmt,$d); |
|
| 934 | + return ($is_gmt) ? @gmdate($fmt, $d) : @date($fmt, $d); |
|
| 935 | 935 | |
| 936 | 936 | } |
| 937 | 937 | } |
| 938 | 938 | $_day_power = 86400; |
| 939 | 939 | |
| 940 | - $arr = _adodb_getdate($d,true,$is_gmt); |
|
| 940 | + $arr = _adodb_getdate($d, true, $is_gmt); |
|
| 941 | 941 | |
| 942 | 942 | if (!isset($daylight)) $daylight = function_exists('adodb_daylight_sv'); |
| 943 | 943 | if ($daylight) adodb_daylight_sv($arr, $is_gmt); |
@@ -956,17 +956,17 @@ discard block |
||
| 956 | 956 | at this point, we have the following integer vars to manipulate: |
| 957 | 957 | $year, $month, $day, $hour, $min, $secs |
| 958 | 958 | */ |
| 959 | - for ($i=0; $i < $max; $i++) { |
|
| 960 | - switch($fmt[$i]) { |
|
| 961 | - case 'T': $dates .= date('T');break; |
|
| 959 | + for ($i = 0; $i < $max; $i++) { |
|
| 960 | + switch ($fmt[$i]) { |
|
| 961 | + case 'T': $dates .= date('T'); break; |
|
| 962 | 962 | // YEAR |
| 963 | 963 | case 'L': $dates .= $arr['leap'] ? '1' : '0'; break; |
| 964 | 964 | case 'r': // Thu, 21 Dec 2000 16:01:07 +0200 |
| 965 | 965 | |
| 966 | 966 | // 4.3.11 uses '04 Jun 2004' |
| 967 | 967 | // 4.3.8 uses ' 4 Jun 2004' |
| 968 | - $dates .= gmdate('D',$_day_power*(3+adodb_dow($year,$month,$day))).', ' |
|
| 969 | - . ($day<10?'0'.$day:$day) . ' '.date('M',mktime(0,0,0,$month,2,1971)).' '.$year.' '; |
|
| 968 | + $dates .= gmdate('D', $_day_power * (3 + adodb_dow($year, $month, $day))).', ' |
|
| 969 | + . ($day < 10 ? '0'.$day : $day).' '.date('M', mktime(0, 0, 0, $month, 2, 1971)).' '.$year.' '; |
|
| 970 | 970 | |
| 971 | 971 | if ($hour < 10) $dates .= '0'.$hour; else $dates .= $hour; |
| 972 | 972 | |
@@ -975,24 +975,24 @@ discard block |
||
| 975 | 975 | if ($secs < 10) $dates .= ':0'.$secs; else $dates .= ':'.$secs; |
| 976 | 976 | |
| 977 | 977 | $gmt = adodb_get_gmt_diff(); |
| 978 | - $dates .= sprintf(' %s%04d',($gmt<0)?'+':'-',abs($gmt)/36); break; |
|
| 978 | + $dates .= sprintf(' %s%04d', ($gmt < 0) ? '+' : '-', abs($gmt) / 36); break; |
|
| 979 | 979 | |
| 980 | 980 | case 'Y': $dates .= $year; break; |
| 981 | - case 'y': $dates .= substr($year,strlen($year)-2,2); break; |
|
| 981 | + case 'y': $dates .= substr($year, strlen($year) - 2, 2); break; |
|
| 982 | 982 | // MONTH |
| 983 | - case 'm': if ($month<10) $dates .= '0'.$month; else $dates .= $month; break; |
|
| 984 | - case 'Q': $dates .= ($month+3)>>2; break; |
|
| 983 | + case 'm': if ($month < 10) $dates .= '0'.$month; else $dates .= $month; break; |
|
| 984 | + case 'Q': $dates .= ($month + 3) >> 2; break; |
|
| 985 | 985 | case 'n': $dates .= $month; break; |
| 986 | - case 'M': $dates .= date('M',mktime(0,0,0,$month,2,1971)); break; |
|
| 987 | - case 'F': $dates .= date('F',mktime(0,0,0,$month,2,1971)); break; |
|
| 986 | + case 'M': $dates .= date('M', mktime(0, 0, 0, $month, 2, 1971)); break; |
|
| 987 | + case 'F': $dates .= date('F', mktime(0, 0, 0, $month, 2, 1971)); break; |
|
| 988 | 988 | // DAY |
| 989 | 989 | case 't': $dates .= $arr['ndays']; break; |
| 990 | 990 | case 'z': $dates .= $arr['yday']; break; |
| 991 | - case 'w': $dates .= adodb_dow($year,$month,$day); break; |
|
| 992 | - case 'l': $dates .= gmdate('l',$_day_power*(3+adodb_dow($year,$month,$day))); break; |
|
| 993 | - case 'D': $dates .= gmdate('D',$_day_power*(3+adodb_dow($year,$month,$day))); break; |
|
| 991 | + case 'w': $dates .= adodb_dow($year, $month, $day); break; |
|
| 992 | + case 'l': $dates .= gmdate('l', $_day_power * (3 + adodb_dow($year, $month, $day))); break; |
|
| 993 | + case 'D': $dates .= gmdate('D', $_day_power * (3 + adodb_dow($year, $month, $day))); break; |
|
| 994 | 994 | case 'j': $dates .= $day; break; |
| 995 | - case 'd': if ($day<10) $dates .= '0'.$day; else $dates .= $day; break; |
|
| 995 | + case 'd': if ($day < 10) $dates .= '0'.$day; else $dates .= $day; break; |
|
| 996 | 996 | case 'S': |
| 997 | 997 | $d10 = $day % 10; |
| 998 | 998 | if ($d10 == 1) $dates .= 'st'; |
@@ -1006,7 +1006,7 @@ discard block |
||
| 1006 | 1006 | $dates .= ($is_gmt) ? 0 : -adodb_get_gmt_diff(); break; |
| 1007 | 1007 | case 'O': |
| 1008 | 1008 | $gmt = ($is_gmt) ? 0 : adodb_get_gmt_diff(); |
| 1009 | - $dates .= sprintf('%s%04d',($gmt<0)?'+':'-',abs($gmt)/36); break; |
|
| 1009 | + $dates .= sprintf('%s%04d', ($gmt < 0) ? '+' : '-', abs($gmt) / 36); break; |
|
| 1010 | 1010 | |
| 1011 | 1011 | case 'H': |
| 1012 | 1012 | if ($hour < 10) $dates .= '0'.$hour; |
@@ -1043,11 +1043,11 @@ discard block |
||
| 1043 | 1043 | // AM/PM |
| 1044 | 1044 | // Note 00:00 to 11:59 is AM, while 12:00 to 23:59 is PM |
| 1045 | 1045 | case 'a': |
| 1046 | - if ($hour>=12) $dates .= 'pm'; |
|
| 1046 | + if ($hour >= 12) $dates .= 'pm'; |
|
| 1047 | 1047 | else $dates .= 'am'; |
| 1048 | 1048 | break; |
| 1049 | 1049 | case 'A': |
| 1050 | - if ($hour>=12) $dates .= 'PM'; |
|
| 1050 | + if ($hour >= 12) $dates .= 'PM'; |
|
| 1051 | 1051 | else $dates .= 'AM'; |
| 1052 | 1052 | break; |
| 1053 | 1053 | default: |
@@ -1066,9 +1066,9 @@ discard block |
||
| 1066 | 1066 | Returns a timestamp given a GMT/UTC time. |
| 1067 | 1067 | Note that $is_dst is not implemented and is ignored. |
| 1068 | 1068 | */ |
| 1069 | -function adodb_gmmktime($hr,$min,$sec,$mon=false,$day=false,$year=false,$is_dst=false) |
|
| 1069 | +function adodb_gmmktime($hr, $min, $sec, $mon = false, $day = false, $year = false, $is_dst = false) |
|
| 1070 | 1070 | { |
| 1071 | - return adodb_mktime($hr,$min,$sec,$mon,$day,$year,$is_dst,true); |
|
| 1071 | + return adodb_mktime($hr, $min, $sec, $mon, $day, $year, $is_dst, true); |
|
| 1072 | 1072 | } |
| 1073 | 1073 | |
| 1074 | 1074 | /** |
@@ -1077,12 +1077,12 @@ discard block |
||
| 1077 | 1077 | |
| 1078 | 1078 | Not a very fast algorithm - O(n) operation. Could be optimized to O(1). |
| 1079 | 1079 | */ |
| 1080 | -function adodb_mktime($hr,$min,$sec,$mon=false,$day=false,$year=false,$is_dst=false,$is_gmt=false) |
|
| 1080 | +function adodb_mktime($hr, $min, $sec, $mon = false, $day = false, $year = false, $is_dst = false, $is_gmt = false) |
|
| 1081 | 1081 | { |
| 1082 | 1082 | if (!defined('ADODB_TEST_DATES')) { |
| 1083 | 1083 | |
| 1084 | 1084 | if ($mon === false) { |
| 1085 | - return $is_gmt? @gmmktime($hr,$min,$sec): @mktime($hr,$min,$sec); |
|
| 1085 | + return $is_gmt ? @gmmktime($hr, $min, $sec) : @mktime($hr, $min, $sec); |
|
| 1086 | 1086 | } |
| 1087 | 1087 | |
| 1088 | 1088 | // for windows, we don't check 1970 because with timezone differences, |
@@ -1091,8 +1091,7 @@ discard block |
||
| 1091 | 1091 | || !defined('ADODB_NO_NEGATIVE_TS') && (1901 < $year && $year < 2038) |
| 1092 | 1092 | ) { |
| 1093 | 1093 | return $is_gmt ? |
| 1094 | - @gmmktime($hr,$min,$sec,$mon,$day,$year): |
|
| 1095 | - @mktime($hr,$min,$sec,$mon,$day,$year); |
|
| 1094 | + @gmmktime($hr, $min, $sec, $mon, $day, $year) : @mktime($hr, $min, $sec, $mon, $day, $year); |
|
| 1096 | 1095 | } |
| 1097 | 1096 | } |
| 1098 | 1097 | |
@@ -1115,23 +1114,23 @@ discard block |
||
| 1115 | 1114 | if ($mon > 12) { |
| 1116 | 1115 | $y = floor($mon / 12); |
| 1117 | 1116 | $year += $y; |
| 1118 | - $mon -= $y*12; |
|
| 1117 | + $mon -= $y * 12; |
|
| 1119 | 1118 | } else if ($mon < 1) { |
| 1120 | - $y = ceil((1-$mon) / 12); |
|
| 1119 | + $y = ceil((1 - $mon) / 12); |
|
| 1121 | 1120 | $year -= $y; |
| 1122 | - $mon += $y*12; |
|
| 1121 | + $mon += $y * 12; |
|
| 1123 | 1122 | } |
| 1124 | 1123 | |
| 1125 | 1124 | $_day_power = 86400; |
| 1126 | 1125 | $_hour_power = 3600; |
| 1127 | 1126 | $_min_power = 60; |
| 1128 | 1127 | |
| 1129 | - $_month_table_normal = array("",31,28,31,30,31,30,31,31,30,31,30,31); |
|
| 1130 | - $_month_table_leaf = array("",31,29,31,30,31,30,31,31,30,31,30,31); |
|
| 1128 | + $_month_table_normal = array("", 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); |
|
| 1129 | + $_month_table_leaf = array("", 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); |
|
| 1131 | 1130 | |
| 1132 | 1131 | $_total_date = 0; |
| 1133 | 1132 | if ($year >= 1970) { |
| 1134 | - for ($a = 1970 ; $a <= $year; $a++) { |
|
| 1133 | + for ($a = 1970; $a <= $year; $a++) { |
|
| 1135 | 1134 | $leaf = _adodb_is_leap_year($a); |
| 1136 | 1135 | if ($leaf == true) { |
| 1137 | 1136 | $loop_table = $_month_table_leaf; |
@@ -1143,16 +1142,16 @@ discard block |
||
| 1143 | 1142 | if ($a < $year) { |
| 1144 | 1143 | $_total_date += $_add_date; |
| 1145 | 1144 | } else { |
| 1146 | - for($b=1;$b<$mon;$b++) { |
|
| 1145 | + for ($b = 1; $b < $mon; $b++) { |
|
| 1147 | 1146 | $_total_date += $loop_table[$b]; |
| 1148 | 1147 | } |
| 1149 | 1148 | } |
| 1150 | 1149 | } |
| 1151 | - $_total_date +=$day-1; |
|
| 1150 | + $_total_date += $day - 1; |
|
| 1152 | 1151 | $ret = $_total_date * $_day_power + $hr * $_hour_power + $min * $_min_power + $sec + $gmt_different; |
| 1153 | 1152 | |
| 1154 | 1153 | } else { |
| 1155 | - for ($a = 1969 ; $a >= $year; $a--) { |
|
| 1154 | + for ($a = 1969; $a >= $year; $a--) { |
|
| 1156 | 1155 | $leaf = _adodb_is_leap_year($a); |
| 1157 | 1156 | if ($leaf == true) { |
| 1158 | 1157 | $loop_table = $_month_table_leaf; |
@@ -1163,7 +1162,7 @@ discard block |
||
| 1163 | 1162 | } |
| 1164 | 1163 | if ($a > $year) { $_total_date += $_add_date; |
| 1165 | 1164 | } else { |
| 1166 | - for($b=12;$b>$mon;$b--) { |
|
| 1165 | + for ($b = 12; $b > $mon; $b--) { |
|
| 1167 | 1166 | $_total_date += $loop_table[$b]; |
| 1168 | 1167 | } |
| 1169 | 1168 | } |
@@ -1172,45 +1171,45 @@ discard block |
||
| 1172 | 1171 | |
| 1173 | 1172 | $_day_time = $hr * $_hour_power + $min * $_min_power + $sec; |
| 1174 | 1173 | $_day_time = $_day_power - $_day_time; |
| 1175 | - $ret = -( $_total_date * $_day_power + $_day_time - $gmt_different); |
|
| 1176 | - if ($ret < -12220185600) $ret += 10*86400; // if earlier than 5 Oct 1582 - gregorian correction |
|
| 1174 | + $ret = -($_total_date * $_day_power + $_day_time - $gmt_different); |
|
| 1175 | + if ($ret < -12220185600) $ret += 10 * 86400; // if earlier than 5 Oct 1582 - gregorian correction |
|
| 1177 | 1176 | else if ($ret < -12219321600) $ret = -12219321600; // if in limbo, reset to 15 Oct 1582. |
| 1178 | 1177 | } |
| 1179 | 1178 | //print " dmy=$day/$mon/$year $hr:$min:$sec => " .$ret; |
| 1180 | 1179 | return $ret; |
| 1181 | 1180 | } |
| 1182 | 1181 | |
| 1183 | -function adodb_gmstrftime($fmt, $ts=false) |
|
| 1182 | +function adodb_gmstrftime($fmt, $ts = false) |
|
| 1184 | 1183 | { |
| 1185 | - return adodb_strftime($fmt,$ts,true); |
|
| 1184 | + return adodb_strftime($fmt, $ts, true); |
|
| 1186 | 1185 | } |
| 1187 | 1186 | |
| 1188 | 1187 | // hack - convert to adodb_date |
| 1189 | -function adodb_strftime($fmt, $ts=false,$is_gmt=false) |
|
| 1188 | +function adodb_strftime($fmt, $ts = false, $is_gmt = false) |
|
| 1190 | 1189 | { |
| 1191 | 1190 | global $ADODB_DATE_LOCALE; |
| 1192 | 1191 | |
| 1193 | 1192 | if (!defined('ADODB_TEST_DATES')) { |
| 1194 | 1193 | if ((abs($ts) <= 0x7FFFFFFF)) { // check if number in 32-bit signed range |
| 1195 | 1194 | if (!defined('ADODB_NO_NEGATIVE_TS') || $ts >= 0) // if windows, must be +ve integer |
| 1196 | - return ($is_gmt)? @gmstrftime($fmt,$ts): @strftime($fmt,$ts); |
|
| 1195 | + return ($is_gmt) ? @gmstrftime($fmt, $ts) : @strftime($fmt, $ts); |
|
| 1197 | 1196 | |
| 1198 | 1197 | } |
| 1199 | 1198 | } |
| 1200 | 1199 | |
| 1201 | 1200 | if (empty($ADODB_DATE_LOCALE)) { |
| 1202 | - $tstr = strtoupper(gmstrftime('%c',31366800)); // 30 Dec 1970, 1 am |
|
| 1203 | - $sep = substr($tstr,2,1); |
|
| 1204 | - $hasAM = strrpos($tstr,'M') !== false; |
|
| 1201 | + $tstr = strtoupper(gmstrftime('%c', 31366800)); // 30 Dec 1970, 1 am |
|
| 1202 | + $sep = substr($tstr, 2, 1); |
|
| 1203 | + $hasAM = strrpos($tstr, 'M') !== false; |
|
| 1205 | 1204 | |
| 1206 | 1205 | $ADODB_DATE_LOCALE = array(); |
| 1207 | - $ADODB_DATE_LOCALE[] = strncmp($tstr,'30',2) == 0 ? 'd'.$sep.'m'.$sep.'y' : 'm'.$sep.'d'.$sep.'y'; |
|
| 1208 | - $ADODB_DATE_LOCALE[] = ($hasAM) ? 'h:i:s a' : 'H:i:s'; |
|
| 1206 | + $ADODB_DATE_LOCALE[] = strncmp($tstr, '30', 2) == 0 ? 'd'.$sep.'m'.$sep.'y' : 'm'.$sep.'d'.$sep.'y'; |
|
| 1207 | + $ADODB_DATE_LOCALE[] = ($hasAM) ? 'h:i:s a' : 'H:i:s'; |
|
| 1209 | 1208 | |
| 1210 | 1209 | } |
| 1211 | 1210 | $inpct = false; |
| 1212 | 1211 | $fmtdate = ''; |
| 1213 | - for ($i=0,$max = strlen($fmt); $i < $max; $i++) { |
|
| 1212 | + for ($i = 0, $max = strlen($fmt); $i < $max; $i++) { |
|
| 1214 | 1213 | $ch = $fmt[$i]; |
| 1215 | 1214 | if ($ch == '%') { |
| 1216 | 1215 | if ($inpct) { |
@@ -1221,7 +1220,7 @@ discard block |
||
| 1221 | 1220 | } else if ($inpct) { |
| 1222 | 1221 | |
| 1223 | 1222 | $inpct = false; |
| 1224 | - switch($ch) { |
|
| 1223 | + switch ($ch) { |
|
| 1225 | 1224 | case '0': |
| 1226 | 1225 | case '1': |
| 1227 | 1226 | case '2': |
@@ -1263,16 +1262,16 @@ discard block |
||
| 1263 | 1262 | case 't': $fmtdate .= "\t"; break; |
| 1264 | 1263 | case 'T': $fmtdate .= 'H:i:s'; break; |
| 1265 | 1264 | case 'u': $fmtdate .= '?u'; $parseu = true; break; // wrong strftime=1-based, date=0-basde |
| 1266 | - case 'U': $fmtdate .= '?U'; $parseU = true; break;// wrong strftime=1-based, date=0-based |
|
| 1265 | + case 'U': $fmtdate .= '?U'; $parseU = true; break; // wrong strftime=1-based, date=0-based |
|
| 1267 | 1266 | case 'x': $fmtdate .= $ADODB_DATE_LOCALE[0]; break; |
| 1268 | 1267 | case 'X': $fmtdate .= $ADODB_DATE_LOCALE[1]; break; |
| 1269 | 1268 | case 'w': $fmtdate .= '?w'; $parseu = true; break; // wrong strftime=1-based, date=0-basde |
| 1270 | - case 'W': $fmtdate .= '?W'; $parseU = true; break;// wrong strftime=1-based, date=0-based |
|
| 1269 | + case 'W': $fmtdate .= '?W'; $parseU = true; break; // wrong strftime=1-based, date=0-based |
|
| 1271 | 1270 | case 'y': $fmtdate .= 'y'; break; |
| 1272 | 1271 | case 'Y': $fmtdate .= 'Y'; break; |
| 1273 | 1272 | case 'Z': $fmtdate .= 'T'; break; |
| 1274 | 1273 | } |
| 1275 | - } else if (('A' <= ($ch) && ($ch) <= 'Z' ) || ('a' <= ($ch) && ($ch) <= 'z' )) |
|
| 1274 | + } else if (('A' <= ($ch) && ($ch) <= 'Z') || ('a' <= ($ch) && ($ch) <= 'z')) |
|
| 1276 | 1275 | $fmtdate .= "\\".$ch; |
| 1277 | 1276 | else |
| 1278 | 1277 | $fmtdate .= $ch; |
@@ -374,13 +374,17 @@ discard block |
||
| 374 | 374 | http://lists.debian.org/debian-glibc/2002/debian-glibc-200205/msg00010.html |
| 375 | 375 | */ |
| 376 | 376 | |
| 377 | -if (!defined('ADODB_ALLOW_NEGATIVE_TS')) define('ADODB_NO_NEGATIVE_TS',1); |
|
| 377 | +if (!defined('ADODB_ALLOW_NEGATIVE_TS')) |
|
| 378 | +{ |
|
| 379 | + define('ADODB_NO_NEGATIVE_TS',1); |
|
| 380 | +} |
|
| 378 | 381 | |
| 379 | 382 | function adodb_date_test_date($y1,$m,$d=13) |
| 380 | 383 | { |
| 381 | 384 | $t = adodb_mktime(0,0,0,$m,$d,$y1); |
| 382 | 385 | $rez = adodb_date('Y-n-j H:i:s',$t); |
| 383 | - if ("$y1-$m-$d 00:00:00" != $rez) { |
|
| 386 | + if ("$y1-$m-$d 00:00:00" != $rez) |
|
| 387 | + { |
|
| 384 | 388 | print "<b>$y1 error, expected=$y1-$m-$d 00:00:00, adodb=$rez</b><br>"; |
| 385 | 389 | return false; |
| 386 | 390 | } |
@@ -392,7 +396,10 @@ discard block |
||
| 392 | 396 | $s1 = strftime($fmt); |
| 393 | 397 | $s2 = adodb_strftime($fmt); |
| 394 | 398 | |
| 395 | - if ($s1 == $s2) return true; |
|
| 399 | + if ($s1 == $s2) |
|
| 400 | + { |
|
| 401 | + return true; |
|
| 402 | + } |
|
| 396 | 403 | |
| 397 | 404 | echo "error for $fmt, strftime=$s1, $adodb=$s2<br>"; |
| 398 | 405 | return false; |
@@ -410,37 +417,61 @@ discard block |
||
| 410 | 417 | $fail = false; |
| 411 | 418 | |
| 412 | 419 | // This flag disables calling of PHP native functions, so we can properly test the code |
| 413 | - if (!defined('ADODB_TEST_DATES')) define('ADODB_TEST_DATES',1); |
|
| 420 | + if (!defined('ADODB_TEST_DATES')) |
|
| 421 | + { |
|
| 422 | + define('ADODB_TEST_DATES',1); |
|
| 423 | + } |
|
| 414 | 424 | |
| 415 | 425 | adodb_date_test_strftime('%Y %m %x %X'); |
| 416 | 426 | adodb_date_test_strftime("%A %d %B %Y"); |
| 417 | 427 | adodb_date_test_strftime("%H %M S"); |
| 418 | 428 | |
| 419 | 429 | $t = adodb_mktime(0,0,0); |
| 420 | - if (!(adodb_date('Y-m-d') == date('Y-m-d'))) print 'Error in '.adodb_mktime(0,0,0).'<br>'; |
|
| 430 | + if (!(adodb_date('Y-m-d') == date('Y-m-d'))) |
|
| 431 | + { |
|
| 432 | + print 'Error in '.adodb_mktime(0,0,0).'<br>'; |
|
| 433 | + } |
|
| 421 | 434 | |
| 422 | 435 | $t = adodb_mktime(0,0,0,6,1,2102); |
| 423 | - if (!(adodb_date('Y-m-d',$t) == '2102-06-01')) print 'Error in '.adodb_date('Y-m-d',$t).'<br>'; |
|
| 436 | + if (!(adodb_date('Y-m-d',$t) == '2102-06-01')) |
|
| 437 | + { |
|
| 438 | + print 'Error in '.adodb_date('Y-m-d',$t).'<br>'; |
|
| 439 | + } |
|
| 424 | 440 | |
| 425 | 441 | $t = adodb_mktime(0,0,0,2,1,2102); |
| 426 | - if (!(adodb_date('Y-m-d',$t) == '2102-02-01')) print 'Error in '.adodb_date('Y-m-d',$t).'<br>'; |
|
| 442 | + if (!(adodb_date('Y-m-d',$t) == '2102-02-01')) |
|
| 443 | + { |
|
| 444 | + print 'Error in '.adodb_date('Y-m-d',$t).'<br>'; |
|
| 445 | + } |
|
| 427 | 446 | |
| 428 | 447 | |
| 429 | 448 | print "<p>Testing gregorian <=> julian conversion<p>"; |
| 430 | 449 | $t = adodb_mktime(0,0,0,10,11,1492); |
| 431 | 450 | //http://www.holidayorigins.com/html/columbus_day.html - Friday check |
| 432 | - if (!(adodb_date('D Y-m-d',$t) == 'Fri 1492-10-11')) print 'Error in Columbus landing<br>'; |
|
| 451 | + if (!(adodb_date('D Y-m-d',$t) == 'Fri 1492-10-11')) |
|
| 452 | + { |
|
| 453 | + print 'Error in Columbus landing<br>'; |
|
| 454 | + } |
|
| 433 | 455 | |
| 434 | 456 | $t = adodb_mktime(0,0,0,2,29,1500); |
| 435 | - if (!(adodb_date('Y-m-d',$t) == '1500-02-29')) print 'Error in julian leap years<br>'; |
|
| 457 | + if (!(adodb_date('Y-m-d',$t) == '1500-02-29')) |
|
| 458 | + { |
|
| 459 | + print 'Error in julian leap years<br>'; |
|
| 460 | + } |
|
| 436 | 461 | |
| 437 | 462 | $t = adodb_mktime(0,0,0,2,29,1700); |
| 438 | - if (!(adodb_date('Y-m-d',$t) == '1700-03-01')) print 'Error in gregorian leap years<br>'; |
|
| 463 | + if (!(adodb_date('Y-m-d',$t) == '1700-03-01')) |
|
| 464 | + { |
|
| 465 | + print 'Error in gregorian leap years<br>'; |
|
| 466 | + } |
|
| 439 | 467 | |
| 440 | 468 | print adodb_mktime(0,0,0,10,4,1582).' '; |
| 441 | 469 | print adodb_mktime(0,0,0,10,15,1582); |
| 442 | 470 | $diff = (adodb_mktime(0,0,0,10,15,1582) - adodb_mktime(0,0,0,10,4,1582)); |
| 443 | - if ($diff != 3600*24) print " <b>Error in gregorian correction = ".($diff/3600/24)." days </b><br>"; |
|
| 471 | + if ($diff != 3600*24) |
|
| 472 | + { |
|
| 473 | + print " <b>Error in gregorian correction = ".($diff/3600/24)." days </b><br>"; |
|
| 474 | + } |
|
| 444 | 475 | |
| 445 | 476 | print " 15 Oct 1582, Fri=".(adodb_dow(1582,10,15) == 5 ? 'Fri' : '<b>Error</b>')."<br>"; |
| 446 | 477 | print " 4 Oct 1582, Thu=".(adodb_dow(1582,10,4) == 4 ? 'Thu' : '<b>Error</b>')."<br>"; |
@@ -448,37 +479,78 @@ discard block |
||
| 448 | 479 | print "<p>Testing overflow<p>"; |
| 449 | 480 | |
| 450 | 481 | $t = adodb_mktime(0,0,0,3,33,1965); |
| 451 | - if (!(adodb_date('Y-m-d',$t) == '1965-04-02')) print 'Error in day overflow 1 <br>'; |
|
| 482 | + if (!(adodb_date('Y-m-d',$t) == '1965-04-02')) |
|
| 483 | + { |
|
| 484 | + print 'Error in day overflow 1 <br>'; |
|
| 485 | + } |
|
| 452 | 486 | $t = adodb_mktime(0,0,0,4,33,1971); |
| 453 | - if (!(adodb_date('Y-m-d',$t) == '1971-05-03')) print 'Error in day overflow 2 <br>'; |
|
| 487 | + if (!(adodb_date('Y-m-d',$t) == '1971-05-03')) |
|
| 488 | + { |
|
| 489 | + print 'Error in day overflow 2 <br>'; |
|
| 490 | + } |
|
| 454 | 491 | $t = adodb_mktime(0,0,0,1,60,1965); |
| 455 | - if (!(adodb_date('Y-m-d',$t) == '1965-03-01')) print 'Error in day overflow 3 '.adodb_date('Y-m-d',$t).' <br>'; |
|
| 492 | + if (!(adodb_date('Y-m-d',$t) == '1965-03-01')) |
|
| 493 | + { |
|
| 494 | + print 'Error in day overflow 3 '.adodb_date('Y-m-d',$t).' <br>'; |
|
| 495 | + } |
|
| 456 | 496 | $t = adodb_mktime(0,0,0,12,32,1965); |
| 457 | - if (!(adodb_date('Y-m-d',$t) == '1966-01-01')) print 'Error in day overflow 4 '.adodb_date('Y-m-d',$t).' <br>'; |
|
| 497 | + if (!(adodb_date('Y-m-d',$t) == '1966-01-01')) |
|
| 498 | + { |
|
| 499 | + print 'Error in day overflow 4 '.adodb_date('Y-m-d',$t).' <br>'; |
|
| 500 | + } |
|
| 458 | 501 | $t = adodb_mktime(0,0,0,12,63,1965); |
| 459 | - if (!(adodb_date('Y-m-d',$t) == '1966-02-01')) print 'Error in day overflow 5 '.adodb_date('Y-m-d',$t).' <br>'; |
|
| 502 | + if (!(adodb_date('Y-m-d',$t) == '1966-02-01')) |
|
| 503 | + { |
|
| 504 | + print 'Error in day overflow 5 '.adodb_date('Y-m-d',$t).' <br>'; |
|
| 505 | + } |
|
| 460 | 506 | $t = adodb_mktime(0,0,0,13,3,1965); |
| 461 | - if (!(adodb_date('Y-m-d',$t) == '1966-01-03')) print 'Error in mth overflow 1 <br>'; |
|
| 507 | + if (!(adodb_date('Y-m-d',$t) == '1966-01-03')) |
|
| 508 | + { |
|
| 509 | + print 'Error in mth overflow 1 <br>'; |
|
| 510 | + } |
|
| 462 | 511 | |
| 463 | 512 | print "Testing 2-digit => 4-digit year conversion<p>"; |
| 464 | - if (adodb_year_digit_check(00) != 2000) print "Err 2-digit 2000<br>"; |
|
| 465 | - if (adodb_year_digit_check(10) != 2010) print "Err 2-digit 2010<br>"; |
|
| 466 | - if (adodb_year_digit_check(20) != 2020) print "Err 2-digit 2020<br>"; |
|
| 467 | - if (adodb_year_digit_check(30) != 2030) print "Err 2-digit 2030<br>"; |
|
| 468 | - if (adodb_year_digit_check(40) != 1940) print "Err 2-digit 1940<br>"; |
|
| 469 | - if (adodb_year_digit_check(50) != 1950) print "Err 2-digit 1950<br>"; |
|
| 470 | - if (adodb_year_digit_check(90) != 1990) print "Err 2-digit 1990<br>"; |
|
| 513 | + if (adodb_year_digit_check(00) != 2000) |
|
| 514 | + { |
|
| 515 | + print "Err 2-digit 2000<br>"; |
|
| 516 | + } |
|
| 517 | + if (adodb_year_digit_check(10) != 2010) |
|
| 518 | + { |
|
| 519 | + print "Err 2-digit 2010<br>"; |
|
| 520 | + } |
|
| 521 | + if (adodb_year_digit_check(20) != 2020) |
|
| 522 | + { |
|
| 523 | + print "Err 2-digit 2020<br>"; |
|
| 524 | + } |
|
| 525 | + if (adodb_year_digit_check(30) != 2030) |
|
| 526 | + { |
|
| 527 | + print "Err 2-digit 2030<br>"; |
|
| 528 | + } |
|
| 529 | + if (adodb_year_digit_check(40) != 1940) |
|
| 530 | + { |
|
| 531 | + print "Err 2-digit 1940<br>"; |
|
| 532 | + } |
|
| 533 | + if (adodb_year_digit_check(50) != 1950) |
|
| 534 | + { |
|
| 535 | + print "Err 2-digit 1950<br>"; |
|
| 536 | + } |
|
| 537 | + if (adodb_year_digit_check(90) != 1990) |
|
| 538 | + { |
|
| 539 | + print "Err 2-digit 1990<br>"; |
|
| 540 | + } |
|
| 471 | 541 | |
| 472 | 542 | // Test string formating |
| 473 | 543 | print "<p>Testing date formating</p>"; |
| 474 | 544 | $fmt = '\d\a\t\e T Y-m-d H:i:s a A d D F g G h H i j l L m M n O \R\F\C822 r s t U w y Y z Z 2003'; |
| 475 | 545 | $s1 = date($fmt,0); |
| 476 | 546 | $s2 = adodb_date($fmt,0); |
| 477 | - if ($s1 != $s2) { |
|
| 547 | + if ($s1 != $s2) |
|
| 548 | + { |
|
| 478 | 549 | print " date() 0 failed<br>$s1<br>$s2<br>"; |
| 479 | 550 | } |
| 480 | 551 | flush(); |
| 481 | - for ($i=100; --$i > 0; ) { |
|
| 552 | + for ($i=100; --$i > 0; ) |
|
| 553 | + { |
|
| 482 | 554 | |
| 483 | 555 | $ts = 3600.0*((rand()%60000)+(rand()%60000))+(rand()%60000); |
| 484 | 556 | $s1 = date($fmt,$ts); |
@@ -486,9 +558,12 @@ discard block |
||
| 486 | 558 | //print "$s1 <br>$s2 <p>"; |
| 487 | 559 | $pos = strcmp($s1,$s2); |
| 488 | 560 | |
| 489 | - if (($s1) != ($s2)) { |
|
| 490 | - for ($j=0,$k=strlen($s1); $j < $k; $j++) { |
|
| 491 | - if ($s1[$j] != $s2[$j]) { |
|
| 561 | + if (($s1) != ($s2)) |
|
| 562 | + { |
|
| 563 | + for ($j=0,$k=strlen($s1); $j < $k; $j++) |
|
| 564 | + { |
|
| 565 | + if ($s1[$j] != $s2[$j]) |
|
| 566 | + { |
|
| 492 | 567 | print substr($s1,$j).' '; |
| 493 | 568 | break; |
| 494 | 569 | } |
@@ -502,7 +577,8 @@ discard block |
||
| 502 | 577 | $a1 = getdate($ts); |
| 503 | 578 | $a2 = adodb_getdate($ts); |
| 504 | 579 | $rez = array_diff($a1,$a2); |
| 505 | - if (sizeof($rez)>0) { |
|
| 580 | + if (sizeof($rez)>0) |
|
| 581 | + { |
|
| 506 | 582 | print "<b>Error getdate() $ts</b><br>"; |
| 507 | 583 | print_r($a1); |
| 508 | 584 | print "<br>"; |
@@ -515,7 +591,8 @@ discard block |
||
| 515 | 591 | // Test generation of dates outside 1901-2038 |
| 516 | 592 | print "<p>Testing random dates between 100 and 4000</p>"; |
| 517 | 593 | adodb_date_test_date(100,1); |
| 518 | - for ($i=100; --$i >= 0;) { |
|
| 594 | + for ($i=100; --$i >= 0;) |
|
| 595 | + { |
|
| 519 | 596 | $y1 = 100+rand(0,1970-100); |
| 520 | 597 | $m = rand(1,12); |
| 521 | 598 | adodb_date_test_date($y1,$m); |
@@ -535,16 +612,19 @@ discard block |
||
| 535 | 612 | // and check if the roundtrip broke the original timestamp value. |
| 536 | 613 | print "Testing $start to ".($start+$yrs).", or $max seconds, offset=$offset: "; |
| 537 | 614 | $cnt = 0; |
| 538 | - for ($max += $i; $i < $max; $i += $offset) { |
|
| 615 | + for ($max += $i; $i < $max; $i += $offset) |
|
| 616 | + { |
|
| 539 | 617 | $ret = adodb_date('m,d,Y,H,i,s',$i); |
| 540 | 618 | $arr = explode(',',$ret); |
| 541 | - if ($lastyear != $arr[2]) { |
|
| 619 | + if ($lastyear != $arr[2]) |
|
| 620 | + { |
|
| 542 | 621 | $lastyear = $arr[2]; |
| 543 | 622 | print " $lastyear "; |
| 544 | 623 | flush(); |
| 545 | 624 | } |
| 546 | 625 | $newi = adodb_mktime($arr[3],$arr[4],$arr[5],$arr[0],$arr[1],$arr[2]); |
| 547 | - if ($i != $newi) { |
|
| 626 | + if ($i != $newi) |
|
| 627 | + { |
|
| 548 | 628 | print "Error at $i, adodb_mktime returned $newi ($ret)"; |
| 549 | 629 | $fail = true; |
| 550 | 630 | break; |
@@ -552,9 +632,14 @@ discard block |
||
| 552 | 632 | $cnt += 1; |
| 553 | 633 | } |
| 554 | 634 | echo "Tested $cnt dates<br>"; |
| 555 | - if (!$fail) print "<p>Passed !</p>"; |
|
| 556 | - else print "<p><b>Failed</b> :-(</p>"; |
|
| 557 | -} |
|
| 635 | + if (!$fail) |
|
| 636 | + { |
|
| 637 | + print "<p>Passed !</p>"; |
|
| 638 | + } |
|
| 639 | + else { |
|
| 640 | + print "<p><b>Failed</b> :-(</p>"; |
|
| 641 | + } |
|
| 642 | + } |
|
| 558 | 643 | |
| 559 | 644 | /** |
| 560 | 645 | Returns day of week, 0 = Sunday,... 6=Saturday. |
@@ -569,17 +654,27 @@ discard block |
||
| 569 | 654 | |
| 570 | 655 | Thursday, October 4, 1582 (Julian) was followed immediately by Friday, October 15, 1582 (Gregorian). |
| 571 | 656 | */ |
| 572 | - if ($year <= 1582) { |
|
| 657 | + if ($year <= 1582) |
|
| 658 | + { |
|
| 573 | 659 | if ($year < 1582 || |
| 574 | - ($year == 1582 && ($month < 10 || ($month == 10 && $day < 15)))) $greg_correction = 3; |
|
| 575 | - else |
|
| 660 | + ($year == 1582 && ($month < 10 || ($month == 10 && $day < 15)))) |
|
| 661 | + { |
|
| 662 | + $greg_correction = 3; |
|
| 663 | + } |
|
| 664 | + else { |
|
| 665 | + $greg_correction = 0; |
|
| 666 | + } |
|
| 667 | + } |
|
| 668 | + else { |
|
| 576 | 669 | $greg_correction = 0; |
| 577 | - } else |
|
| 578 | - $greg_correction = 0; |
|
| 670 | + } |
|
| 579 | 671 | |
| 580 | 672 | if($month > 2) |
| 581 | - $month -= 2; |
|
| 582 | - else { |
|
| 673 | + { |
|
| 674 | + $month -= 2; |
|
| 675 | + } |
|
| 676 | + else |
|
| 677 | + { |
|
| 583 | 678 | $month += 10; |
| 584 | 679 | $year--; |
| 585 | 680 | } |
@@ -598,14 +693,20 @@ discard block |
||
| 598 | 693 | Checks for leap year, returns true if it is. No 2-digit year check. Also |
| 599 | 694 | handles julian calendar correctly. |
| 600 | 695 | */ |
| 601 | -function _adodb_is_leap_year($year) |
|
| 696 | +function _adodb_is_leap_year($year) |
|
| 602 | 697 | { |
| 603 | - if ($year % 4 != 0) return false; |
|
| 698 | + if ($year % 4 != 0) |
|
| 699 | + { |
|
| 700 | + return false; |
|
| 701 | + } |
|
| 604 | 702 | |
| 605 | - if ($year % 400 == 0) { |
|
| 703 | + if ($year % 400 == 0) |
|
| 704 | + { |
|
| 606 | 705 | return true; |
| 607 | 706 | // if gregorian calendar (>1582), century not-divisible by 400 is not leap |
| 608 | - } else if ($year > 1582 && $year % 100 == 0 ) { |
|
| 707 | + } |
|
| 708 | + else if ($year > 1582 && $year % 100 == 0 ) |
|
| 709 | + { |
|
| 609 | 710 | return false; |
| 610 | 711 | } |
| 611 | 712 | |
@@ -616,7 +717,7 @@ discard block |
||
| 616 | 717 | /** |
| 617 | 718 | checks for leap year, returns true if it is. Has 2-digit year check |
| 618 | 719 | */ |
| 619 | -function adodb_is_leap_year($year) |
|
| 720 | +function adodb_is_leap_year($year) |
|
| 620 | 721 | { |
| 621 | 722 | return _adodb_is_leap_year(adodb_year_digit_check($year)); |
| 622 | 723 | } |
@@ -625,25 +726,34 @@ discard block |
||
| 625 | 726 | Fix 2-digit years. Works for any century. |
| 626 | 727 | Assumes that if 2-digit is more than 30 years in future, then previous century. |
| 627 | 728 | */ |
| 628 | -function adodb_year_digit_check($y) |
|
| 729 | +function adodb_year_digit_check($y) |
|
| 629 | 730 | { |
| 630 | - if ($y < 100) { |
|
| 731 | + if ($y < 100) |
|
| 732 | + { |
|
| 631 | 733 | |
| 632 | 734 | $yr = (integer) date("Y"); |
| 633 | 735 | $century = (integer) ($yr /100); |
| 634 | 736 | |
| 635 | - if ($yr%100 > 50) { |
|
| 737 | + if ($yr%100 > 50) |
|
| 738 | + { |
|
| 636 | 739 | $c1 = $century + 1; |
| 637 | 740 | $c0 = $century; |
| 638 | - } else { |
|
| 741 | + } |
|
| 742 | + else |
|
| 743 | + { |
|
| 639 | 744 | $c1 = $century; |
| 640 | 745 | $c0 = $century - 1; |
| 641 | 746 | } |
| 642 | 747 | $c1 *= 100; |
| 643 | 748 | // if 2-digit year is less than 30 years in future, set it to this century |
| 644 | 749 | // otherwise if more than 30 years in future, then we set 2-digit year to the prev century. |
| 645 | - if (($y + $c1) < $yr+30) $y = $y + $c1; |
|
| 646 | - else $y = $y + $c0*100; |
|
| 750 | + if (($y + $c1) < $yr+30) |
|
| 751 | + { |
|
| 752 | + $y = $y + $c1; |
|
| 753 | + } |
|
| 754 | + else { |
|
| 755 | + $y = $y + $c0*100; |
|
| 756 | + } |
|
| 647 | 757 | } |
| 648 | 758 | return $y; |
| 649 | 759 | } |
@@ -651,10 +761,13 @@ discard block |
||
| 651 | 761 | /** |
| 652 | 762 | get local time zone offset from GMT |
| 653 | 763 | */ |
| 654 | -function adodb_get_gmt_diff() |
|
| 764 | +function adodb_get_gmt_diff() |
|
| 655 | 765 | { |
| 656 | 766 | static $TZ; |
| 657 | - if (isset($TZ)) return $TZ; |
|
| 767 | + if (isset($TZ)) |
|
| 768 | + { |
|
| 769 | + return $TZ; |
|
| 770 | + } |
|
| 658 | 771 | |
| 659 | 772 | $TZ = mktime(0,0,0,1,2,1970) - gmmktime(0,0,0,1,2,1970); |
| 660 | 773 | return $TZ; |
@@ -665,11 +778,20 @@ discard block |
||
| 665 | 778 | */ |
| 666 | 779 | function adodb_getdate($d=false,$fast=false) |
| 667 | 780 | { |
| 668 | - if ($d === false) return getdate(); |
|
| 669 | - if (!defined('ADODB_TEST_DATES')) { |
|
| 670 | - if ((abs($d) <= 0x7FFFFFFF)) { // check if number in 32-bit signed range |
|
| 671 | - if (!defined('ADODB_NO_NEGATIVE_TS') || $d >= 0) // if windows, must be +ve integer |
|
| 781 | + if ($d === false) |
|
| 782 | + { |
|
| 783 | + return getdate(); |
|
| 784 | + } |
|
| 785 | + if (!defined('ADODB_TEST_DATES')) |
|
| 786 | + { |
|
| 787 | + if ((abs($d) <= 0x7FFFFFFF)) |
|
| 788 | + { |
|
| 789 | +// check if number in 32-bit signed range |
|
| 790 | + if (!defined('ADODB_NO_NEGATIVE_TS') || $d >= 0) |
|
| 791 | + { |
|
| 792 | + // if windows, must be +ve integer |
|
| 672 | 793 | return @getdate($d); |
| 794 | + } |
|
| 673 | 795 | } |
| 674 | 796 | } |
| 675 | 797 | return _adodb_getdate($d); |
@@ -710,7 +832,11 @@ discard block |
||
| 710 | 832 | $_hour_power = 3600; |
| 711 | 833 | $_min_power = 60; |
| 712 | 834 | |
| 713 | - if ($d < -12219321600) $d -= 86400*10; // if 15 Oct 1582 or earlier, gregorian correction |
|
| 835 | + if ($d < -12219321600) |
|
| 836 | + { |
|
| 837 | + $d -= 86400*10; |
|
| 838 | + } |
|
| 839 | + // if 15 Oct 1582 or earlier, gregorian correction |
|
| 714 | 840 | |
| 715 | 841 | $_month_table_normal = array("",31,28,31,30,31,30,31,31,30,31,30,31); |
| 716 | 842 | $_month_table_leaf = array("",31,29,31,30,31,30,31,31,30,31,30,31); |
@@ -718,9 +844,12 @@ discard block |
||
| 718 | 844 | $d366 = $_day_power * 366; |
| 719 | 845 | $d365 = $_day_power * 365; |
| 720 | 846 | |
| 721 | - if ($d < 0) { |
|
| 847 | + if ($d < 0) |
|
| 848 | + { |
|
| 722 | 849 | |
| 723 | - if (empty($YRS)) $YRS = array( |
|
| 850 | + if (empty($YRS)) |
|
| 851 | + { |
|
| 852 | + $YRS = array( |
|
| 724 | 853 | 1970 => 0, |
| 725 | 854 | 1960 => -315619200, |
| 726 | 855 | 1950 => -631152000, |
@@ -759,8 +888,12 @@ discard block |
||
| 759 | 888 | 1620 => -11044944000, |
| 760 | 889 | 1610 => -11360476800, |
| 761 | 890 | 1600 => -11676096000); |
| 891 | + } |
|
| 762 | 892 | |
| 763 | - if ($is_gmt) $origd = $d; |
|
| 893 | + if ($is_gmt) |
|
| 894 | + { |
|
| 895 | + $origd = $d; |
|
| 896 | + } |
|
| 764 | 897 | // The valid range of a 32bit signed timestamp is typically from |
| 765 | 898 | // Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT |
| 766 | 899 | // |
@@ -785,8 +918,10 @@ discard block |
||
| 785 | 918 | |
| 786 | 919 | $lastsecs = 0; |
| 787 | 920 | $lastyear = 1970; |
| 788 | - foreach($YRS as $year => $secs) { |
|
| 789 | - if ($d >= $secs) { |
|
| 921 | + foreach($YRS as $year => $secs) |
|
| 922 | + { |
|
| 923 | + if ($d >= $secs) |
|
| 924 | + { |
|
| 790 | 925 | $a = $lastyear; |
| 791 | 926 | break; |
| 792 | 927 | } |
@@ -795,17 +930,27 @@ discard block |
||
| 795 | 930 | } |
| 796 | 931 | |
| 797 | 932 | $d -= $lastsecs; |
| 798 | - if (!isset($a)) $a = $lastyear; |
|
| 933 | + if (!isset($a)) |
|
| 934 | + { |
|
| 935 | + $a = $lastyear; |
|
| 936 | + } |
|
| 799 | 937 | |
| 800 | 938 | //echo ' yr=',$a,' ', $d,'.'; |
| 801 | 939 | |
| 802 | - for (; --$a >= 0;) { |
|
| 940 | + for (; --$a >= 0;) |
|
| 941 | + { |
|
| 803 | 942 | $lastd = $d; |
| 804 | 943 | |
| 805 | - if ($leaf = _adodb_is_leap_year($a)) $d += $d366; |
|
| 806 | - else $d += $d365; |
|
| 944 | + if ($leaf = _adodb_is_leap_year($a)) |
|
| 945 | + { |
|
| 946 | + $d += $d366; |
|
| 947 | + } |
|
| 948 | + else { |
|
| 949 | + $d += $d365; |
|
| 950 | + } |
|
| 807 | 951 | |
| 808 | - if ($d >= 0) { |
|
| 952 | + if ($d >= 0) |
|
| 953 | + { |
|
| 809 | 954 | $year = $a; |
| 810 | 955 | break; |
| 811 | 956 | } |
@@ -816,10 +961,12 @@ discard block |
||
| 816 | 961 | |
| 817 | 962 | $d = $lastd; |
| 818 | 963 | $mtab = ($leaf) ? $_month_table_leaf : $_month_table_normal; |
| 819 | - for ($a = 13 ; --$a > 0;) { |
|
| 964 | + for ($a = 13 ; --$a > 0;) |
|
| 965 | + { |
|
| 820 | 966 | $lastd = $d; |
| 821 | 967 | $d += $mtab[$a] * $_day_power; |
| 822 | - if ($d >= 0) { |
|
| 968 | + if ($d >= 0) |
|
| 969 | + { |
|
| 823 | 970 | $month = $a; |
| 824 | 971 | $ndays = $mtab[$a]; |
| 825 | 972 | break; |
@@ -832,13 +979,22 @@ discard block |
||
| 832 | 979 | $d += ($ndays - $day+1)* $_day_power; |
| 833 | 980 | $hour = floor($d/$_hour_power); |
| 834 | 981 | |
| 835 | - } else { |
|
| 836 | - for ($a = 1970 ;; $a++) { |
|
| 982 | + } |
|
| 983 | + else |
|
| 984 | + { |
|
| 985 | + for ($a = 1970 ;; $a++) |
|
| 986 | + { |
|
| 837 | 987 | $lastd = $d; |
| 838 | 988 | |
| 839 | - if ($leaf = _adodb_is_leap_year($a)) $d -= $d366; |
|
| 840 | - else $d -= $d365; |
|
| 841 | - if ($d < 0) { |
|
| 989 | + if ($leaf = _adodb_is_leap_year($a)) |
|
| 990 | + { |
|
| 991 | + $d -= $d366; |
|
| 992 | + } |
|
| 993 | + else { |
|
| 994 | + $d -= $d365; |
|
| 995 | + } |
|
| 996 | + if ($d < 0) |
|
| 997 | + { |
|
| 842 | 998 | $year = $a; |
| 843 | 999 | break; |
| 844 | 1000 | } |
@@ -846,10 +1002,12 @@ discard block |
||
| 846 | 1002 | $secsInYear = $lastd; |
| 847 | 1003 | $d = $lastd; |
| 848 | 1004 | $mtab = ($leaf) ? $_month_table_leaf : $_month_table_normal; |
| 849 | - for ($a = 1 ; $a <= 12; $a++) { |
|
| 1005 | + for ($a = 1 ; $a <= 12; $a++) |
|
| 1006 | + { |
|
| 850 | 1007 | $lastd = $d; |
| 851 | 1008 | $d -= $mtab[$a] * $_day_power; |
| 852 | - if ($d < 0) { |
|
| 1009 | + if ($d < 0) |
|
| 1010 | + { |
|
| 853 | 1011 | $month = $a; |
| 854 | 1012 | $ndays = $mtab[$a]; |
| 855 | 1013 | break; |
@@ -864,7 +1022,8 @@ discard block |
||
| 864 | 1022 | $d -= $hour * $_hour_power; |
| 865 | 1023 | $min = floor($d/$_min_power); |
| 866 | 1024 | $secs = $d - $min * $_min_power; |
| 867 | - if ($fast) { |
|
| 1025 | + if ($fast) |
|
| 1026 | + { |
|
| 868 | 1027 | return array( |
| 869 | 1028 | 'seconds' => $secs, |
| 870 | 1029 | 'minutes' => $min, |
@@ -904,16 +1063,28 @@ discard block |
||
| 904 | 1063 | // accepts unix timestamp and iso date format in $d |
| 905 | 1064 | function adodb_date2($fmt, $d=false, $is_gmt=false) |
| 906 | 1065 | { |
| 907 | - if ($d !== false) { |
|
| 1066 | + if ($d !== false) |
|
| 1067 | + { |
|
| 908 | 1068 | if (!preg_match( |
| 909 | 1069 | "|^([0-9]{4})[-/\.]?([0-9]{1,2})[-/\.]?([0-9]{1,2})[ -]?(([0-9]{1,2}):?([0-9]{1,2}):?([0-9\.]{1,4}))?|", |
| 910 | - ($d), $rr)) return adodb_date($fmt,false,$is_gmt); |
|
| 1070 | + ($d), $rr)) |
|
| 1071 | + { |
|
| 1072 | + return adodb_date($fmt,false,$is_gmt); |
|
| 1073 | + } |
|
| 911 | 1074 | |
| 912 | - if ($rr[1] <= 100 && $rr[2]<= 1) return adodb_date($fmt,false,$is_gmt); |
|
| 1075 | + if ($rr[1] <= 100 && $rr[2]<= 1) |
|
| 1076 | + { |
|
| 1077 | + return adodb_date($fmt,false,$is_gmt); |
|
| 1078 | + } |
|
| 913 | 1079 | |
| 914 | 1080 | // h-m-s-MM-DD-YY |
| 915 | - if (!isset($rr[5])) $d = adodb_mktime(0,0,0,$rr[2],$rr[3],$rr[1]); |
|
| 916 | - else $d = @adodb_mktime($rr[5],$rr[6],$rr[7],$rr[2],$rr[3],$rr[1]); |
|
| 1081 | + if (!isset($rr[5])) |
|
| 1082 | + { |
|
| 1083 | + $d = adodb_mktime(0,0,0,$rr[2],$rr[3],$rr[1]); |
|
| 1084 | + } |
|
| 1085 | + else { |
|
| 1086 | + $d = @adodb_mktime($rr[5],$rr[6],$rr[7],$rr[2],$rr[3],$rr[1]); |
|
| 1087 | + } |
|
| 917 | 1088 | } |
| 918 | 1089 | |
| 919 | 1090 | return adodb_date($fmt,$d,$is_gmt); |
@@ -927,11 +1098,20 @@ discard block |
||
| 927 | 1098 | { |
| 928 | 1099 | static $daylight; |
| 929 | 1100 | |
| 930 | - if ($d === false) return ($is_gmt)? @gmdate($fmt): @date($fmt); |
|
| 931 | - if (!defined('ADODB_TEST_DATES')) { |
|
| 932 | - if ((abs($d) <= 0x7FFFFFFF)) { // check if number in 32-bit signed range |
|
| 933 | - if (!defined('ADODB_NO_NEGATIVE_TS') || $d >= 0) // if windows, must be +ve integer |
|
| 1101 | + if ($d === false) |
|
| 1102 | + { |
|
| 1103 | + return ($is_gmt)? @gmdate($fmt): @date($fmt); |
|
| 1104 | + } |
|
| 1105 | + if (!defined('ADODB_TEST_DATES')) |
|
| 1106 | + { |
|
| 1107 | + if ((abs($d) <= 0x7FFFFFFF)) |
|
| 1108 | + { |
|
| 1109 | +// check if number in 32-bit signed range |
|
| 1110 | + if (!defined('ADODB_NO_NEGATIVE_TS') || $d >= 0) |
|
| 1111 | + { |
|
| 1112 | + // if windows, must be +ve integer |
|
| 934 | 1113 | return ($is_gmt)? @gmdate($fmt,$d): @date($fmt,$d); |
| 1114 | + } |
|
| 935 | 1115 | |
| 936 | 1116 | } |
| 937 | 1117 | } |
@@ -939,8 +1119,14 @@ discard block |
||
| 939 | 1119 | |
| 940 | 1120 | $arr = _adodb_getdate($d,true,$is_gmt); |
| 941 | 1121 | |
| 942 | - if (!isset($daylight)) $daylight = function_exists('adodb_daylight_sv'); |
|
| 943 | - if ($daylight) adodb_daylight_sv($arr, $is_gmt); |
|
| 1122 | + if (!isset($daylight)) |
|
| 1123 | + { |
|
| 1124 | + $daylight = function_exists('adodb_daylight_sv'); |
|
| 1125 | + } |
|
| 1126 | + if ($daylight) |
|
| 1127 | + { |
|
| 1128 | + adodb_daylight_sv($arr, $is_gmt); |
|
| 1129 | + } |
|
| 944 | 1130 | |
| 945 | 1131 | $year = $arr['year']; |
| 946 | 1132 | $month = $arr['mon']; |
@@ -956,8 +1142,10 @@ discard block |
||
| 956 | 1142 | at this point, we have the following integer vars to manipulate: |
| 957 | 1143 | $year, $month, $day, $hour, $min, $secs |
| 958 | 1144 | */ |
| 959 | - for ($i=0; $i < $max; $i++) { |
|
| 960 | - switch($fmt[$i]) { |
|
| 1145 | + for ($i=0; $i < $max; $i++) |
|
| 1146 | + { |
|
| 1147 | + switch($fmt[$i]) |
|
| 1148 | + { |
|
| 961 | 1149 | case 'T': $dates .= date('T');break; |
| 962 | 1150 | // YEAR |
| 963 | 1151 | case 'L': $dates .= $arr['leap'] ? '1' : '0'; break; |
@@ -968,11 +1156,29 @@ discard block |
||
| 968 | 1156 | $dates .= gmdate('D',$_day_power*(3+adodb_dow($year,$month,$day))).', ' |
| 969 | 1157 | . ($day<10?'0'.$day:$day) . ' '.date('M',mktime(0,0,0,$month,2,1971)).' '.$year.' '; |
| 970 | 1158 | |
| 971 | - if ($hour < 10) $dates .= '0'.$hour; else $dates .= $hour; |
|
| 1159 | + if ($hour < 10) |
|
| 1160 | + { |
|
| 1161 | + $dates .= '0'.$hour; |
|
| 1162 | + } |
|
| 1163 | + else { |
|
| 1164 | + $dates .= $hour; |
|
| 1165 | + } |
|
| 972 | 1166 | |
| 973 | - if ($min < 10) $dates .= ':0'.$min; else $dates .= ':'.$min; |
|
| 1167 | + if ($min < 10) |
|
| 1168 | + { |
|
| 1169 | + $dates .= ':0'.$min; |
|
| 1170 | + } |
|
| 1171 | + else { |
|
| 1172 | + $dates .= ':'.$min; |
|
| 1173 | + } |
|
| 974 | 1174 | |
| 975 | - if ($secs < 10) $dates .= ':0'.$secs; else $dates .= ':'.$secs; |
|
| 1175 | + if ($secs < 10) |
|
| 1176 | + { |
|
| 1177 | + $dates .= ':0'.$secs; |
|
| 1178 | + } |
|
| 1179 | + else { |
|
| 1180 | + $dates .= ':'.$secs; |
|
| 1181 | + } |
|
| 976 | 1182 | |
| 977 | 1183 | $gmt = adodb_get_gmt_diff(); |
| 978 | 1184 | $dates .= sprintf(' %s%04d',($gmt<0)?'+':'-',abs($gmt)/36); break; |
@@ -980,7 +1186,14 @@ discard block |
||
| 980 | 1186 | case 'Y': $dates .= $year; break; |
| 981 | 1187 | case 'y': $dates .= substr($year,strlen($year)-2,2); break; |
| 982 | 1188 | // MONTH |
| 983 | - case 'm': if ($month<10) $dates .= '0'.$month; else $dates .= $month; break; |
|
| 1189 | + case 'm': if ($month<10) |
|
| 1190 | + { |
|
| 1191 | + $dates .= '0'.$month; |
|
| 1192 | + } |
|
| 1193 | + else { |
|
| 1194 | + $dates .= $month; |
|
| 1195 | + } |
|
| 1196 | + break; |
|
| 984 | 1197 | case 'Q': $dates .= ($month+3)>>2; break; |
| 985 | 1198 | case 'n': $dates .= $month; break; |
| 986 | 1199 | case 'M': $dates .= date('M',mktime(0,0,0,$month,2,1971)); break; |
@@ -992,13 +1205,31 @@ discard block |
||
| 992 | 1205 | case 'l': $dates .= gmdate('l',$_day_power*(3+adodb_dow($year,$month,$day))); break; |
| 993 | 1206 | case 'D': $dates .= gmdate('D',$_day_power*(3+adodb_dow($year,$month,$day))); break; |
| 994 | 1207 | case 'j': $dates .= $day; break; |
| 995 | - case 'd': if ($day<10) $dates .= '0'.$day; else $dates .= $day; break; |
|
| 1208 | + case 'd': if ($day<10) |
|
| 1209 | + { |
|
| 1210 | + $dates .= '0'.$day; |
|
| 1211 | + } |
|
| 1212 | + else { |
|
| 1213 | + $dates .= $day; |
|
| 1214 | + } |
|
| 1215 | + break; |
|
| 996 | 1216 | case 'S': |
| 997 | 1217 | $d10 = $day % 10; |
| 998 | - if ($d10 == 1) $dates .= 'st'; |
|
| 999 | - else if ($d10 == 2 && $day != 12) $dates .= 'nd'; |
|
| 1000 | - else if ($d10 == 3) $dates .= 'rd'; |
|
| 1001 | - else $dates .= 'th'; |
|
| 1218 | + if ($d10 == 1) |
|
| 1219 | + { |
|
| 1220 | + $dates .= 'st'; |
|
| 1221 | + } |
|
| 1222 | + else if ($d10 == 2 && $day != 12) |
|
| 1223 | + { |
|
| 1224 | + $dates .= 'nd'; |
|
| 1225 | + } |
|
| 1226 | + else if ($d10 == 3) |
|
| 1227 | + { |
|
| 1228 | + $dates .= 'rd'; |
|
| 1229 | + } |
|
| 1230 | + else { |
|
| 1231 | + $dates .= 'th'; |
|
| 1232 | + } |
|
| 1002 | 1233 | break; |
| 1003 | 1234 | |
| 1004 | 1235 | // HOUR |
@@ -1009,18 +1240,37 @@ discard block |
||
| 1009 | 1240 | $dates .= sprintf('%s%04d',($gmt<0)?'+':'-',abs($gmt)/36); break; |
| 1010 | 1241 | |
| 1011 | 1242 | case 'H': |
| 1012 | - if ($hour < 10) $dates .= '0'.$hour; |
|
| 1013 | - else $dates .= $hour; |
|
| 1243 | + if ($hour < 10) |
|
| 1244 | + { |
|
| 1245 | + $dates .= '0'.$hour; |
|
| 1246 | + } |
|
| 1247 | + else { |
|
| 1248 | + $dates .= $hour; |
|
| 1249 | + } |
|
| 1014 | 1250 | break; |
| 1015 | 1251 | case 'h': |
| 1016 | - if ($hour > 12) $hh = $hour - 12; |
|
| 1017 | - else { |
|
| 1018 | - if ($hour == 0) $hh = '12'; |
|
| 1019 | - else $hh = $hour; |
|
| 1252 | + if ($hour > 12) |
|
| 1253 | + { |
|
| 1254 | + $hh = $hour - 12; |
|
| 1255 | + } |
|
| 1256 | + else |
|
| 1257 | + { |
|
| 1258 | + if ($hour == 0) |
|
| 1259 | + { |
|
| 1260 | + $hh = '12'; |
|
| 1261 | + } |
|
| 1262 | + else { |
|
| 1263 | + $hh = $hour; |
|
| 1264 | + } |
|
| 1020 | 1265 | } |
| 1021 | 1266 | |
| 1022 | - if ($hh < 10) $dates .= '0'.$hh; |
|
| 1023 | - else $dates .= $hh; |
|
| 1267 | + if ($hh < 10) |
|
| 1268 | + { |
|
| 1269 | + $dates .= '0'.$hh; |
|
| 1270 | + } |
|
| 1271 | + else { |
|
| 1272 | + $dates .= $hh; |
|
| 1273 | + } |
|
| 1024 | 1274 | break; |
| 1025 | 1275 | |
| 1026 | 1276 | case 'G': |
@@ -1028,34 +1278,70 @@ discard block |
||
| 1028 | 1278 | break; |
| 1029 | 1279 | |
| 1030 | 1280 | case 'g': |
| 1031 | - if ($hour > 12) $hh = $hour - 12; |
|
| 1032 | - else { |
|
| 1033 | - if ($hour == 0) $hh = '12'; |
|
| 1034 | - else $hh = $hour; |
|
| 1281 | + if ($hour > 12) |
|
| 1282 | + { |
|
| 1283 | + $hh = $hour - 12; |
|
| 1284 | + } |
|
| 1285 | + else |
|
| 1286 | + { |
|
| 1287 | + if ($hour == 0) |
|
| 1288 | + { |
|
| 1289 | + $hh = '12'; |
|
| 1290 | + } |
|
| 1291 | + else { |
|
| 1292 | + $hh = $hour; |
|
| 1293 | + } |
|
| 1035 | 1294 | } |
| 1036 | 1295 | $dates .= $hh; |
| 1037 | 1296 | break; |
| 1038 | 1297 | // MINUTES |
| 1039 | - case 'i': if ($min < 10) $dates .= '0'.$min; else $dates .= $min; break; |
|
| 1298 | + case 'i': if ($min < 10) |
|
| 1299 | + { |
|
| 1300 | + $dates .= '0'.$min; |
|
| 1301 | + } |
|
| 1302 | + else { |
|
| 1303 | + $dates .= $min; |
|
| 1304 | + } |
|
| 1305 | + break; |
|
| 1040 | 1306 | // SECONDS |
| 1041 | 1307 | case 'U': $dates .= $d; break; |
| 1042 | - case 's': if ($secs < 10) $dates .= '0'.$secs; else $dates .= $secs; break; |
|
| 1308 | + case 's': if ($secs < 10) |
|
| 1309 | + { |
|
| 1310 | + $dates .= '0'.$secs; |
|
| 1311 | + } |
|
| 1312 | + else { |
|
| 1313 | + $dates .= $secs; |
|
| 1314 | + } |
|
| 1315 | + break; |
|
| 1043 | 1316 | // AM/PM |
| 1044 | 1317 | // Note 00:00 to 11:59 is AM, while 12:00 to 23:59 is PM |
| 1045 | 1318 | case 'a': |
| 1046 | - if ($hour>=12) $dates .= 'pm'; |
|
| 1047 | - else $dates .= 'am'; |
|
| 1319 | + if ($hour>=12) |
|
| 1320 | + { |
|
| 1321 | + $dates .= 'pm'; |
|
| 1322 | + } |
|
| 1323 | + else { |
|
| 1324 | + $dates .= 'am'; |
|
| 1325 | + } |
|
| 1048 | 1326 | break; |
| 1049 | 1327 | case 'A': |
| 1050 | - if ($hour>=12) $dates .= 'PM'; |
|
| 1051 | - else $dates .= 'AM'; |
|
| 1328 | + if ($hour>=12) |
|
| 1329 | + { |
|
| 1330 | + $dates .= 'PM'; |
|
| 1331 | + } |
|
| 1332 | + else { |
|
| 1333 | + $dates .= 'AM'; |
|
| 1334 | + } |
|
| 1052 | 1335 | break; |
| 1053 | 1336 | default: |
| 1054 | 1337 | $dates .= $fmt[$i]; break; |
| 1055 | 1338 | // ESCAPE |
| 1056 | 1339 | case "\\": |
| 1057 | 1340 | $i++; |
| 1058 | - if ($i < $max) $dates .= $fmt[$i]; |
|
| 1341 | + if ($i < $max) |
|
| 1342 | + { |
|
| 1343 | + $dates .= $fmt[$i]; |
|
| 1344 | + } |
|
| 1059 | 1345 | break; |
| 1060 | 1346 | } |
| 1061 | 1347 | } |
@@ -1077,11 +1363,13 @@ discard block |
||
| 1077 | 1363 | |
| 1078 | 1364 | Not a very fast algorithm - O(n) operation. Could be optimized to O(1). |
| 1079 | 1365 | */ |
| 1080 | -function adodb_mktime($hr,$min,$sec,$mon=false,$day=false,$year=false,$is_dst=false,$is_gmt=false) |
|
| 1366 | +function adodb_mktime($hr,$min,$sec,$mon=false,$day=false,$year=false,$is_dst=false,$is_gmt=false) |
|
| 1081 | 1367 | { |
| 1082 | - if (!defined('ADODB_TEST_DATES')) { |
|
| 1368 | + if (!defined('ADODB_TEST_DATES')) |
|
| 1369 | + { |
|
| 1083 | 1370 | |
| 1084 | - if ($mon === false) { |
|
| 1371 | + if ($mon === false) |
|
| 1372 | + { |
|
| 1085 | 1373 | return $is_gmt? @gmmktime($hr,$min,$sec): @mktime($hr,$min,$sec); |
| 1086 | 1374 | } |
| 1087 | 1375 | |
@@ -1112,11 +1400,14 @@ discard block |
||
| 1112 | 1400 | |
| 1113 | 1401 | $year = adodb_year_digit_check($year); |
| 1114 | 1402 | |
| 1115 | - if ($mon > 12) { |
|
| 1403 | + if ($mon > 12) |
|
| 1404 | + { |
|
| 1116 | 1405 | $y = floor($mon / 12); |
| 1117 | 1406 | $year += $y; |
| 1118 | 1407 | $mon -= $y*12; |
| 1119 | - } else if ($mon < 1) { |
|
| 1408 | + } |
|
| 1409 | + else if ($mon < 1) |
|
| 1410 | + { |
|
| 1120 | 1411 | $y = ceil((1-$mon) / 12); |
| 1121 | 1412 | $year -= $y; |
| 1122 | 1413 | $mon += $y*12; |
@@ -1130,20 +1421,29 @@ discard block |
||
| 1130 | 1421 | $_month_table_leaf = array("",31,29,31,30,31,30,31,31,30,31,30,31); |
| 1131 | 1422 | |
| 1132 | 1423 | $_total_date = 0; |
| 1133 | - if ($year >= 1970) { |
|
| 1134 | - for ($a = 1970 ; $a <= $year; $a++) { |
|
| 1424 | + if ($year >= 1970) |
|
| 1425 | + { |
|
| 1426 | + for ($a = 1970 ; $a <= $year; $a++) |
|
| 1427 | + { |
|
| 1135 | 1428 | $leaf = _adodb_is_leap_year($a); |
| 1136 | - if ($leaf == true) { |
|
| 1429 | + if ($leaf == true) |
|
| 1430 | + { |
|
| 1137 | 1431 | $loop_table = $_month_table_leaf; |
| 1138 | 1432 | $_add_date = 366; |
| 1139 | - } else { |
|
| 1433 | + } |
|
| 1434 | + else |
|
| 1435 | + { |
|
| 1140 | 1436 | $loop_table = $_month_table_normal; |
| 1141 | 1437 | $_add_date = 365; |
| 1142 | 1438 | } |
| 1143 | - if ($a < $year) { |
|
| 1439 | + if ($a < $year) |
|
| 1440 | + { |
|
| 1144 | 1441 | $_total_date += $_add_date; |
| 1145 | - } else { |
|
| 1146 | - for($b=1;$b<$mon;$b++) { |
|
| 1442 | + } |
|
| 1443 | + else |
|
| 1444 | + { |
|
| 1445 | + for($b=1;$b<$mon;$b++) |
|
| 1446 | + { |
|
| 1147 | 1447 | $_total_date += $loop_table[$b]; |
| 1148 | 1448 | } |
| 1149 | 1449 | } |
@@ -1151,19 +1451,30 @@ discard block |
||
| 1151 | 1451 | $_total_date +=$day-1; |
| 1152 | 1452 | $ret = $_total_date * $_day_power + $hr * $_hour_power + $min * $_min_power + $sec + $gmt_different; |
| 1153 | 1453 | |
| 1154 | - } else { |
|
| 1155 | - for ($a = 1969 ; $a >= $year; $a--) { |
|
| 1454 | + } |
|
| 1455 | + else |
|
| 1456 | + { |
|
| 1457 | + for ($a = 1969 ; $a >= $year; $a--) |
|
| 1458 | + { |
|
| 1156 | 1459 | $leaf = _adodb_is_leap_year($a); |
| 1157 | - if ($leaf == true) { |
|
| 1460 | + if ($leaf == true) |
|
| 1461 | + { |
|
| 1158 | 1462 | $loop_table = $_month_table_leaf; |
| 1159 | 1463 | $_add_date = 366; |
| 1160 | - } else { |
|
| 1464 | + } |
|
| 1465 | + else |
|
| 1466 | + { |
|
| 1161 | 1467 | $loop_table = $_month_table_normal; |
| 1162 | 1468 | $_add_date = 365; |
| 1163 | 1469 | } |
| 1164 | - if ($a > $year) { $_total_date += $_add_date; |
|
| 1165 | - } else { |
|
| 1166 | - for($b=12;$b>$mon;$b--) { |
|
| 1470 | + if ($a > $year) |
|
| 1471 | + { |
|
| 1472 | +$_total_date += $_add_date; |
|
| 1473 | + } |
|
| 1474 | + else |
|
| 1475 | + { |
|
| 1476 | + for($b=12;$b>$mon;$b--) |
|
| 1477 | + { |
|
| 1167 | 1478 | $_total_date += $loop_table[$b]; |
| 1168 | 1479 | } |
| 1169 | 1480 | } |
@@ -1173,8 +1484,16 @@ discard block |
||
| 1173 | 1484 | $_day_time = $hr * $_hour_power + $min * $_min_power + $sec; |
| 1174 | 1485 | $_day_time = $_day_power - $_day_time; |
| 1175 | 1486 | $ret = -( $_total_date * $_day_power + $_day_time - $gmt_different); |
| 1176 | - if ($ret < -12220185600) $ret += 10*86400; // if earlier than 5 Oct 1582 - gregorian correction |
|
| 1177 | - else if ($ret < -12219321600) $ret = -12219321600; // if in limbo, reset to 15 Oct 1582. |
|
| 1487 | + if ($ret < -12220185600) |
|
| 1488 | + { |
|
| 1489 | + $ret += 10*86400; |
|
| 1490 | + } |
|
| 1491 | + // if earlier than 5 Oct 1582 - gregorian correction |
|
| 1492 | + else if ($ret < -12219321600) |
|
| 1493 | + { |
|
| 1494 | + $ret = -12219321600; |
|
| 1495 | + } |
|
| 1496 | + // if in limbo, reset to 15 Oct 1582. |
|
| 1178 | 1497 | } |
| 1179 | 1498 | //print " dmy=$day/$mon/$year $hr:$min:$sec => " .$ret; |
| 1180 | 1499 | return $ret; |
@@ -1190,15 +1509,22 @@ discard block |
||
| 1190 | 1509 | { |
| 1191 | 1510 | global $ADODB_DATE_LOCALE; |
| 1192 | 1511 | |
| 1193 | - if (!defined('ADODB_TEST_DATES')) { |
|
| 1194 | - if ((abs($ts) <= 0x7FFFFFFF)) { // check if number in 32-bit signed range |
|
| 1195 | - if (!defined('ADODB_NO_NEGATIVE_TS') || $ts >= 0) // if windows, must be +ve integer |
|
| 1512 | + if (!defined('ADODB_TEST_DATES')) |
|
| 1513 | + { |
|
| 1514 | + if ((abs($ts) <= 0x7FFFFFFF)) |
|
| 1515 | + { |
|
| 1516 | +// check if number in 32-bit signed range |
|
| 1517 | + if (!defined('ADODB_NO_NEGATIVE_TS') || $ts >= 0) |
|
| 1518 | + { |
|
| 1519 | + // if windows, must be +ve integer |
|
| 1196 | 1520 | return ($is_gmt)? @gmstrftime($fmt,$ts): @strftime($fmt,$ts); |
| 1521 | + } |
|
| 1197 | 1522 | |
| 1198 | 1523 | } |
| 1199 | 1524 | } |
| 1200 | 1525 | |
| 1201 | - if (empty($ADODB_DATE_LOCALE)) { |
|
| 1526 | + if (empty($ADODB_DATE_LOCALE)) |
|
| 1527 | + { |
|
| 1202 | 1528 | $tstr = strtoupper(gmstrftime('%c',31366800)); // 30 Dec 1970, 1 am |
| 1203 | 1529 | $sep = substr($tstr,2,1); |
| 1204 | 1530 | $hasAM = strrpos($tstr,'M') !== false; |
@@ -1210,18 +1536,26 @@ discard block |
||
| 1210 | 1536 | } |
| 1211 | 1537 | $inpct = false; |
| 1212 | 1538 | $fmtdate = ''; |
| 1213 | - for ($i=0,$max = strlen($fmt); $i < $max; $i++) { |
|
| 1539 | + for ($i=0,$max = strlen($fmt); $i < $max; $i++) |
|
| 1540 | + { |
|
| 1214 | 1541 | $ch = $fmt[$i]; |
| 1215 | - if ($ch == '%') { |
|
| 1216 | - if ($inpct) { |
|
| 1542 | + if ($ch == '%') |
|
| 1543 | + { |
|
| 1544 | + if ($inpct) |
|
| 1545 | + { |
|
| 1217 | 1546 | $fmtdate .= '%'; |
| 1218 | 1547 | $inpct = false; |
| 1219 | - } else |
|
| 1220 | - $inpct = true; |
|
| 1221 | - } else if ($inpct) { |
|
| 1548 | + } |
|
| 1549 | + else { |
|
| 1550 | + $inpct = true; |
|
| 1551 | + } |
|
| 1552 | + } |
|
| 1553 | + else if ($inpct) |
|
| 1554 | + { |
|
| 1222 | 1555 | |
| 1223 | 1556 | $inpct = false; |
| 1224 | - switch($ch) { |
|
| 1557 | + switch($ch) |
|
| 1558 | + { |
|
| 1225 | 1559 | case '0': |
| 1226 | 1560 | case '1': |
| 1227 | 1561 | case '2': |
@@ -1272,13 +1606,20 @@ discard block |
||
| 1272 | 1606 | case 'Y': $fmtdate .= 'Y'; break; |
| 1273 | 1607 | case 'Z': $fmtdate .= 'T'; break; |
| 1274 | 1608 | } |
| 1275 | - } else if (('A' <= ($ch) && ($ch) <= 'Z' ) || ('a' <= ($ch) && ($ch) <= 'z' )) |
|
| 1276 | - $fmtdate .= "\\".$ch; |
|
| 1277 | - else |
|
| 1278 | - $fmtdate .= $ch; |
|
| 1609 | + } |
|
| 1610 | + else if (('A' <= ($ch) && ($ch) <= 'Z' ) || ('a' <= ($ch) && ($ch) <= 'z' )) |
|
| 1611 | + { |
|
| 1612 | + $fmtdate .= "\\".$ch; |
|
| 1613 | + } |
|
| 1614 | + else { |
|
| 1615 | + $fmtdate .= $ch; |
|
| 1616 | + } |
|
| 1279 | 1617 | } |
| 1280 | 1618 | //echo "fmt=",$fmtdate,"<br>"; |
| 1281 | - if ($ts === false) $ts = time(); |
|
| 1619 | + if ($ts === false) |
|
| 1620 | + { |
|
| 1621 | + $ts = time(); |
|
| 1622 | + } |
|
| 1282 | 1623 | $ret = adodb_date($fmtdate, $ts, $is_gmt); |
| 1283 | 1624 | return $ret; |
| 1284 | 1625 | } |
@@ -533,7 +533,7 @@ discard block |
||
| 533 | 533 | |
| 534 | 534 | // we generate a timestamp, convert it to a date, and convert it back to a timestamp |
| 535 | 535 | // and check if the roundtrip broke the original timestamp value. |
| 536 | - print "Testing $start to ".($start+$yrs).", or $max seconds, offset=$offset: "; |
|
| 536 | + print "testing $start to ".($start+$yrs).", or $max seconds, offset=$offset: "; |
|
| 537 | 537 | $cnt = 0; |
| 538 | 538 | for ($max += $i; $i < $max; $i += $offset) { |
| 539 | 539 | $ret = adodb_date('m,d,Y,H,i,s',$i); |
@@ -551,7 +551,7 @@ discard block |
||
| 551 | 551 | } |
| 552 | 552 | $cnt += 1; |
| 553 | 553 | } |
| 554 | - echo "Tested $cnt dates<br>"; |
|
| 554 | + echo "tested $cnt dates<br>"; |
|
| 555 | 555 | if (!$fail) print "<p>Passed !</p>"; |
| 556 | 556 | else print "<p><b>Failed</b> :-(</p>"; |
| 557 | 557 | } |
@@ -231,8 +231,7 @@ discard block |
||
| 231 | 231 | /** |
| 232 | 232 | * Iniitializes a new table object. |
| 233 | 233 | * |
| 234 | - * @param string $prefix DB Object prefix |
|
| 235 | - * @param array $attributes Array of table attributes. |
|
| 234 | + * @param adoSchema $parent |
|
| 236 | 235 | */ |
| 237 | 236 | function dbTable( &$parent, $attributes = NULL ) { |
| 238 | 237 | $this->parent =& $parent; |
@@ -346,7 +345,7 @@ discard block |
||
| 346 | 345 | * Adds an index to a table object |
| 347 | 346 | * |
| 348 | 347 | * @param array $attributes Index attributes |
| 349 | - * @return object dbIndex object |
|
| 348 | + * @return dbIndex dbIndex object |
|
| 350 | 349 | */ |
| 351 | 350 | function &addIndex( $attributes ) { |
| 352 | 351 | $name = strtoupper( $attributes['NAME'] ); |
@@ -446,7 +445,7 @@ discard block |
||
| 446 | 445 | * and appends them to the table object. |
| 447 | 446 | * |
| 448 | 447 | * @param string $opt Table option |
| 449 | - * @return array Options |
|
| 448 | + * @return string[] Options |
|
| 450 | 449 | */ |
| 451 | 450 | function addTableOpt( $opt ) { |
| 452 | 451 | $this->opts[] = $opt; |
@@ -621,7 +620,7 @@ discard block |
||
| 621 | 620 | /** |
| 622 | 621 | * Initializes the new dbIndex object. |
| 623 | 622 | * |
| 624 | - * @param object $parent Parent object |
|
| 623 | + * @param dbTable $parent Parent object |
|
| 625 | 624 | * @param array $attributes Attributes |
| 626 | 625 | * |
| 627 | 626 | * @internal |
@@ -710,7 +709,7 @@ discard block |
||
| 710 | 709 | * Adds options to the index |
| 711 | 710 | * |
| 712 | 711 | * @param string $opt Comma-separated list of index options. |
| 713 | - * @return string Option list |
|
| 712 | + * @return string[] Option list |
|
| 714 | 713 | */ |
| 715 | 714 | function addIndexOpt( $opt ) { |
| 716 | 715 | $this->opts[] = $opt; |
@@ -765,7 +764,7 @@ discard block |
||
| 765 | 764 | /** |
| 766 | 765 | * Initializes the new dbIndex object. |
| 767 | 766 | * |
| 768 | - * @param object $parent Parent object |
|
| 767 | + * @param dbTable $parent Parent object |
|
| 769 | 768 | * @param array $attributes Attributes |
| 770 | 769 | * |
| 771 | 770 | * @internal |
@@ -833,8 +832,6 @@ discard block |
||
| 833 | 832 | /** |
| 834 | 833 | * Adds a field to the index |
| 835 | 834 | * |
| 836 | - * @param string $name Field name |
|
| 837 | - * @return string Field list |
|
| 838 | 835 | */ |
| 839 | 836 | function addField( $attributes ) { |
| 840 | 837 | if( isset( $attributes['NAME'] ) ) { |
@@ -850,8 +847,6 @@ discard block |
||
| 850 | 847 | /** |
| 851 | 848 | * Adds options to the index |
| 852 | 849 | * |
| 853 | - * @param string $opt Comma-separated list of index options. |
|
| 854 | - * @return string Option list |
|
| 855 | 850 | */ |
| 856 | 851 | function addData( $cdata ) { |
| 857 | 852 | if( !isset( $this->data[$this->row] ) ) { |
@@ -966,7 +961,7 @@ discard block |
||
| 966 | 961 | /** |
| 967 | 962 | * Initializes the query set. |
| 968 | 963 | * |
| 969 | - * @param object $parent Parent object |
|
| 964 | + * @param adoSchema $parent Parent object |
|
| 970 | 965 | * @param array $attributes Attributes |
| 971 | 966 | */ |
| 972 | 967 | function dbQuerySet( &$parent, $attributes = NULL ) { |
@@ -1080,8 +1075,6 @@ discard block |
||
| 1080 | 1075 | /** |
| 1081 | 1076 | * Appends a line to a query that is being built line by line |
| 1082 | 1077 | * |
| 1083 | - * @param string $data Line of SQL data or NULL to initialize a new query |
|
| 1084 | - * @return string SQL query string. |
|
| 1085 | 1078 | */ |
| 1086 | 1079 | function buildQuery( $sql = NULL ) { |
| 1087 | 1080 | if( !isset( $this->query ) OR empty( $sql ) ) { |
@@ -1394,9 +1387,6 @@ discard block |
||
| 1394 | 1387 | * the filesystem and generate the SQL necessary to create the database described. |
| 1395 | 1388 | * @see ParseSchemaString() |
| 1396 | 1389 | * |
| 1397 | - * @param string $file Name of XML schema file. |
|
| 1398 | - * @param bool $returnSchema Return schema rather than parsing. |
|
| 1399 | - * @return array Array of SQL queries, ready to execute |
|
| 1400 | 1390 | */ |
| 1401 | 1391 | function ParseSchema( $filename, $returnSchema = FALSE ) { |
| 1402 | 1392 | return $this->ParseSchemaString( $this->ConvertSchemaFile( $filename ), $returnSchema ); |
@@ -1408,12 +1398,6 @@ discard block |
||
| 1408 | 1398 | * Call this method to load the specified schema from a file (see the DTD for the proper format) |
| 1409 | 1399 | * and generate the SQL necessary to create the database described by the schema. |
| 1410 | 1400 | * |
| 1411 | - * @param string $file Name of XML schema file. |
|
| 1412 | - * @param bool $returnSchema Return schema rather than parsing. |
|
| 1413 | - * @return array Array of SQL queries, ready to execute. |
|
| 1414 | - * |
|
| 1415 | - * @deprecated Replaced by adoSchema::ParseSchema() and adoSchema::ParseSchemaString() |
|
| 1416 | - * @see ParseSchema(), ParseSchemaString() |
|
| 1417 | 1401 | */ |
| 1418 | 1402 | function ParseSchemaFile( $filename, $returnSchema = FALSE ) { |
| 1419 | 1403 | // Open the file |
@@ -1502,9 +1486,6 @@ discard block |
||
| 1502 | 1486 | * the filesystem and generate the SQL necessary to remove the database described. |
| 1503 | 1487 | * @see RemoveSchemaString() |
| 1504 | 1488 | * |
| 1505 | - * @param string $file Name of XML schema file. |
|
| 1506 | - * @param bool $returnSchema Return schema rather than parsing. |
|
| 1507 | - * @return array Array of SQL queries, ready to execute |
|
| 1508 | 1489 | */ |
| 1509 | 1490 | function RemoveSchema( $filename, $returnSchema = FALSE ) { |
| 1510 | 1491 | return $this->RemoveSchemaString( $this->ConvertSchemaFile( $filename ), $returnSchema ); |
@@ -1582,7 +1563,7 @@ discard block |
||
| 1582 | 1563 | * parsed XML schema) to the filesystem. |
| 1583 | 1564 | * |
| 1584 | 1565 | * @param string $filename Path and name where the file should be saved. |
| 1585 | - * @return boolean TRUE if save is successful, else FALSE. |
|
| 1566 | + * @return false|null TRUE if save is successful, else FALSE. |
|
| 1586 | 1567 | */ |
| 1587 | 1568 | function SaveSQL( $filename = './schema.sql' ) { |
| 1588 | 1569 | |
@@ -1604,7 +1585,7 @@ discard block |
||
| 1604 | 1585 | /** |
| 1605 | 1586 | * Create an xml parser |
| 1606 | 1587 | * |
| 1607 | - * @return object PHP XML parser object |
|
| 1588 | + * @return resource PHP XML parser object |
|
| 1608 | 1589 | * |
| 1609 | 1590 | * @access private |
| 1610 | 1591 | */ |
@@ -1748,6 +1729,10 @@ discard block |
||
| 1748 | 1729 | return $result; |
| 1749 | 1730 | } |
| 1750 | 1731 | |
| 1732 | + /** |
|
| 1733 | + * @param string $schema |
|
| 1734 | + * @param string $xsl |
|
| 1735 | + */ |
|
| 1751 | 1736 | function TransformSchema( $schema, $xsl, $schematype='string' ) |
| 1752 | 1737 | { |
| 1753 | 1738 | // Fail if XSLT extension is not available |
@@ -92,45 +92,45 @@ discard block |
||
| 92 | 92 | class dbObject { |
| 93 | 93 | |
| 94 | 94 | /** |
| 95 | - * var object Parent |
|
| 96 | - */ |
|
| 95 | + * var object Parent |
|
| 96 | + */ |
|
| 97 | 97 | var $parent; |
| 98 | 98 | |
| 99 | 99 | /** |
| 100 | - * var string current element |
|
| 101 | - */ |
|
| 100 | + * var string current element |
|
| 101 | + */ |
|
| 102 | 102 | var $currentElement; |
| 103 | 103 | |
| 104 | 104 | /** |
| 105 | - * NOP |
|
| 106 | - */ |
|
| 105 | + * NOP |
|
| 106 | + */ |
|
| 107 | 107 | function dbObject( &$parent, $attributes = NULL ) { |
| 108 | 108 | $this->parent =& $parent; |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | /** |
| 112 | - * XML Callback to process start elements |
|
| 113 | - * |
|
| 114 | - * @access private |
|
| 115 | - */ |
|
| 112 | + * XML Callback to process start elements |
|
| 113 | + * |
|
| 114 | + * @access private |
|
| 115 | + */ |
|
| 116 | 116 | function _tag_open( &$parser, $tag, $attributes ) { |
| 117 | 117 | |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | /** |
| 121 | - * XML Callback to process CDATA elements |
|
| 122 | - * |
|
| 123 | - * @access private |
|
| 124 | - */ |
|
| 121 | + * XML Callback to process CDATA elements |
|
| 122 | + * |
|
| 123 | + * @access private |
|
| 124 | + */ |
|
| 125 | 125 | function _tag_cdata( &$parser, $cdata ) { |
| 126 | 126 | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | /** |
| 130 | - * XML Callback to process end elements |
|
| 131 | - * |
|
| 132 | - * @access private |
|
| 133 | - */ |
|
| 130 | + * XML Callback to process end elements |
|
| 131 | + * |
|
| 132 | + * @access private |
|
| 133 | + */ |
|
| 134 | 134 | function _tag_close( &$parser, $tag ) { |
| 135 | 135 | |
| 136 | 136 | } |
@@ -140,39 +140,39 @@ discard block |
||
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | /** |
| 143 | - * Destroys the object |
|
| 144 | - */ |
|
| 143 | + * Destroys the object |
|
| 144 | + */ |
|
| 145 | 145 | function destroy() { |
| 146 | 146 | unset( $this ); |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
| 150 | - * Checks whether the specified RDBMS is supported by the current |
|
| 151 | - * database object or its ranking ancestor. |
|
| 152 | - * |
|
| 153 | - * @param string $platform RDBMS platform name (from ADODB platform list). |
|
| 154 | - * @return boolean TRUE if RDBMS is supported; otherwise returns FALSE. |
|
| 155 | - */ |
|
| 150 | + * Checks whether the specified RDBMS is supported by the current |
|
| 151 | + * database object or its ranking ancestor. |
|
| 152 | + * |
|
| 153 | + * @param string $platform RDBMS platform name (from ADODB platform list). |
|
| 154 | + * @return boolean TRUE if RDBMS is supported; otherwise returns FALSE. |
|
| 155 | + */ |
|
| 156 | 156 | function supportedPlatform( $platform = NULL ) { |
| 157 | 157 | return is_object( $this->parent ) ? $this->parent->supportedPlatform( $platform ) : TRUE; |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | /** |
| 161 | - * Returns the prefix set by the ranking ancestor of the database object. |
|
| 162 | - * |
|
| 163 | - * @param string $name Prefix string. |
|
| 164 | - * @return string Prefix. |
|
| 165 | - */ |
|
| 161 | + * Returns the prefix set by the ranking ancestor of the database object. |
|
| 162 | + * |
|
| 163 | + * @param string $name Prefix string. |
|
| 164 | + * @return string Prefix. |
|
| 165 | + */ |
|
| 166 | 166 | function prefix( $name = '' ) { |
| 167 | 167 | return is_object( $this->parent ) ? $this->parent->prefix( $name ) : $name; |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | /** |
| 171 | - * Extracts a field ID from the specified field. |
|
| 172 | - * |
|
| 173 | - * @param string $field Field. |
|
| 174 | - * @return string Field ID. |
|
| 175 | - */ |
|
| 171 | + * Extracts a field ID from the specified field. |
|
| 172 | + * |
|
| 173 | + * @param string $field Field. |
|
| 174 | + * @return string Field ID. |
|
| 175 | + */ |
|
| 176 | 176 | function FieldID( $field ) { |
| 177 | 177 | return strtoupper( preg_replace( '/^`(.+)`$/', '$1', $field ) ); |
| 178 | 178 | } |
@@ -192,59 +192,59 @@ discard block |
||
| 192 | 192 | class dbTable extends dbObject { |
| 193 | 193 | |
| 194 | 194 | /** |
| 195 | - * @var string Table name |
|
| 196 | - */ |
|
| 195 | + * @var string Table name |
|
| 196 | + */ |
|
| 197 | 197 | var $name; |
| 198 | 198 | |
| 199 | 199 | /** |
| 200 | - * @var array Field specifier: Meta-information about each field |
|
| 201 | - */ |
|
| 200 | + * @var array Field specifier: Meta-information about each field |
|
| 201 | + */ |
|
| 202 | 202 | var $fields = array(); |
| 203 | 203 | |
| 204 | 204 | /** |
| 205 | - * @var array List of table indexes. |
|
| 206 | - */ |
|
| 205 | + * @var array List of table indexes. |
|
| 206 | + */ |
|
| 207 | 207 | var $indexes = array(); |
| 208 | 208 | |
| 209 | 209 | /** |
| 210 | - * @var array Table options: Table-level options |
|
| 211 | - */ |
|
| 210 | + * @var array Table options: Table-level options |
|
| 211 | + */ |
|
| 212 | 212 | var $opts = array(); |
| 213 | 213 | |
| 214 | 214 | /** |
| 215 | - * @var string Field index: Keeps track of which field is currently being processed |
|
| 216 | - */ |
|
| 215 | + * @var string Field index: Keeps track of which field is currently being processed |
|
| 216 | + */ |
|
| 217 | 217 | var $current_field; |
| 218 | 218 | |
| 219 | 219 | /** |
| 220 | - * @var boolean Mark table for destruction |
|
| 221 | - * @access private |
|
| 222 | - */ |
|
| 220 | + * @var boolean Mark table for destruction |
|
| 221 | + * @access private |
|
| 222 | + */ |
|
| 223 | 223 | var $drop_table; |
| 224 | 224 | |
| 225 | 225 | /** |
| 226 | - * @var boolean Mark field for destruction (not yet implemented) |
|
| 227 | - * @access private |
|
| 228 | - */ |
|
| 226 | + * @var boolean Mark field for destruction (not yet implemented) |
|
| 227 | + * @access private |
|
| 228 | + */ |
|
| 229 | 229 | var $drop_field = array(); |
| 230 | 230 | |
| 231 | 231 | /** |
| 232 | - * Iniitializes a new table object. |
|
| 233 | - * |
|
| 234 | - * @param string $prefix DB Object prefix |
|
| 235 | - * @param array $attributes Array of table attributes. |
|
| 236 | - */ |
|
| 232 | + * Iniitializes a new table object. |
|
| 233 | + * |
|
| 234 | + * @param string $prefix DB Object prefix |
|
| 235 | + * @param array $attributes Array of table attributes. |
|
| 236 | + */ |
|
| 237 | 237 | function dbTable( &$parent, $attributes = NULL ) { |
| 238 | 238 | $this->parent =& $parent; |
| 239 | 239 | $this->name = $this->prefix($attributes['NAME']); |
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | /** |
| 243 | - * XML Callback to process start elements. Elements currently |
|
| 244 | - * processed are: INDEX, DROP, FIELD, KEY, NOTNULL, AUTOINCREMENT & DEFAULT. |
|
| 245 | - * |
|
| 246 | - * @access private |
|
| 247 | - */ |
|
| 243 | + * XML Callback to process start elements. Elements currently |
|
| 244 | + * processed are: INDEX, DROP, FIELD, KEY, NOTNULL, AUTOINCREMENT & DEFAULT. |
|
| 245 | + * |
|
| 246 | + * @access private |
|
| 247 | + */ |
|
| 248 | 248 | function _tag_open( &$parser, $tag, $attributes ) { |
| 249 | 249 | $this->currentElement = strtoupper( $tag ); |
| 250 | 250 | |
@@ -298,10 +298,10 @@ discard block |
||
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | /** |
| 301 | - * XML Callback to process CDATA elements |
|
| 302 | - * |
|
| 303 | - * @access private |
|
| 304 | - */ |
|
| 301 | + * XML Callback to process CDATA elements |
|
| 302 | + * |
|
| 303 | + * @access private |
|
| 304 | + */ |
|
| 305 | 305 | function _tag_cdata( &$parser, $cdata ) { |
| 306 | 306 | switch( $this->currentElement ) { |
| 307 | 307 | // Table constraint |
@@ -322,10 +322,10 @@ discard block |
||
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | /** |
| 325 | - * XML Callback to process end elements |
|
| 326 | - * |
|
| 327 | - * @access private |
|
| 328 | - */ |
|
| 325 | + * XML Callback to process end elements |
|
| 326 | + * |
|
| 327 | + * @access private |
|
| 328 | + */ |
|
| 329 | 329 | function _tag_close( &$parser, $tag ) { |
| 330 | 330 | $this->currentElement = ''; |
| 331 | 331 | |
@@ -343,11 +343,11 @@ discard block |
||
| 343 | 343 | } |
| 344 | 344 | |
| 345 | 345 | /** |
| 346 | - * Adds an index to a table object |
|
| 347 | - * |
|
| 348 | - * @param array $attributes Index attributes |
|
| 349 | - * @return object dbIndex object |
|
| 350 | - */ |
|
| 346 | + * Adds an index to a table object |
|
| 347 | + * |
|
| 348 | + * @param array $attributes Index attributes |
|
| 349 | + * @return object dbIndex object |
|
| 350 | + */ |
|
| 351 | 351 | function &addIndex( $attributes ) { |
| 352 | 352 | $name = strtoupper( $attributes['NAME'] ); |
| 353 | 353 | $this->indexes[$name] = new dbIndex( $this, $attributes ); |
@@ -355,11 +355,11 @@ discard block |
||
| 355 | 355 | } |
| 356 | 356 | |
| 357 | 357 | /** |
| 358 | - * Adds data to a table object |
|
| 359 | - * |
|
| 360 | - * @param array $attributes Data attributes |
|
| 361 | - * @return object dbData object |
|
| 362 | - */ |
|
| 358 | + * Adds data to a table object |
|
| 359 | + * |
|
| 360 | + * @param array $attributes Data attributes |
|
| 361 | + * @return object dbData object |
|
| 362 | + */ |
|
| 363 | 363 | function &addData( $attributes ) { |
| 364 | 364 | if( !isset( $this->data ) ) { |
| 365 | 365 | $this->data = new dbData( $this, $attributes ); |
@@ -368,34 +368,34 @@ discard block |
||
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | /** |
| 371 | - * Adds a field to a table object |
|
| 372 | - * |
|
| 373 | - * $name is the name of the table to which the field should be added. |
|
| 374 | - * $type is an ADODB datadict field type. The following field types |
|
| 375 | - * are supported as of ADODB 3.40: |
|
| 376 | - * - C: varchar |
|
| 377 | - * - X: CLOB (character large object) or largest varchar size |
|
| 378 | - * if CLOB is not supported |
|
| 379 | - * - C2: Multibyte varchar |
|
| 380 | - * - X2: Multibyte CLOB |
|
| 381 | - * - B: BLOB (binary large object) |
|
| 382 | - * - D: Date (some databases do not support this, and we return a datetime type) |
|
| 383 | - * - T: Datetime or Timestamp |
|
| 384 | - * - L: Integer field suitable for storing booleans (0 or 1) |
|
| 385 | - * - I: Integer (mapped to I4) |
|
| 386 | - * - I1: 1-byte integer |
|
| 387 | - * - I2: 2-byte integer |
|
| 388 | - * - I4: 4-byte integer |
|
| 389 | - * - I8: 8-byte integer |
|
| 390 | - * - F: Floating point number |
|
| 391 | - * - N: Numeric or decimal number |
|
| 392 | - * |
|
| 393 | - * @param string $name Name of the table to which the field will be added. |
|
| 394 | - * @param string $type ADODB datadict field type. |
|
| 395 | - * @param string $size Field size |
|
| 396 | - * @param array $opts Field options array |
|
| 397 | - * @return array Field specifier array |
|
| 398 | - */ |
|
| 371 | + * Adds a field to a table object |
|
| 372 | + * |
|
| 373 | + * $name is the name of the table to which the field should be added. |
|
| 374 | + * $type is an ADODB datadict field type. The following field types |
|
| 375 | + * are supported as of ADODB 3.40: |
|
| 376 | + * - C: varchar |
|
| 377 | + * - X: CLOB (character large object) or largest varchar size |
|
| 378 | + * if CLOB is not supported |
|
| 379 | + * - C2: Multibyte varchar |
|
| 380 | + * - X2: Multibyte CLOB |
|
| 381 | + * - B: BLOB (binary large object) |
|
| 382 | + * - D: Date (some databases do not support this, and we return a datetime type) |
|
| 383 | + * - T: Datetime or Timestamp |
|
| 384 | + * - L: Integer field suitable for storing booleans (0 or 1) |
|
| 385 | + * - I: Integer (mapped to I4) |
|
| 386 | + * - I1: 1-byte integer |
|
| 387 | + * - I2: 2-byte integer |
|
| 388 | + * - I4: 4-byte integer |
|
| 389 | + * - I8: 8-byte integer |
|
| 390 | + * - F: Floating point number |
|
| 391 | + * - N: Numeric or decimal number |
|
| 392 | + * |
|
| 393 | + * @param string $name Name of the table to which the field will be added. |
|
| 394 | + * @param string $type ADODB datadict field type. |
|
| 395 | + * @param string $size Field size |
|
| 396 | + * @param array $opts Field options array |
|
| 397 | + * @return array Field specifier array |
|
| 398 | + */ |
|
| 399 | 399 | function addField( $name, $type, $size = NULL, $opts = NULL ) { |
| 400 | 400 | $field_id = $this->FieldID( $name ); |
| 401 | 401 | |
@@ -420,16 +420,16 @@ discard block |
||
| 420 | 420 | } |
| 421 | 421 | |
| 422 | 422 | /** |
| 423 | - * Adds a field option to the current field specifier |
|
| 424 | - * |
|
| 425 | - * This method adds a field option allowed by the ADOdb datadict |
|
| 426 | - * and appends it to the given field. |
|
| 427 | - * |
|
| 428 | - * @param string $field Field name |
|
| 429 | - * @param string $opt ADOdb field option |
|
| 430 | - * @param mixed $value Field option value |
|
| 431 | - * @return array Field specifier array |
|
| 432 | - */ |
|
| 423 | + * Adds a field option to the current field specifier |
|
| 424 | + * |
|
| 425 | + * This method adds a field option allowed by the ADOdb datadict |
|
| 426 | + * and appends it to the given field. |
|
| 427 | + * |
|
| 428 | + * @param string $field Field name |
|
| 429 | + * @param string $opt ADOdb field option |
|
| 430 | + * @param mixed $value Field option value |
|
| 431 | + * @return array Field specifier array |
|
| 432 | + */ |
|
| 433 | 433 | function addFieldOpt( $field, $opt, $value = NULL ) { |
| 434 | 434 | if( !isset( $value ) ) { |
| 435 | 435 | $this->fields[$this->FieldID( $field )]['OPTS'][] = $opt; |
@@ -440,14 +440,14 @@ discard block |
||
| 440 | 440 | } |
| 441 | 441 | |
| 442 | 442 | /** |
| 443 | - * Adds an option to the table |
|
| 444 | - * |
|
| 445 | - * This method takes a comma-separated list of table-level options |
|
| 446 | - * and appends them to the table object. |
|
| 447 | - * |
|
| 448 | - * @param string $opt Table option |
|
| 449 | - * @return array Options |
|
| 450 | - */ |
|
| 443 | + * Adds an option to the table |
|
| 444 | + * |
|
| 445 | + * This method takes a comma-separated list of table-level options |
|
| 446 | + * and appends them to the table object. |
|
| 447 | + * |
|
| 448 | + * @param string $opt Table option |
|
| 449 | + * @return array Options |
|
| 450 | + */ |
|
| 451 | 451 | function addTableOpt( $opt ) { |
| 452 | 452 | $this->opts[] = $opt; |
| 453 | 453 | |
@@ -455,11 +455,11 @@ discard block |
||
| 455 | 455 | } |
| 456 | 456 | |
| 457 | 457 | /** |
| 458 | - * Generates the SQL that will create the table in the database |
|
| 459 | - * |
|
| 460 | - * @param object $xmls adoSchema object |
|
| 461 | - * @return array Array containing table creation SQL |
|
| 462 | - */ |
|
| 458 | + * Generates the SQL that will create the table in the database |
|
| 459 | + * |
|
| 460 | + * @param object $xmls adoSchema object |
|
| 461 | + * @return array Array containing table creation SQL |
|
| 462 | + */ |
|
| 463 | 463 | function create( &$xmls ) { |
| 464 | 464 | $sql = array(); |
| 465 | 465 | |
@@ -567,8 +567,8 @@ discard block |
||
| 567 | 567 | } |
| 568 | 568 | |
| 569 | 569 | /** |
| 570 | - * Marks a field or table for destruction |
|
| 571 | - */ |
|
| 570 | + * Marks a field or table for destruction |
|
| 571 | + */ |
|
| 572 | 572 | function drop() { |
| 573 | 573 | if( isset( $this->current_field ) ) { |
| 574 | 574 | // Drop the current field |
@@ -598,34 +598,34 @@ discard block |
||
| 598 | 598 | class dbIndex extends dbObject { |
| 599 | 599 | |
| 600 | 600 | /** |
| 601 | - * @var string Index name |
|
| 602 | - */ |
|
| 601 | + * @var string Index name |
|
| 602 | + */ |
|
| 603 | 603 | var $name; |
| 604 | 604 | |
| 605 | 605 | /** |
| 606 | - * @var array Index options: Index-level options |
|
| 607 | - */ |
|
| 606 | + * @var array Index options: Index-level options |
|
| 607 | + */ |
|
| 608 | 608 | var $opts = array(); |
| 609 | 609 | |
| 610 | 610 | /** |
| 611 | - * @var array Indexed fields: Table columns included in this index |
|
| 612 | - */ |
|
| 611 | + * @var array Indexed fields: Table columns included in this index |
|
| 612 | + */ |
|
| 613 | 613 | var $columns = array(); |
| 614 | 614 | |
| 615 | 615 | /** |
| 616 | - * @var boolean Mark index for destruction |
|
| 617 | - * @access private |
|
| 618 | - */ |
|
| 616 | + * @var boolean Mark index for destruction |
|
| 617 | + * @access private |
|
| 618 | + */ |
|
| 619 | 619 | var $drop = FALSE; |
| 620 | 620 | |
| 621 | 621 | /** |
| 622 | - * Initializes the new dbIndex object. |
|
| 623 | - * |
|
| 624 | - * @param object $parent Parent object |
|
| 625 | - * @param array $attributes Attributes |
|
| 626 | - * |
|
| 627 | - * @internal |
|
| 628 | - */ |
|
| 622 | + * Initializes the new dbIndex object. |
|
| 623 | + * |
|
| 624 | + * @param object $parent Parent object |
|
| 625 | + * @param array $attributes Attributes |
|
| 626 | + * |
|
| 627 | + * @internal |
|
| 628 | + */ |
|
| 629 | 629 | function dbIndex( &$parent, $attributes = NULL ) { |
| 630 | 630 | $this->parent =& $parent; |
| 631 | 631 | |
@@ -633,13 +633,13 @@ discard block |
||
| 633 | 633 | } |
| 634 | 634 | |
| 635 | 635 | /** |
| 636 | - * XML Callback to process start elements |
|
| 637 | - * |
|
| 638 | - * Processes XML opening tags. |
|
| 639 | - * Elements currently processed are: DROP, CLUSTERED, BITMAP, UNIQUE, FULLTEXT & HASH. |
|
| 640 | - * |
|
| 641 | - * @access private |
|
| 642 | - */ |
|
| 636 | + * XML Callback to process start elements |
|
| 637 | + * |
|
| 638 | + * Processes XML opening tags. |
|
| 639 | + * Elements currently processed are: DROP, CLUSTERED, BITMAP, UNIQUE, FULLTEXT & HASH. |
|
| 640 | + * |
|
| 641 | + * @access private |
|
| 642 | + */ |
|
| 643 | 643 | function _tag_open( &$parser, $tag, $attributes ) { |
| 644 | 644 | $this->currentElement = strtoupper( $tag ); |
| 645 | 645 | |
@@ -661,12 +661,12 @@ discard block |
||
| 661 | 661 | } |
| 662 | 662 | |
| 663 | 663 | /** |
| 664 | - * XML Callback to process CDATA elements |
|
| 665 | - * |
|
| 666 | - * Processes XML cdata. |
|
| 667 | - * |
|
| 668 | - * @access private |
|
| 669 | - */ |
|
| 664 | + * XML Callback to process CDATA elements |
|
| 665 | + * |
|
| 666 | + * Processes XML cdata. |
|
| 667 | + * |
|
| 668 | + * @access private |
|
| 669 | + */ |
|
| 670 | 670 | function _tag_cdata( &$parser, $cdata ) { |
| 671 | 671 | switch( $this->currentElement ) { |
| 672 | 672 | // Index field name |
@@ -679,10 +679,10 @@ discard block |
||
| 679 | 679 | } |
| 680 | 680 | |
| 681 | 681 | /** |
| 682 | - * XML Callback to process end elements |
|
| 683 | - * |
|
| 684 | - * @access private |
|
| 685 | - */ |
|
| 682 | + * XML Callback to process end elements |
|
| 683 | + * |
|
| 684 | + * @access private |
|
| 685 | + */ |
|
| 686 | 686 | function _tag_close( &$parser, $tag ) { |
| 687 | 687 | $this->currentElement = ''; |
| 688 | 688 | |
@@ -694,11 +694,11 @@ discard block |
||
| 694 | 694 | } |
| 695 | 695 | |
| 696 | 696 | /** |
| 697 | - * Adds a field to the index |
|
| 698 | - * |
|
| 699 | - * @param string $name Field name |
|
| 700 | - * @return string Field list |
|
| 701 | - */ |
|
| 697 | + * Adds a field to the index |
|
| 698 | + * |
|
| 699 | + * @param string $name Field name |
|
| 700 | + * @return string Field list |
|
| 701 | + */ |
|
| 702 | 702 | function addField( $name ) { |
| 703 | 703 | $this->columns[$this->FieldID( $name )] = $name; |
| 704 | 704 | |
@@ -707,11 +707,11 @@ discard block |
||
| 707 | 707 | } |
| 708 | 708 | |
| 709 | 709 | /** |
| 710 | - * Adds options to the index |
|
| 711 | - * |
|
| 712 | - * @param string $opt Comma-separated list of index options. |
|
| 713 | - * @return string Option list |
|
| 714 | - */ |
|
| 710 | + * Adds options to the index |
|
| 711 | + * |
|
| 712 | + * @param string $opt Comma-separated list of index options. |
|
| 713 | + * @return string Option list |
|
| 714 | + */ |
|
| 715 | 715 | function addIndexOpt( $opt ) { |
| 716 | 716 | $this->opts[] = $opt; |
| 717 | 717 | |
@@ -720,11 +720,11 @@ discard block |
||
| 720 | 720 | } |
| 721 | 721 | |
| 722 | 722 | /** |
| 723 | - * Generates the SQL that will create the index in the database |
|
| 724 | - * |
|
| 725 | - * @param object $xmls adoSchema object |
|
| 726 | - * @return array Array containing index creation SQL |
|
| 727 | - */ |
|
| 723 | + * Generates the SQL that will create the index in the database |
|
| 724 | + * |
|
| 725 | + * @param object $xmls adoSchema object |
|
| 726 | + * @return array Array containing index creation SQL |
|
| 727 | + */ |
|
| 728 | 728 | function create( &$xmls ) { |
| 729 | 729 | if( $this->drop ) { |
| 730 | 730 | return NULL; |
@@ -741,8 +741,8 @@ discard block |
||
| 741 | 741 | } |
| 742 | 742 | |
| 743 | 743 | /** |
| 744 | - * Marks an index for destruction |
|
| 745 | - */ |
|
| 744 | + * Marks an index for destruction |
|
| 745 | + */ |
|
| 746 | 746 | function drop() { |
| 747 | 747 | $this->drop = TRUE; |
| 748 | 748 | } |
@@ -763,25 +763,25 @@ discard block |
||
| 763 | 763 | var $row; |
| 764 | 764 | |
| 765 | 765 | /** |
| 766 | - * Initializes the new dbIndex object. |
|
| 767 | - * |
|
| 768 | - * @param object $parent Parent object |
|
| 769 | - * @param array $attributes Attributes |
|
| 770 | - * |
|
| 771 | - * @internal |
|
| 772 | - */ |
|
| 766 | + * Initializes the new dbIndex object. |
|
| 767 | + * |
|
| 768 | + * @param object $parent Parent object |
|
| 769 | + * @param array $attributes Attributes |
|
| 770 | + * |
|
| 771 | + * @internal |
|
| 772 | + */ |
|
| 773 | 773 | function dbData( &$parent, $attributes = NULL ) { |
| 774 | 774 | $this->parent =& $parent; |
| 775 | 775 | } |
| 776 | 776 | |
| 777 | 777 | /** |
| 778 | - * XML Callback to process start elements |
|
| 779 | - * |
|
| 780 | - * Processes XML opening tags. |
|
| 781 | - * Elements currently processed are: DROP, CLUSTERED, BITMAP, UNIQUE, FULLTEXT & HASH. |
|
| 782 | - * |
|
| 783 | - * @access private |
|
| 784 | - */ |
|
| 778 | + * XML Callback to process start elements |
|
| 779 | + * |
|
| 780 | + * Processes XML opening tags. |
|
| 781 | + * Elements currently processed are: DROP, CLUSTERED, BITMAP, UNIQUE, FULLTEXT & HASH. |
|
| 782 | + * |
|
| 783 | + * @access private |
|
| 784 | + */ |
|
| 785 | 785 | function _tag_open( &$parser, $tag, $attributes ) { |
| 786 | 786 | $this->currentElement = strtoupper( $tag ); |
| 787 | 787 | |
@@ -798,12 +798,12 @@ discard block |
||
| 798 | 798 | } |
| 799 | 799 | |
| 800 | 800 | /** |
| 801 | - * XML Callback to process CDATA elements |
|
| 802 | - * |
|
| 803 | - * Processes XML cdata. |
|
| 804 | - * |
|
| 805 | - * @access private |
|
| 806 | - */ |
|
| 801 | + * XML Callback to process CDATA elements |
|
| 802 | + * |
|
| 803 | + * Processes XML cdata. |
|
| 804 | + * |
|
| 805 | + * @access private |
|
| 806 | + */ |
|
| 807 | 807 | function _tag_cdata( &$parser, $cdata ) { |
| 808 | 808 | switch( $this->currentElement ) { |
| 809 | 809 | // Index field name |
@@ -816,10 +816,10 @@ discard block |
||
| 816 | 816 | } |
| 817 | 817 | |
| 818 | 818 | /** |
| 819 | - * XML Callback to process end elements |
|
| 820 | - * |
|
| 821 | - * @access private |
|
| 822 | - */ |
|
| 819 | + * XML Callback to process end elements |
|
| 820 | + * |
|
| 821 | + * @access private |
|
| 822 | + */ |
|
| 823 | 823 | function _tag_close( &$parser, $tag ) { |
| 824 | 824 | $this->currentElement = ''; |
| 825 | 825 | |
@@ -831,11 +831,11 @@ discard block |
||
| 831 | 831 | } |
| 832 | 832 | |
| 833 | 833 | /** |
| 834 | - * Adds a field to the index |
|
| 835 | - * |
|
| 836 | - * @param string $name Field name |
|
| 837 | - * @return string Field list |
|
| 838 | - */ |
|
| 834 | + * Adds a field to the index |
|
| 835 | + * |
|
| 836 | + * @param string $name Field name |
|
| 837 | + * @return string Field list |
|
| 838 | + */ |
|
| 839 | 839 | function addField( $attributes ) { |
| 840 | 840 | if( isset( $attributes['NAME'] ) ) { |
| 841 | 841 | $name = $attributes['NAME']; |
@@ -848,11 +848,11 @@ discard block |
||
| 848 | 848 | } |
| 849 | 849 | |
| 850 | 850 | /** |
| 851 | - * Adds options to the index |
|
| 852 | - * |
|
| 853 | - * @param string $opt Comma-separated list of index options. |
|
| 854 | - * @return string Option list |
|
| 855 | - */ |
|
| 851 | + * Adds options to the index |
|
| 852 | + * |
|
| 853 | + * @param string $opt Comma-separated list of index options. |
|
| 854 | + * @return string Option list |
|
| 855 | + */ |
|
| 856 | 856 | function addData( $cdata ) { |
| 857 | 857 | if( !isset( $this->data[$this->row] ) ) { |
| 858 | 858 | $this->data[$this->row] = array(); |
@@ -866,11 +866,11 @@ discard block |
||
| 866 | 866 | } |
| 867 | 867 | |
| 868 | 868 | /** |
| 869 | - * Generates the SQL that will create the index in the database |
|
| 870 | - * |
|
| 871 | - * @param object $xmls adoSchema object |
|
| 872 | - * @return array Array containing index creation SQL |
|
| 873 | - */ |
|
| 869 | + * Generates the SQL that will create the index in the database |
|
| 870 | + * |
|
| 871 | + * @param object $xmls adoSchema object |
|
| 872 | + * @return array Array containing index creation SQL |
|
| 873 | + */ |
|
| 874 | 874 | function create( &$xmls ) { |
| 875 | 875 | $table = $xmls->dict->TableName($this->parent->name); |
| 876 | 876 | $table_field_count = count($this->parent->fields); |
@@ -944,31 +944,31 @@ discard block |
||
| 944 | 944 | class dbQuerySet extends dbObject { |
| 945 | 945 | |
| 946 | 946 | /** |
| 947 | - * @var array List of SQL queries |
|
| 948 | - */ |
|
| 947 | + * @var array List of SQL queries |
|
| 948 | + */ |
|
| 949 | 949 | var $queries = array(); |
| 950 | 950 | |
| 951 | 951 | /** |
| 952 | - * @var string String used to build of a query line by line |
|
| 953 | - */ |
|
| 952 | + * @var string String used to build of a query line by line |
|
| 953 | + */ |
|
| 954 | 954 | var $query; |
| 955 | 955 | |
| 956 | 956 | /** |
| 957 | - * @var string Query prefix key |
|
| 958 | - */ |
|
| 957 | + * @var string Query prefix key |
|
| 958 | + */ |
|
| 959 | 959 | var $prefixKey = ''; |
| 960 | 960 | |
| 961 | 961 | /** |
| 962 | - * @var boolean Auto prefix enable (TRUE) |
|
| 963 | - */ |
|
| 962 | + * @var boolean Auto prefix enable (TRUE) |
|
| 963 | + */ |
|
| 964 | 964 | var $prefixMethod = 'AUTO'; |
| 965 | 965 | |
| 966 | 966 | /** |
| 967 | - * Initializes the query set. |
|
| 968 | - * |
|
| 969 | - * @param object $parent Parent object |
|
| 970 | - * @param array $attributes Attributes |
|
| 971 | - */ |
|
| 967 | + * Initializes the query set. |
|
| 968 | + * |
|
| 969 | + * @param object $parent Parent object |
|
| 970 | + * @param array $attributes Attributes |
|
| 971 | + */ |
|
| 972 | 972 | function dbQuerySet( &$parent, $attributes = NULL ) { |
| 973 | 973 | $this->parent =& $parent; |
| 974 | 974 | |
@@ -994,11 +994,11 @@ discard block |
||
| 994 | 994 | } |
| 995 | 995 | |
| 996 | 996 | /** |
| 997 | - * XML Callback to process start elements. Elements currently |
|
| 998 | - * processed are: QUERY. |
|
| 999 | - * |
|
| 1000 | - * @access private |
|
| 1001 | - */ |
|
| 997 | + * XML Callback to process start elements. Elements currently |
|
| 998 | + * processed are: QUERY. |
|
| 999 | + * |
|
| 1000 | + * @access private |
|
| 1001 | + */ |
|
| 1002 | 1002 | function _tag_open( &$parser, $tag, $attributes ) { |
| 1003 | 1003 | $this->currentElement = strtoupper( $tag ); |
| 1004 | 1004 | |
@@ -1019,8 +1019,8 @@ discard block |
||
| 1019 | 1019 | } |
| 1020 | 1020 | |
| 1021 | 1021 | /** |
| 1022 | - * XML Callback to process CDATA elements |
|
| 1023 | - */ |
|
| 1022 | + * XML Callback to process CDATA elements |
|
| 1023 | + */ |
|
| 1024 | 1024 | function _tag_cdata( &$parser, $cdata ) { |
| 1025 | 1025 | switch( $this->currentElement ) { |
| 1026 | 1026 | // Line of queryset SQL data |
@@ -1033,10 +1033,10 @@ discard block |
||
| 1033 | 1033 | } |
| 1034 | 1034 | |
| 1035 | 1035 | /** |
| 1036 | - * XML Callback to process end elements |
|
| 1037 | - * |
|
| 1038 | - * @access private |
|
| 1039 | - */ |
|
| 1036 | + * XML Callback to process end elements |
|
| 1037 | + * |
|
| 1038 | + * @access private |
|
| 1039 | + */ |
|
| 1040 | 1040 | function _tag_close( &$parser, $tag ) { |
| 1041 | 1041 | $this->currentElement = ''; |
| 1042 | 1042 | |
@@ -1056,10 +1056,10 @@ discard block |
||
| 1056 | 1056 | } |
| 1057 | 1057 | |
| 1058 | 1058 | /** |
| 1059 | - * Re-initializes the query. |
|
| 1060 | - * |
|
| 1061 | - * @return boolean TRUE |
|
| 1062 | - */ |
|
| 1059 | + * Re-initializes the query. |
|
| 1060 | + * |
|
| 1061 | + * @return boolean TRUE |
|
| 1062 | + */ |
|
| 1063 | 1063 | function newQuery() { |
| 1064 | 1064 | $this->query = ''; |
| 1065 | 1065 | |
@@ -1067,10 +1067,10 @@ discard block |
||
| 1067 | 1067 | } |
| 1068 | 1068 | |
| 1069 | 1069 | /** |
| 1070 | - * Discards the existing query. |
|
| 1071 | - * |
|
| 1072 | - * @return boolean TRUE |
|
| 1073 | - */ |
|
| 1070 | + * Discards the existing query. |
|
| 1071 | + * |
|
| 1072 | + * @return boolean TRUE |
|
| 1073 | + */ |
|
| 1074 | 1074 | function discardQuery() { |
| 1075 | 1075 | unset( $this->query ); |
| 1076 | 1076 | |
@@ -1078,11 +1078,11 @@ discard block |
||
| 1078 | 1078 | } |
| 1079 | 1079 | |
| 1080 | 1080 | /** |
| 1081 | - * Appends a line to a query that is being built line by line |
|
| 1082 | - * |
|
| 1083 | - * @param string $data Line of SQL data or NULL to initialize a new query |
|
| 1084 | - * @return string SQL query string. |
|
| 1085 | - */ |
|
| 1081 | + * Appends a line to a query that is being built line by line |
|
| 1082 | + * |
|
| 1083 | + * @param string $data Line of SQL data or NULL to initialize a new query |
|
| 1084 | + * @return string SQL query string. |
|
| 1085 | + */ |
|
| 1086 | 1086 | function buildQuery( $sql = NULL ) { |
| 1087 | 1087 | if( !isset( $this->query ) OR empty( $sql ) ) { |
| 1088 | 1088 | return FALSE; |
@@ -1094,10 +1094,10 @@ discard block |
||
| 1094 | 1094 | } |
| 1095 | 1095 | |
| 1096 | 1096 | /** |
| 1097 | - * Adds a completed query to the query list |
|
| 1098 | - * |
|
| 1099 | - * @return string SQL of added query |
|
| 1100 | - */ |
|
| 1097 | + * Adds a completed query to the query list |
|
| 1098 | + * |
|
| 1099 | + * @return string SQL of added query |
|
| 1100 | + */ |
|
| 1101 | 1101 | function addQuery() { |
| 1102 | 1102 | if( !isset( $this->query ) ) { |
| 1103 | 1103 | return FALSE; |
@@ -1111,11 +1111,11 @@ discard block |
||
| 1111 | 1111 | } |
| 1112 | 1112 | |
| 1113 | 1113 | /** |
| 1114 | - * Creates and returns the current query set |
|
| 1115 | - * |
|
| 1116 | - * @param object $xmls adoSchema object |
|
| 1117 | - * @return array Query set |
|
| 1118 | - */ |
|
| 1114 | + * Creates and returns the current query set |
|
| 1115 | + * |
|
| 1116 | + * @param object $xmls adoSchema object |
|
| 1117 | + * @return array Query set |
|
| 1118 | + */ |
|
| 1119 | 1119 | function create( &$xmls ) { |
| 1120 | 1120 | foreach( $this->queries as $id => $query ) { |
| 1121 | 1121 | switch( $this->prefixMethod ) { |
@@ -1151,13 +1151,13 @@ discard block |
||
| 1151 | 1151 | } |
| 1152 | 1152 | |
| 1153 | 1153 | /** |
| 1154 | - * Rebuilds the query with the prefix attached to any objects |
|
| 1155 | - * |
|
| 1156 | - * @param string $regex Regex used to add prefix |
|
| 1157 | - * @param string $query SQL query string |
|
| 1158 | - * @param string $prefix Prefix to be appended to tables, indices, etc. |
|
| 1159 | - * @return string Prefixed SQL query string. |
|
| 1160 | - */ |
|
| 1154 | + * Rebuilds the query with the prefix attached to any objects |
|
| 1155 | + * |
|
| 1156 | + * @param string $regex Regex used to add prefix |
|
| 1157 | + * @param string $query SQL query string |
|
| 1158 | + * @param string $prefix Prefix to be appended to tables, indices, etc. |
|
| 1159 | + * @return string Prefixed SQL query string. |
|
| 1160 | + */ |
|
| 1161 | 1161 | function prefixQuery( $regex, $query, $prefix = NULL ) { |
| 1162 | 1162 | if( !isset( $prefix ) ) { |
| 1163 | 1163 | return $query; |
@@ -1202,89 +1202,89 @@ discard block |
||
| 1202 | 1202 | class adoSchema { |
| 1203 | 1203 | |
| 1204 | 1204 | /** |
| 1205 | - * @var array Array containing SQL queries to generate all objects |
|
| 1206 | - * @access private |
|
| 1207 | - */ |
|
| 1205 | + * @var array Array containing SQL queries to generate all objects |
|
| 1206 | + * @access private |
|
| 1207 | + */ |
|
| 1208 | 1208 | var $sqlArray; |
| 1209 | 1209 | |
| 1210 | 1210 | /** |
| 1211 | - * @var object ADOdb connection object |
|
| 1212 | - * @access private |
|
| 1213 | - */ |
|
| 1211 | + * @var object ADOdb connection object |
|
| 1212 | + * @access private |
|
| 1213 | + */ |
|
| 1214 | 1214 | var $db; |
| 1215 | 1215 | |
| 1216 | 1216 | /** |
| 1217 | - * @var object ADOdb Data Dictionary |
|
| 1218 | - * @access private |
|
| 1219 | - */ |
|
| 1217 | + * @var object ADOdb Data Dictionary |
|
| 1218 | + * @access private |
|
| 1219 | + */ |
|
| 1220 | 1220 | var $dict; |
| 1221 | 1221 | |
| 1222 | 1222 | /** |
| 1223 | - * @var string Current XML element |
|
| 1224 | - * @access private |
|
| 1225 | - */ |
|
| 1223 | + * @var string Current XML element |
|
| 1224 | + * @access private |
|
| 1225 | + */ |
|
| 1226 | 1226 | var $currentElement = ''; |
| 1227 | 1227 | |
| 1228 | 1228 | /** |
| 1229 | - * @var string If set (to 'ALTER' or 'REPLACE'), upgrade an existing database |
|
| 1230 | - * @access private |
|
| 1231 | - */ |
|
| 1229 | + * @var string If set (to 'ALTER' or 'REPLACE'), upgrade an existing database |
|
| 1230 | + * @access private |
|
| 1231 | + */ |
|
| 1232 | 1232 | var $upgrade = ''; |
| 1233 | 1233 | |
| 1234 | 1234 | /** |
| 1235 | - * @var string Optional object prefix |
|
| 1236 | - * @access private |
|
| 1237 | - */ |
|
| 1235 | + * @var string Optional object prefix |
|
| 1236 | + * @access private |
|
| 1237 | + */ |
|
| 1238 | 1238 | var $objectPrefix = ''; |
| 1239 | 1239 | |
| 1240 | 1240 | /** |
| 1241 | - * @var long Original Magic Quotes Runtime value |
|
| 1242 | - * @access private |
|
| 1243 | - */ |
|
| 1241 | + * @var long Original Magic Quotes Runtime value |
|
| 1242 | + * @access private |
|
| 1243 | + */ |
|
| 1244 | 1244 | var $mgq; |
| 1245 | 1245 | |
| 1246 | 1246 | /** |
| 1247 | - * @var long System debug |
|
| 1248 | - * @access private |
|
| 1249 | - */ |
|
| 1247 | + * @var long System debug |
|
| 1248 | + * @access private |
|
| 1249 | + */ |
|
| 1250 | 1250 | var $debug; |
| 1251 | 1251 | |
| 1252 | 1252 | /** |
| 1253 | - * @var string Regular expression to find schema version |
|
| 1254 | - * @access private |
|
| 1255 | - */ |
|
| 1253 | + * @var string Regular expression to find schema version |
|
| 1254 | + * @access private |
|
| 1255 | + */ |
|
| 1256 | 1256 | var $versionRegex = '/<schema.*?( version="([^"]*)")?.*?>/'; |
| 1257 | 1257 | |
| 1258 | 1258 | /** |
| 1259 | - * @var string Current schema version |
|
| 1260 | - * @access private |
|
| 1261 | - */ |
|
| 1259 | + * @var string Current schema version |
|
| 1260 | + * @access private |
|
| 1261 | + */ |
|
| 1262 | 1262 | var $schemaVersion; |
| 1263 | 1263 | |
| 1264 | 1264 | /** |
| 1265 | - * @var int Success of last Schema execution |
|
| 1266 | - */ |
|
| 1265 | + * @var int Success of last Schema execution |
|
| 1266 | + */ |
|
| 1267 | 1267 | var $success; |
| 1268 | 1268 | |
| 1269 | 1269 | /** |
| 1270 | - * @var bool Execute SQL inline as it is generated |
|
| 1271 | - */ |
|
| 1270 | + * @var bool Execute SQL inline as it is generated |
|
| 1271 | + */ |
|
| 1272 | 1272 | var $executeInline; |
| 1273 | 1273 | |
| 1274 | 1274 | /** |
| 1275 | - * @var bool Continue SQL execution if errors occur |
|
| 1276 | - */ |
|
| 1275 | + * @var bool Continue SQL execution if errors occur |
|
| 1276 | + */ |
|
| 1277 | 1277 | var $continueOnError; |
| 1278 | 1278 | |
| 1279 | 1279 | /** |
| 1280 | - * Creates an adoSchema object |
|
| 1281 | - * |
|
| 1282 | - * Creating an adoSchema object is the first step in processing an XML schema. |
|
| 1283 | - * The only parameter is an ADOdb database connection object, which must already |
|
| 1284 | - * have been created. |
|
| 1285 | - * |
|
| 1286 | - * @param object $db ADOdb database connection object. |
|
| 1287 | - */ |
|
| 1280 | + * Creates an adoSchema object |
|
| 1281 | + * |
|
| 1282 | + * Creating an adoSchema object is the first step in processing an XML schema. |
|
| 1283 | + * The only parameter is an ADOdb database connection object, which must already |
|
| 1284 | + * have been created. |
|
| 1285 | + * |
|
| 1286 | + * @param object $db ADOdb database connection object. |
|
| 1287 | + */ |
|
| 1288 | 1288 | function adoSchema( &$db ) { |
| 1289 | 1289 | // Initialize the environment |
| 1290 | 1290 | $this->mgq = get_magic_quotes_runtime(); |
@@ -1301,21 +1301,21 @@ discard block |
||
| 1301 | 1301 | } |
| 1302 | 1302 | |
| 1303 | 1303 | /** |
| 1304 | - * Sets the method to be used for upgrading an existing database |
|
| 1305 | - * |
|
| 1306 | - * Use this method to specify how existing database objects should be upgraded. |
|
| 1307 | - * The method option can be set to ALTER, REPLACE, BEST, or NONE. ALTER attempts to |
|
| 1308 | - * alter each database object directly, REPLACE attempts to rebuild each object |
|
| 1309 | - * from scratch, BEST attempts to determine the best upgrade method for each |
|
| 1310 | - * object, and NONE disables upgrading. |
|
| 1311 | - * |
|
| 1312 | - * This method is not yet used by AXMLS, but exists for backward compatibility. |
|
| 1313 | - * The ALTER method is automatically assumed when the adoSchema object is |
|
| 1314 | - * instantiated; other upgrade methods are not currently supported. |
|
| 1315 | - * |
|
| 1316 | - * @param string $method Upgrade method (ALTER|REPLACE|BEST|NONE) |
|
| 1317 | - * @returns string Upgrade method used |
|
| 1318 | - */ |
|
| 1304 | + * Sets the method to be used for upgrading an existing database |
|
| 1305 | + * |
|
| 1306 | + * Use this method to specify how existing database objects should be upgraded. |
|
| 1307 | + * The method option can be set to ALTER, REPLACE, BEST, or NONE. ALTER attempts to |
|
| 1308 | + * alter each database object directly, REPLACE attempts to rebuild each object |
|
| 1309 | + * from scratch, BEST attempts to determine the best upgrade method for each |
|
| 1310 | + * object, and NONE disables upgrading. |
|
| 1311 | + * |
|
| 1312 | + * This method is not yet used by AXMLS, but exists for backward compatibility. |
|
| 1313 | + * The ALTER method is automatically assumed when the adoSchema object is |
|
| 1314 | + * instantiated; other upgrade methods are not currently supported. |
|
| 1315 | + * |
|
| 1316 | + * @param string $method Upgrade method (ALTER|REPLACE|BEST|NONE) |
|
| 1317 | + * @returns string Upgrade method used |
|
| 1318 | + */ |
|
| 1319 | 1319 | function SetUpgradeMethod( $method = '' ) { |
| 1320 | 1320 | if( !is_string( $method ) ) { |
| 1321 | 1321 | return FALSE; |
@@ -1346,18 +1346,18 @@ discard block |
||
| 1346 | 1346 | } |
| 1347 | 1347 | |
| 1348 | 1348 | /** |
| 1349 | - * Enables/disables inline SQL execution. |
|
| 1350 | - * |
|
| 1351 | - * Call this method to enable or disable inline execution of the schema. If the mode is set to TRUE (inline execution), |
|
| 1352 | - * AXMLS applies the SQL to the database immediately as each schema entity is parsed. If the mode |
|
| 1353 | - * is set to FALSE (post execution), AXMLS parses the entire schema and you will need to call adoSchema::ExecuteSchema() |
|
| 1354 | - * to apply the schema to the database. |
|
| 1355 | - * |
|
| 1356 | - * @param bool $mode execute |
|
| 1357 | - * @return bool current execution mode |
|
| 1358 | - * |
|
| 1359 | - * @see ParseSchema(), ExecuteSchema() |
|
| 1360 | - */ |
|
| 1349 | + * Enables/disables inline SQL execution. |
|
| 1350 | + * |
|
| 1351 | + * Call this method to enable or disable inline execution of the schema. If the mode is set to TRUE (inline execution), |
|
| 1352 | + * AXMLS applies the SQL to the database immediately as each schema entity is parsed. If the mode |
|
| 1353 | + * is set to FALSE (post execution), AXMLS parses the entire schema and you will need to call adoSchema::ExecuteSchema() |
|
| 1354 | + * to apply the schema to the database. |
|
| 1355 | + * |
|
| 1356 | + * @param bool $mode execute |
|
| 1357 | + * @return bool current execution mode |
|
| 1358 | + * |
|
| 1359 | + * @see ParseSchema(), ExecuteSchema() |
|
| 1360 | + */ |
|
| 1361 | 1361 | function ExecuteInline( $mode = NULL ) { |
| 1362 | 1362 | if( is_bool( $mode ) ) { |
| 1363 | 1363 | $this->executeInline = $mode; |
@@ -1367,18 +1367,18 @@ discard block |
||
| 1367 | 1367 | } |
| 1368 | 1368 | |
| 1369 | 1369 | /** |
| 1370 | - * Enables/disables SQL continue on error. |
|
| 1371 | - * |
|
| 1372 | - * Call this method to enable or disable continuation of SQL execution if an error occurs. |
|
| 1373 | - * If the mode is set to TRUE (continue), AXMLS will continue to apply SQL to the database, even if an error occurs. |
|
| 1374 | - * If the mode is set to FALSE (halt), AXMLS will halt execution of generated sql if an error occurs, though parsing |
|
| 1375 | - * of the schema will continue. |
|
| 1376 | - * |
|
| 1377 | - * @param bool $mode execute |
|
| 1378 | - * @return bool current continueOnError mode |
|
| 1379 | - * |
|
| 1380 | - * @see addSQL(), ExecuteSchema() |
|
| 1381 | - */ |
|
| 1370 | + * Enables/disables SQL continue on error. |
|
| 1371 | + * |
|
| 1372 | + * Call this method to enable or disable continuation of SQL execution if an error occurs. |
|
| 1373 | + * If the mode is set to TRUE (continue), AXMLS will continue to apply SQL to the database, even if an error occurs. |
|
| 1374 | + * If the mode is set to FALSE (halt), AXMLS will halt execution of generated sql if an error occurs, though parsing |
|
| 1375 | + * of the schema will continue. |
|
| 1376 | + * |
|
| 1377 | + * @param bool $mode execute |
|
| 1378 | + * @return bool current continueOnError mode |
|
| 1379 | + * |
|
| 1380 | + * @see addSQL(), ExecuteSchema() |
|
| 1381 | + */ |
|
| 1382 | 1382 | function ContinueOnError( $mode = NULL ) { |
| 1383 | 1383 | if( is_bool( $mode ) ) { |
| 1384 | 1384 | $this->continueOnError = $mode; |
@@ -1388,33 +1388,33 @@ discard block |
||
| 1388 | 1388 | } |
| 1389 | 1389 | |
| 1390 | 1390 | /** |
| 1391 | - * Loads an XML schema from a file and converts it to SQL. |
|
| 1392 | - * |
|
| 1393 | - * Call this method to load the specified schema (see the DTD for the proper format) from |
|
| 1394 | - * the filesystem and generate the SQL necessary to create the database described. |
|
| 1395 | - * @see ParseSchemaString() |
|
| 1396 | - * |
|
| 1397 | - * @param string $file Name of XML schema file. |
|
| 1398 | - * @param bool $returnSchema Return schema rather than parsing. |
|
| 1399 | - * @return array Array of SQL queries, ready to execute |
|
| 1400 | - */ |
|
| 1391 | + * Loads an XML schema from a file and converts it to SQL. |
|
| 1392 | + * |
|
| 1393 | + * Call this method to load the specified schema (see the DTD for the proper format) from |
|
| 1394 | + * the filesystem and generate the SQL necessary to create the database described. |
|
| 1395 | + * @see ParseSchemaString() |
|
| 1396 | + * |
|
| 1397 | + * @param string $file Name of XML schema file. |
|
| 1398 | + * @param bool $returnSchema Return schema rather than parsing. |
|
| 1399 | + * @return array Array of SQL queries, ready to execute |
|
| 1400 | + */ |
|
| 1401 | 1401 | function ParseSchema( $filename, $returnSchema = FALSE ) { |
| 1402 | 1402 | return $this->ParseSchemaString( $this->ConvertSchemaFile( $filename ), $returnSchema ); |
| 1403 | 1403 | } |
| 1404 | 1404 | |
| 1405 | 1405 | /** |
| 1406 | - * Loads an XML schema from a file and converts it to SQL. |
|
| 1407 | - * |
|
| 1408 | - * Call this method to load the specified schema from a file (see the DTD for the proper format) |
|
| 1409 | - * and generate the SQL necessary to create the database described by the schema. |
|
| 1410 | - * |
|
| 1411 | - * @param string $file Name of XML schema file. |
|
| 1412 | - * @param bool $returnSchema Return schema rather than parsing. |
|
| 1413 | - * @return array Array of SQL queries, ready to execute. |
|
| 1414 | - * |
|
| 1415 | - * @deprecated Replaced by adoSchema::ParseSchema() and adoSchema::ParseSchemaString() |
|
| 1416 | - * @see ParseSchema(), ParseSchemaString() |
|
| 1417 | - */ |
|
| 1406 | + * Loads an XML schema from a file and converts it to SQL. |
|
| 1407 | + * |
|
| 1408 | + * Call this method to load the specified schema from a file (see the DTD for the proper format) |
|
| 1409 | + * and generate the SQL necessary to create the database described by the schema. |
|
| 1410 | + * |
|
| 1411 | + * @param string $file Name of XML schema file. |
|
| 1412 | + * @param bool $returnSchema Return schema rather than parsing. |
|
| 1413 | + * @return array Array of SQL queries, ready to execute. |
|
| 1414 | + * |
|
| 1415 | + * @deprecated Replaced by adoSchema::ParseSchema() and adoSchema::ParseSchemaString() |
|
| 1416 | + * @see ParseSchema(), ParseSchemaString() |
|
| 1417 | + */ |
|
| 1418 | 1418 | function ParseSchemaFile( $filename, $returnSchema = FALSE ) { |
| 1419 | 1419 | // Open the file |
| 1420 | 1420 | if( !($fp = fopen( $filename, 'r' )) ) { |
@@ -1453,16 +1453,16 @@ discard block |
||
| 1453 | 1453 | } |
| 1454 | 1454 | |
| 1455 | 1455 | /** |
| 1456 | - * Converts an XML schema string to SQL. |
|
| 1457 | - * |
|
| 1458 | - * Call this method to parse a string containing an XML schema (see the DTD for the proper format) |
|
| 1459 | - * and generate the SQL necessary to create the database described by the schema. |
|
| 1460 | - * @see ParseSchema() |
|
| 1461 | - * |
|
| 1462 | - * @param string $xmlstring XML schema string. |
|
| 1463 | - * @param bool $returnSchema Return schema rather than parsing. |
|
| 1464 | - * @return array Array of SQL queries, ready to execute. |
|
| 1465 | - */ |
|
| 1456 | + * Converts an XML schema string to SQL. |
|
| 1457 | + * |
|
| 1458 | + * Call this method to parse a string containing an XML schema (see the DTD for the proper format) |
|
| 1459 | + * and generate the SQL necessary to create the database described by the schema. |
|
| 1460 | + * @see ParseSchema() |
|
| 1461 | + * |
|
| 1462 | + * @param string $xmlstring XML schema string. |
|
| 1463 | + * @param bool $returnSchema Return schema rather than parsing. |
|
| 1464 | + * @return array Array of SQL queries, ready to execute. |
|
| 1465 | + */ |
|
| 1466 | 1466 | function ParseSchemaString( $xmlstring, $returnSchema = FALSE ) { |
| 1467 | 1467 | if( !is_string( $xmlstring ) OR empty( $xmlstring ) ) { |
| 1468 | 1468 | return FALSE; |
@@ -1496,31 +1496,31 @@ discard block |
||
| 1496 | 1496 | } |
| 1497 | 1497 | |
| 1498 | 1498 | /** |
| 1499 | - * Loads an XML schema from a file and converts it to uninstallation SQL. |
|
| 1500 | - * |
|
| 1501 | - * Call this method to load the specified schema (see the DTD for the proper format) from |
|
| 1502 | - * the filesystem and generate the SQL necessary to remove the database described. |
|
| 1503 | - * @see RemoveSchemaString() |
|
| 1504 | - * |
|
| 1505 | - * @param string $file Name of XML schema file. |
|
| 1506 | - * @param bool $returnSchema Return schema rather than parsing. |
|
| 1507 | - * @return array Array of SQL queries, ready to execute |
|
| 1508 | - */ |
|
| 1499 | + * Loads an XML schema from a file and converts it to uninstallation SQL. |
|
| 1500 | + * |
|
| 1501 | + * Call this method to load the specified schema (see the DTD for the proper format) from |
|
| 1502 | + * the filesystem and generate the SQL necessary to remove the database described. |
|
| 1503 | + * @see RemoveSchemaString() |
|
| 1504 | + * |
|
| 1505 | + * @param string $file Name of XML schema file. |
|
| 1506 | + * @param bool $returnSchema Return schema rather than parsing. |
|
| 1507 | + * @return array Array of SQL queries, ready to execute |
|
| 1508 | + */ |
|
| 1509 | 1509 | function RemoveSchema( $filename, $returnSchema = FALSE ) { |
| 1510 | 1510 | return $this->RemoveSchemaString( $this->ConvertSchemaFile( $filename ), $returnSchema ); |
| 1511 | 1511 | } |
| 1512 | 1512 | |
| 1513 | 1513 | /** |
| 1514 | - * Converts an XML schema string to uninstallation SQL. |
|
| 1515 | - * |
|
| 1516 | - * Call this method to parse a string containing an XML schema (see the DTD for the proper format) |
|
| 1517 | - * and generate the SQL necessary to uninstall the database described by the schema. |
|
| 1518 | - * @see RemoveSchema() |
|
| 1519 | - * |
|
| 1520 | - * @param string $schema XML schema string. |
|
| 1521 | - * @param bool $returnSchema Return schema rather than parsing. |
|
| 1522 | - * @return array Array of SQL queries, ready to execute. |
|
| 1523 | - */ |
|
| 1514 | + * Converts an XML schema string to uninstallation SQL. |
|
| 1515 | + * |
|
| 1516 | + * Call this method to parse a string containing an XML schema (see the DTD for the proper format) |
|
| 1517 | + * and generate the SQL necessary to uninstall the database described by the schema. |
|
| 1518 | + * @see RemoveSchema() |
|
| 1519 | + * |
|
| 1520 | + * @param string $schema XML schema string. |
|
| 1521 | + * @param bool $returnSchema Return schema rather than parsing. |
|
| 1522 | + * @return array Array of SQL queries, ready to execute. |
|
| 1523 | + */ |
|
| 1524 | 1524 | function RemoveSchemaString( $schema, $returnSchema = FALSE ) { |
| 1525 | 1525 | |
| 1526 | 1526 | // grab current version |
@@ -1532,18 +1532,18 @@ discard block |
||
| 1532 | 1532 | } |
| 1533 | 1533 | |
| 1534 | 1534 | /** |
| 1535 | - * Applies the current XML schema to the database (post execution). |
|
| 1536 | - * |
|
| 1537 | - * Call this method to apply the current schema (generally created by calling |
|
| 1538 | - * ParseSchema() or ParseSchemaString() ) to the database (creating the tables, indexes, |
|
| 1539 | - * and executing other SQL specified in the schema) after parsing. |
|
| 1540 | - * @see ParseSchema(), ParseSchemaString(), ExecuteInline() |
|
| 1541 | - * |
|
| 1542 | - * @param array $sqlArray Array of SQL statements that will be applied rather than |
|
| 1543 | - * the current schema. |
|
| 1544 | - * @param boolean $continueOnErr Continue to apply the schema even if an error occurs. |
|
| 1545 | - * @returns integer 0 if failure, 1 if errors, 2 if successful. |
|
| 1546 | - */ |
|
| 1535 | + * Applies the current XML schema to the database (post execution). |
|
| 1536 | + * |
|
| 1537 | + * Call this method to apply the current schema (generally created by calling |
|
| 1538 | + * ParseSchema() or ParseSchemaString() ) to the database (creating the tables, indexes, |
|
| 1539 | + * and executing other SQL specified in the schema) after parsing. |
|
| 1540 | + * @see ParseSchema(), ParseSchemaString(), ExecuteInline() |
|
| 1541 | + * |
|
| 1542 | + * @param array $sqlArray Array of SQL statements that will be applied rather than |
|
| 1543 | + * the current schema. |
|
| 1544 | + * @param boolean $continueOnErr Continue to apply the schema even if an error occurs. |
|
| 1545 | + * @returns integer 0 if failure, 1 if errors, 2 if successful. |
|
| 1546 | + */ |
|
| 1547 | 1547 | function ExecuteSchema( $sqlArray = NULL, $continueOnErr = NULL ) { |
| 1548 | 1548 | if( !is_bool( $continueOnErr ) ) { |
| 1549 | 1549 | $continueOnErr = $this->ContinueOnError(); |
@@ -1563,27 +1563,27 @@ discard block |
||
| 1563 | 1563 | } |
| 1564 | 1564 | |
| 1565 | 1565 | /** |
| 1566 | - * Returns the current SQL array. |
|
| 1567 | - * |
|
| 1568 | - * Call this method to fetch the array of SQL queries resulting from |
|
| 1569 | - * ParseSchema() or ParseSchemaString(). |
|
| 1570 | - * |
|
| 1571 | - * @param string $format Format: HTML, TEXT, or NONE (PHP array) |
|
| 1572 | - * @return array Array of SQL statements or FALSE if an error occurs |
|
| 1573 | - */ |
|
| 1566 | + * Returns the current SQL array. |
|
| 1567 | + * |
|
| 1568 | + * Call this method to fetch the array of SQL queries resulting from |
|
| 1569 | + * ParseSchema() or ParseSchemaString(). |
|
| 1570 | + * |
|
| 1571 | + * @param string $format Format: HTML, TEXT, or NONE (PHP array) |
|
| 1572 | + * @return array Array of SQL statements or FALSE if an error occurs |
|
| 1573 | + */ |
|
| 1574 | 1574 | function PrintSQL( $format = 'NONE' ) { |
| 1575 | 1575 | return $this->getSQL( $format, $sqlArray ); |
| 1576 | 1576 | } |
| 1577 | 1577 | |
| 1578 | 1578 | /** |
| 1579 | - * Saves the current SQL array to the local filesystem as a list of SQL queries. |
|
| 1580 | - * |
|
| 1581 | - * Call this method to save the array of SQL queries (generally resulting from a |
|
| 1582 | - * parsed XML schema) to the filesystem. |
|
| 1583 | - * |
|
| 1584 | - * @param string $filename Path and name where the file should be saved. |
|
| 1585 | - * @return boolean TRUE if save is successful, else FALSE. |
|
| 1586 | - */ |
|
| 1579 | + * Saves the current SQL array to the local filesystem as a list of SQL queries. |
|
| 1580 | + * |
|
| 1581 | + * Call this method to save the array of SQL queries (generally resulting from a |
|
| 1582 | + * parsed XML schema) to the filesystem. |
|
| 1583 | + * |
|
| 1584 | + * @param string $filename Path and name where the file should be saved. |
|
| 1585 | + * @return boolean TRUE if save is successful, else FALSE. |
|
| 1586 | + */ |
|
| 1587 | 1587 | function SaveSQL( $filename = './schema.sql' ) { |
| 1588 | 1588 | |
| 1589 | 1589 | if( !isset( $sqlArray ) ) { |
@@ -1602,12 +1602,12 @@ discard block |
||
| 1602 | 1602 | } |
| 1603 | 1603 | |
| 1604 | 1604 | /** |
| 1605 | - * Create an xml parser |
|
| 1606 | - * |
|
| 1607 | - * @return object PHP XML parser object |
|
| 1608 | - * |
|
| 1609 | - * @access private |
|
| 1610 | - */ |
|
| 1605 | + * Create an xml parser |
|
| 1606 | + * |
|
| 1607 | + * @return object PHP XML parser object |
|
| 1608 | + * |
|
| 1609 | + * @access private |
|
| 1610 | + */ |
|
| 1611 | 1611 | function &create_parser() { |
| 1612 | 1612 | // Create the parser |
| 1613 | 1613 | $xmlParser = xml_parser_create(); |
@@ -1621,10 +1621,10 @@ discard block |
||
| 1621 | 1621 | } |
| 1622 | 1622 | |
| 1623 | 1623 | /** |
| 1624 | - * XML Callback to process start elements |
|
| 1625 | - * |
|
| 1626 | - * @access private |
|
| 1627 | - */ |
|
| 1624 | + * XML Callback to process start elements |
|
| 1625 | + * |
|
| 1626 | + * @access private |
|
| 1627 | + */ |
|
| 1628 | 1628 | function _tag_open( &$parser, $tag, $attributes ) { |
| 1629 | 1629 | switch( strtoupper( $tag ) ) { |
| 1630 | 1630 | case 'TABLE': |
@@ -1644,39 +1644,39 @@ discard block |
||
| 1644 | 1644 | } |
| 1645 | 1645 | |
| 1646 | 1646 | /** |
| 1647 | - * XML Callback to process CDATA elements |
|
| 1648 | - * |
|
| 1649 | - * @access private |
|
| 1650 | - */ |
|
| 1647 | + * XML Callback to process CDATA elements |
|
| 1648 | + * |
|
| 1649 | + * @access private |
|
| 1650 | + */ |
|
| 1651 | 1651 | function _tag_cdata( &$parser, $cdata ) { |
| 1652 | 1652 | } |
| 1653 | 1653 | |
| 1654 | 1654 | /** |
| 1655 | - * XML Callback to process end elements |
|
| 1656 | - * |
|
| 1657 | - * @access private |
|
| 1658 | - * @internal |
|
| 1659 | - */ |
|
| 1655 | + * XML Callback to process end elements |
|
| 1656 | + * |
|
| 1657 | + * @access private |
|
| 1658 | + * @internal |
|
| 1659 | + */ |
|
| 1660 | 1660 | function _tag_close( &$parser, $tag ) { |
| 1661 | 1661 | |
| 1662 | 1662 | } |
| 1663 | 1663 | |
| 1664 | 1664 | /** |
| 1665 | - * Converts an XML schema string to the specified DTD version. |
|
| 1666 | - * |
|
| 1667 | - * Call this method to convert a string containing an XML schema to a different AXMLS |
|
| 1668 | - * DTD version. For instance, to convert a schema created for an pre-1.0 version for |
|
| 1669 | - * AXMLS (DTD version 0.1) to a newer version of the DTD (e.g. 0.2). If no DTD version |
|
| 1670 | - * parameter is specified, the schema will be converted to the current DTD version. |
|
| 1671 | - * If the newFile parameter is provided, the converted schema will be written to the specified |
|
| 1672 | - * file. |
|
| 1673 | - * @see ConvertSchemaFile() |
|
| 1674 | - * |
|
| 1675 | - * @param string $schema String containing XML schema that will be converted. |
|
| 1676 | - * @param string $newVersion DTD version to convert to. |
|
| 1677 | - * @param string $newFile File name of (converted) output file. |
|
| 1678 | - * @return string Converted XML schema or FALSE if an error occurs. |
|
| 1679 | - */ |
|
| 1665 | + * Converts an XML schema string to the specified DTD version. |
|
| 1666 | + * |
|
| 1667 | + * Call this method to convert a string containing an XML schema to a different AXMLS |
|
| 1668 | + * DTD version. For instance, to convert a schema created for an pre-1.0 version for |
|
| 1669 | + * AXMLS (DTD version 0.1) to a newer version of the DTD (e.g. 0.2). If no DTD version |
|
| 1670 | + * parameter is specified, the schema will be converted to the current DTD version. |
|
| 1671 | + * If the newFile parameter is provided, the converted schema will be written to the specified |
|
| 1672 | + * file. |
|
| 1673 | + * @see ConvertSchemaFile() |
|
| 1674 | + * |
|
| 1675 | + * @param string $schema String containing XML schema that will be converted. |
|
| 1676 | + * @param string $newVersion DTD version to convert to. |
|
| 1677 | + * @param string $newFile File name of (converted) output file. |
|
| 1678 | + * @return string Converted XML schema or FALSE if an error occurs. |
|
| 1679 | + */ |
|
| 1680 | 1680 | function ConvertSchemaString( $schema, $newVersion = NULL, $newFile = NULL ) { |
| 1681 | 1681 | |
| 1682 | 1682 | // grab current version |
@@ -1703,21 +1703,21 @@ discard block |
||
| 1703 | 1703 | } |
| 1704 | 1704 | |
| 1705 | 1705 | /** |
| 1706 | - * Converts an XML schema file to the specified DTD version. |
|
| 1707 | - * |
|
| 1708 | - * Call this method to convert the specified XML schema file to a different AXMLS |
|
| 1709 | - * DTD version. For instance, to convert a schema created for an pre-1.0 version for |
|
| 1710 | - * AXMLS (DTD version 0.1) to a newer version of the DTD (e.g. 0.2). If no DTD version |
|
| 1711 | - * parameter is specified, the schema will be converted to the current DTD version. |
|
| 1712 | - * If the newFile parameter is provided, the converted schema will be written to the specified |
|
| 1713 | - * file. |
|
| 1714 | - * @see ConvertSchemaString() |
|
| 1715 | - * |
|
| 1716 | - * @param string $filename Name of XML schema file that will be converted. |
|
| 1717 | - * @param string $newVersion DTD version to convert to. |
|
| 1718 | - * @param string $newFile File name of (converted) output file. |
|
| 1719 | - * @return string Converted XML schema or FALSE if an error occurs. |
|
| 1720 | - */ |
|
| 1706 | + * Converts an XML schema file to the specified DTD version. |
|
| 1707 | + * |
|
| 1708 | + * Call this method to convert the specified XML schema file to a different AXMLS |
|
| 1709 | + * DTD version. For instance, to convert a schema created for an pre-1.0 version for |
|
| 1710 | + * AXMLS (DTD version 0.1) to a newer version of the DTD (e.g. 0.2). If no DTD version |
|
| 1711 | + * parameter is specified, the schema will be converted to the current DTD version. |
|
| 1712 | + * If the newFile parameter is provided, the converted schema will be written to the specified |
|
| 1713 | + * file. |
|
| 1714 | + * @see ConvertSchemaString() |
|
| 1715 | + * |
|
| 1716 | + * @param string $filename Name of XML schema file that will be converted. |
|
| 1717 | + * @param string $newVersion DTD version to convert to. |
|
| 1718 | + * @param string $newFile File name of (converted) output file. |
|
| 1719 | + * @return string Converted XML schema or FALSE if an error occurs. |
|
| 1720 | + */ |
|
| 1721 | 1721 | function ConvertSchemaFile( $filename, $newVersion = NULL, $newFile = NULL ) { |
| 1722 | 1722 | |
| 1723 | 1723 | // grab current version |
@@ -1798,15 +1798,15 @@ discard block |
||
| 1798 | 1798 | } |
| 1799 | 1799 | |
| 1800 | 1800 | /** |
| 1801 | - * Processes XSLT transformation errors |
|
| 1802 | - * |
|
| 1803 | - * @param object $parser XML parser object |
|
| 1804 | - * @param integer $errno Error number |
|
| 1805 | - * @param integer $level Error level |
|
| 1806 | - * @param array $fields Error information fields |
|
| 1807 | - * |
|
| 1808 | - * @access private |
|
| 1809 | - */ |
|
| 1801 | + * Processes XSLT transformation errors |
|
| 1802 | + * |
|
| 1803 | + * @param object $parser XML parser object |
|
| 1804 | + * @param integer $errno Error number |
|
| 1805 | + * @param integer $level Error level |
|
| 1806 | + * @param array $fields Error information fields |
|
| 1807 | + * |
|
| 1808 | + * @access private |
|
| 1809 | + */ |
|
| 1810 | 1810 | function xslt_error_handler( $parser, $errno, $level, $fields ) { |
| 1811 | 1811 | if( is_array( $fields ) ) { |
| 1812 | 1812 | $msg = array( |
@@ -1851,14 +1851,14 @@ discard block |
||
| 1851 | 1851 | } |
| 1852 | 1852 | |
| 1853 | 1853 | /** |
| 1854 | - * Returns the AXMLS Schema Version of the requested XML schema file. |
|
| 1855 | - * |
|
| 1856 | - * Call this method to obtain the AXMLS DTD version of the requested XML schema file. |
|
| 1857 | - * @see SchemaStringVersion() |
|
| 1858 | - * |
|
| 1859 | - * @param string $filename AXMLS schema file |
|
| 1860 | - * @return string Schema version number or FALSE on error |
|
| 1861 | - */ |
|
| 1854 | + * Returns the AXMLS Schema Version of the requested XML schema file. |
|
| 1855 | + * |
|
| 1856 | + * Call this method to obtain the AXMLS DTD version of the requested XML schema file. |
|
| 1857 | + * @see SchemaStringVersion() |
|
| 1858 | + * |
|
| 1859 | + * @param string $filename AXMLS schema file |
|
| 1860 | + * @return string Schema version number or FALSE on error |
|
| 1861 | + */ |
|
| 1862 | 1862 | function SchemaFileVersion( $filename ) { |
| 1863 | 1863 | // Open the file |
| 1864 | 1864 | if( !($fp = fopen( $filename, 'r' )) ) { |
@@ -1877,14 +1877,14 @@ discard block |
||
| 1877 | 1877 | } |
| 1878 | 1878 | |
| 1879 | 1879 | /** |
| 1880 | - * Returns the AXMLS Schema Version of the provided XML schema string. |
|
| 1881 | - * |
|
| 1882 | - * Call this method to obtain the AXMLS DTD version of the provided XML schema string. |
|
| 1883 | - * @see SchemaFileVersion() |
|
| 1884 | - * |
|
| 1885 | - * @param string $xmlstring XML schema string |
|
| 1886 | - * @return string Schema version number or FALSE on error |
|
| 1887 | - */ |
|
| 1880 | + * Returns the AXMLS Schema Version of the provided XML schema string. |
|
| 1881 | + * |
|
| 1882 | + * Call this method to obtain the AXMLS DTD version of the provided XML schema string. |
|
| 1883 | + * @see SchemaFileVersion() |
|
| 1884 | + * |
|
| 1885 | + * @param string $xmlstring XML schema string |
|
| 1886 | + * @return string Schema version number or FALSE on error |
|
| 1887 | + */ |
|
| 1888 | 1888 | function SchemaStringVersion( $xmlstring ) { |
| 1889 | 1889 | if( !is_string( $xmlstring ) OR empty( $xmlstring ) ) { |
| 1890 | 1890 | return FALSE; |
@@ -1898,15 +1898,15 @@ discard block |
||
| 1898 | 1898 | } |
| 1899 | 1899 | |
| 1900 | 1900 | /** |
| 1901 | - * Extracts an XML schema from an existing database. |
|
| 1902 | - * |
|
| 1903 | - * Call this method to create an XML schema string from an existing database. |
|
| 1904 | - * If the data parameter is set to TRUE, AXMLS will include the data from the database |
|
| 1905 | - * in the schema. |
|
| 1906 | - * |
|
| 1907 | - * @param boolean $data Include data in schema dump |
|
| 1908 | - * @return string Generated XML schema |
|
| 1909 | - */ |
|
| 1901 | + * Extracts an XML schema from an existing database. |
|
| 1902 | + * |
|
| 1903 | + * Call this method to create an XML schema string from an existing database. |
|
| 1904 | + * If the data parameter is set to TRUE, AXMLS will include the data from the database |
|
| 1905 | + * in the schema. |
|
| 1906 | + * |
|
| 1907 | + * @param boolean $data Include data in schema dump |
|
| 1908 | + * @return string Generated XML schema |
|
| 1909 | + */ |
|
| 1910 | 1910 | function ExtractSchema( $data = FALSE ) { |
| 1911 | 1911 | $old_mode = $this->db->SetFetchMode( ADODB_FETCH_NUM ); |
| 1912 | 1912 | |
@@ -2005,15 +2005,15 @@ discard block |
||
| 2005 | 2005 | } |
| 2006 | 2006 | |
| 2007 | 2007 | /** |
| 2008 | - * Sets a prefix for database objects |
|
| 2009 | - * |
|
| 2010 | - * Call this method to set a standard prefix that will be prepended to all database tables |
|
| 2011 | - * and indices when the schema is parsed. Calling setPrefix with no arguments clears the prefix. |
|
| 2012 | - * |
|
| 2013 | - * @param string $prefix Prefix that will be prepended. |
|
| 2014 | - * @param boolean $underscore If TRUE, automatically append an underscore character to the prefix. |
|
| 2015 | - * @return boolean TRUE if successful, else FALSE |
|
| 2016 | - */ |
|
| 2008 | + * Sets a prefix for database objects |
|
| 2009 | + * |
|
| 2010 | + * Call this method to set a standard prefix that will be prepended to all database tables |
|
| 2011 | + * and indices when the schema is parsed. Calling setPrefix with no arguments clears the prefix. |
|
| 2012 | + * |
|
| 2013 | + * @param string $prefix Prefix that will be prepended. |
|
| 2014 | + * @param boolean $underscore If TRUE, automatically append an underscore character to the prefix. |
|
| 2015 | + * @return boolean TRUE if successful, else FALSE |
|
| 2016 | + */ |
|
| 2017 | 2017 | function SetPrefix( $prefix = '', $underscore = TRUE ) { |
| 2018 | 2018 | switch( TRUE ) { |
| 2019 | 2019 | // clear prefix |
@@ -2040,13 +2040,13 @@ discard block |
||
| 2040 | 2040 | } |
| 2041 | 2041 | |
| 2042 | 2042 | /** |
| 2043 | - * Returns an object name with the current prefix prepended. |
|
| 2044 | - * |
|
| 2045 | - * @param string $name Name |
|
| 2046 | - * @return string Prefixed name |
|
| 2047 | - * |
|
| 2048 | - * @access private |
|
| 2049 | - */ |
|
| 2043 | + * Returns an object name with the current prefix prepended. |
|
| 2044 | + * |
|
| 2045 | + * @param string $name Name |
|
| 2046 | + * @return string Prefixed name |
|
| 2047 | + * |
|
| 2048 | + * @access private |
|
| 2049 | + */ |
|
| 2050 | 2050 | function prefix( $name = '' ) { |
| 2051 | 2051 | // if prefix is set |
| 2052 | 2052 | if( !empty( $this->objectPrefix ) ) { |
@@ -2060,13 +2060,13 @@ discard block |
||
| 2060 | 2060 | } |
| 2061 | 2061 | |
| 2062 | 2062 | /** |
| 2063 | - * Checks if element references a specific platform |
|
| 2064 | - * |
|
| 2065 | - * @param string $platform Requested platform |
|
| 2066 | - * @returns boolean TRUE if platform check succeeds |
|
| 2067 | - * |
|
| 2068 | - * @access private |
|
| 2069 | - */ |
|
| 2063 | + * Checks if element references a specific platform |
|
| 2064 | + * |
|
| 2065 | + * @param string $platform Requested platform |
|
| 2066 | + * @returns boolean TRUE if platform check succeeds |
|
| 2067 | + * |
|
| 2068 | + * @access private |
|
| 2069 | + */ |
|
| 2070 | 2070 | function supportedPlatform( $platform = NULL ) { |
| 2071 | 2071 | $regex = '/^(\w*\|)*' . $this->db->databaseType . '(\|\w*)*$/'; |
| 2072 | 2072 | |
@@ -2080,22 +2080,22 @@ discard block |
||
| 2080 | 2080 | } |
| 2081 | 2081 | |
| 2082 | 2082 | /** |
| 2083 | - * Clears the array of generated SQL. |
|
| 2084 | - * |
|
| 2085 | - * @access private |
|
| 2086 | - */ |
|
| 2083 | + * Clears the array of generated SQL. |
|
| 2084 | + * |
|
| 2085 | + * @access private |
|
| 2086 | + */ |
|
| 2087 | 2087 | function clearSQL() { |
| 2088 | 2088 | $this->sqlArray = array(); |
| 2089 | 2089 | } |
| 2090 | 2090 | |
| 2091 | 2091 | /** |
| 2092 | - * Adds SQL into the SQL array. |
|
| 2093 | - * |
|
| 2094 | - * @param mixed $sql SQL to Add |
|
| 2095 | - * @return boolean TRUE if successful, else FALSE. |
|
| 2096 | - * |
|
| 2097 | - * @access private |
|
| 2098 | - */ |
|
| 2092 | + * Adds SQL into the SQL array. |
|
| 2093 | + * |
|
| 2094 | + * @param mixed $sql SQL to Add |
|
| 2095 | + * @return boolean TRUE if successful, else FALSE. |
|
| 2096 | + * |
|
| 2097 | + * @access private |
|
| 2098 | + */ |
|
| 2099 | 2099 | function addSQL( $sql = NULL ) { |
| 2100 | 2100 | if( is_array( $sql ) ) { |
| 2101 | 2101 | foreach( $sql as $line ) { |
@@ -2131,13 +2131,13 @@ discard block |
||
| 2131 | 2131 | } |
| 2132 | 2132 | |
| 2133 | 2133 | /** |
| 2134 | - * Gets the SQL array in the specified format. |
|
| 2135 | - * |
|
| 2136 | - * @param string $format Format |
|
| 2137 | - * @return mixed SQL |
|
| 2138 | - * |
|
| 2139 | - * @access private |
|
| 2140 | - */ |
|
| 2134 | + * Gets the SQL array in the specified format. |
|
| 2135 | + * |
|
| 2136 | + * @param string $format Format |
|
| 2137 | + * @return mixed SQL |
|
| 2138 | + * |
|
| 2139 | + * @access private |
|
| 2140 | + */ |
|
| 2141 | 2141 | function getSQL( $format = NULL, $sqlArray = NULL ) { |
| 2142 | 2142 | if( !is_array( $sqlArray ) ) { |
| 2143 | 2143 | $sqlArray = $this->sqlArray; |
@@ -2159,11 +2159,11 @@ discard block |
||
| 2159 | 2159 | } |
| 2160 | 2160 | |
| 2161 | 2161 | /** |
| 2162 | - * Destroys an adoSchema object. |
|
| 2163 | - * |
|
| 2164 | - * Call this method to clean up after an adoSchema object that is no longer in use. |
|
| 2165 | - * @deprecated adoSchema now cleans up automatically. |
|
| 2166 | - */ |
|
| 2162 | + * Destroys an adoSchema object. |
|
| 2163 | + * |
|
| 2164 | + * Call this method to clean up after an adoSchema object that is no longer in use. |
|
| 2165 | + * @deprecated adoSchema now cleans up automatically. |
|
| 2166 | + */ |
|
| 2167 | 2167 | function Destroy() { |
| 2168 | 2168 | set_magic_quotes_runtime( $this->mgq ); |
| 2169 | 2169 | unset( $this ); |
@@ -21,65 +21,65 @@ discard block |
||
| 21 | 21 | /** |
| 22 | 22 | * Debug on or off |
| 23 | 23 | */ |
| 24 | -if( !defined( 'XMLS_DEBUG' ) ) { |
|
| 25 | - define( 'XMLS_DEBUG', FALSE ); |
|
| 24 | +if (!defined('XMLS_DEBUG')) { |
|
| 25 | + define('XMLS_DEBUG', FALSE); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | 29 | * Default prefix key |
| 30 | 30 | */ |
| 31 | -if( !defined( 'XMLS_PREFIX' ) ) { |
|
| 32 | - define( 'XMLS_PREFIX', '%%P' ); |
|
| 31 | +if (!defined('XMLS_PREFIX')) { |
|
| 32 | + define('XMLS_PREFIX', '%%P'); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | /** |
| 36 | 36 | * Maximum length allowed for object prefix |
| 37 | 37 | */ |
| 38 | -if( !defined( 'XMLS_PREFIX_MAXLEN' ) ) { |
|
| 39 | - define( 'XMLS_PREFIX_MAXLEN', 10 ); |
|
| 38 | +if (!defined('XMLS_PREFIX_MAXLEN')) { |
|
| 39 | + define('XMLS_PREFIX_MAXLEN', 10); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | 43 | * Execute SQL inline as it is generated |
| 44 | 44 | */ |
| 45 | -if( !defined( 'XMLS_EXECUTE_INLINE' ) ) { |
|
| 46 | - define( 'XMLS_EXECUTE_INLINE', FALSE ); |
|
| 45 | +if (!defined('XMLS_EXECUTE_INLINE')) { |
|
| 46 | + define('XMLS_EXECUTE_INLINE', FALSE); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /** |
| 50 | 50 | * Continue SQL Execution if an error occurs? |
| 51 | 51 | */ |
| 52 | -if( !defined( 'XMLS_CONTINUE_ON_ERROR' ) ) { |
|
| 53 | - define( 'XMLS_CONTINUE_ON_ERROR', FALSE ); |
|
| 52 | +if (!defined('XMLS_CONTINUE_ON_ERROR')) { |
|
| 53 | + define('XMLS_CONTINUE_ON_ERROR', FALSE); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | /** |
| 57 | 57 | * Current Schema Version |
| 58 | 58 | */ |
| 59 | -if( !defined( 'XMLS_SCHEMA_VERSION' ) ) { |
|
| 60 | - define( 'XMLS_SCHEMA_VERSION', '0.2' ); |
|
| 59 | +if (!defined('XMLS_SCHEMA_VERSION')) { |
|
| 60 | + define('XMLS_SCHEMA_VERSION', '0.2'); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | /** |
| 64 | 64 | * Default Schema Version. Used for Schemas without an explicit version set. |
| 65 | 65 | */ |
| 66 | -if( !defined( 'XMLS_DEFAULT_SCHEMA_VERSION' ) ) { |
|
| 67 | - define( 'XMLS_DEFAULT_SCHEMA_VERSION', '0.1' ); |
|
| 66 | +if (!defined('XMLS_DEFAULT_SCHEMA_VERSION')) { |
|
| 67 | + define('XMLS_DEFAULT_SCHEMA_VERSION', '0.1'); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
| 71 | 71 | * Default Schema Version. Used for Schemas without an explicit version set. |
| 72 | 72 | */ |
| 73 | -if( !defined( 'XMLS_DEFAULT_UPGRADE_METHOD' ) ) { |
|
| 74 | - define( 'XMLS_DEFAULT_UPGRADE_METHOD', 'ALTER' ); |
|
| 73 | +if (!defined('XMLS_DEFAULT_UPGRADE_METHOD')) { |
|
| 74 | + define('XMLS_DEFAULT_UPGRADE_METHOD', 'ALTER'); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | /** |
| 78 | 78 | * Include the main ADODB library |
| 79 | 79 | */ |
| 80 | -if( !defined( '_ADODB_LAYER' ) ) { |
|
| 81 | - require( 'adodb.inc.php' ); |
|
| 82 | - require( 'adodb-datadict.inc.php' ); |
|
| 80 | +if (!defined('_ADODB_LAYER')) { |
|
| 81 | + require('adodb.inc.php'); |
|
| 82 | + require('adodb-datadict.inc.php'); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | /** |
@@ -104,8 +104,8 @@ discard block |
||
| 104 | 104 | /** |
| 105 | 105 | * NOP |
| 106 | 106 | */ |
| 107 | - function dbObject( &$parent, $attributes = NULL ) { |
|
| 108 | - $this->parent =& $parent; |
|
| 107 | + function dbObject(&$parent, $attributes = NULL) { |
|
| 108 | + $this->parent = & $parent; |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | /** |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | * |
| 114 | 114 | * @access private |
| 115 | 115 | */ |
| 116 | - function _tag_open( &$parser, $tag, $attributes ) { |
|
| 116 | + function _tag_open(&$parser, $tag, $attributes) { |
|
| 117 | 117 | |
| 118 | 118 | } |
| 119 | 119 | |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | * |
| 123 | 123 | * @access private |
| 124 | 124 | */ |
| 125 | - function _tag_cdata( &$parser, $cdata ) { |
|
| 125 | + function _tag_cdata(&$parser, $cdata) { |
|
| 126 | 126 | |
| 127 | 127 | } |
| 128 | 128 | |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | * |
| 132 | 132 | * @access private |
| 133 | 133 | */ |
| 134 | - function _tag_close( &$parser, $tag ) { |
|
| 134 | + function _tag_close(&$parser, $tag) { |
|
| 135 | 135 | |
| 136 | 136 | } |
| 137 | 137 | |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | * Destroys the object |
| 144 | 144 | */ |
| 145 | 145 | function destroy() { |
| 146 | - unset( $this ); |
|
| 146 | + unset($this); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
@@ -153,8 +153,8 @@ discard block |
||
| 153 | 153 | * @param string $platform RDBMS platform name (from ADODB platform list). |
| 154 | 154 | * @return boolean TRUE if RDBMS is supported; otherwise returns FALSE. |
| 155 | 155 | */ |
| 156 | - function supportedPlatform( $platform = NULL ) { |
|
| 157 | - return is_object( $this->parent ) ? $this->parent->supportedPlatform( $platform ) : TRUE; |
|
| 156 | + function supportedPlatform($platform = NULL) { |
|
| 157 | + return is_object($this->parent) ? $this->parent->supportedPlatform($platform) : TRUE; |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | /** |
@@ -163,8 +163,8 @@ discard block |
||
| 163 | 163 | * @param string $name Prefix string. |
| 164 | 164 | * @return string Prefix. |
| 165 | 165 | */ |
| 166 | - function prefix( $name = '' ) { |
|
| 167 | - return is_object( $this->parent ) ? $this->parent->prefix( $name ) : $name; |
|
| 166 | + function prefix($name = '') { |
|
| 167 | + return is_object($this->parent) ? $this->parent->prefix($name) : $name; |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | /** |
@@ -173,8 +173,8 @@ discard block |
||
| 173 | 173 | * @param string $field Field. |
| 174 | 174 | * @return string Field ID. |
| 175 | 175 | */ |
| 176 | - function FieldID( $field ) { |
|
| 177 | - return strtoupper( preg_replace( '/^`(.+)`$/', '$1', $field ) ); |
|
| 176 | + function FieldID($field) { |
|
| 177 | + return strtoupper(preg_replace('/^`(.+)`$/', '$1', $field)); |
|
| 178 | 178 | } |
| 179 | 179 | } |
| 180 | 180 | |
@@ -234,8 +234,8 @@ discard block |
||
| 234 | 234 | * @param string $prefix DB Object prefix |
| 235 | 235 | * @param array $attributes Array of table attributes. |
| 236 | 236 | */ |
| 237 | - function dbTable( &$parent, $attributes = NULL ) { |
|
| 238 | - $this->parent =& $parent; |
|
| 237 | + function dbTable(&$parent, $attributes = NULL) { |
|
| 238 | + $this->parent = & $parent; |
|
| 239 | 239 | $this->name = $this->prefix($attributes['NAME']); |
| 240 | 240 | } |
| 241 | 241 | |
@@ -245,18 +245,18 @@ discard block |
||
| 245 | 245 | * |
| 246 | 246 | * @access private |
| 247 | 247 | */ |
| 248 | - function _tag_open( &$parser, $tag, $attributes ) { |
|
| 249 | - $this->currentElement = strtoupper( $tag ); |
|
| 248 | + function _tag_open(&$parser, $tag, $attributes) { |
|
| 249 | + $this->currentElement = strtoupper($tag); |
|
| 250 | 250 | |
| 251 | - switch( $this->currentElement ) { |
|
| 251 | + switch ($this->currentElement) { |
|
| 252 | 252 | case 'INDEX': |
| 253 | - if( !isset( $attributes['PLATFORM'] ) OR $this->supportedPlatform( $attributes['PLATFORM'] ) ) { |
|
| 254 | - xml_set_object( $parser, $this->addIndex( $attributes ) ); |
|
| 253 | + if (!isset($attributes['PLATFORM']) OR $this->supportedPlatform($attributes['PLATFORM'])) { |
|
| 254 | + xml_set_object($parser, $this->addIndex($attributes)); |
|
| 255 | 255 | } |
| 256 | 256 | break; |
| 257 | 257 | case 'DATA': |
| 258 | - if( !isset( $attributes['PLATFORM'] ) OR $this->supportedPlatform( $attributes['PLATFORM'] ) ) { |
|
| 259 | - xml_set_object( $parser, $this->addData( $attributes ) ); |
|
| 258 | + if (!isset($attributes['PLATFORM']) OR $this->supportedPlatform($attributes['PLATFORM'])) { |
|
| 259 | + xml_set_object($parser, $this->addData($attributes)); |
|
| 260 | 260 | } |
| 261 | 261 | break; |
| 262 | 262 | case 'DROP': |
@@ -266,31 +266,31 @@ discard block |
||
| 266 | 266 | // Add a field |
| 267 | 267 | $fieldName = $attributes['NAME']; |
| 268 | 268 | $fieldType = $attributes['TYPE']; |
| 269 | - $fieldSize = isset( $attributes['SIZE'] ) ? $attributes['SIZE'] : NULL; |
|
| 270 | - $fieldOpts = isset( $attributes['OPTS'] ) ? $attributes['OPTS'] : NULL; |
|
| 269 | + $fieldSize = isset($attributes['SIZE']) ? $attributes['SIZE'] : NULL; |
|
| 270 | + $fieldOpts = isset($attributes['OPTS']) ? $attributes['OPTS'] : NULL; |
|
| 271 | 271 | |
| 272 | - $this->addField( $fieldName, $fieldType, $fieldSize, $fieldOpts ); |
|
| 272 | + $this->addField($fieldName, $fieldType, $fieldSize, $fieldOpts); |
|
| 273 | 273 | break; |
| 274 | 274 | case 'KEY': |
| 275 | 275 | case 'NOTNULL': |
| 276 | 276 | case 'AUTOINCREMENT': |
| 277 | 277 | // Add a field option |
| 278 | - $this->addFieldOpt( $this->current_field, $this->currentElement ); |
|
| 278 | + $this->addFieldOpt($this->current_field, $this->currentElement); |
|
| 279 | 279 | break; |
| 280 | 280 | case 'DEFAULT': |
| 281 | 281 | // Add a field option to the table object |
| 282 | 282 | |
| 283 | 283 | // Work around ADOdb datadict issue that misinterprets empty strings. |
| 284 | - if( $attributes['VALUE'] == '' ) { |
|
| 284 | + if ($attributes['VALUE'] == '') { |
|
| 285 | 285 | $attributes['VALUE'] = " '' "; |
| 286 | 286 | } |
| 287 | 287 | |
| 288 | - $this->addFieldOpt( $this->current_field, $this->currentElement, $attributes['VALUE'] ); |
|
| 288 | + $this->addFieldOpt($this->current_field, $this->currentElement, $attributes['VALUE']); |
|
| 289 | 289 | break; |
| 290 | 290 | case 'DEFDATE': |
| 291 | 291 | case 'DEFTIMESTAMP': |
| 292 | 292 | // Add a field option to the table object |
| 293 | - $this->addFieldOpt( $this->current_field, $this->currentElement ); |
|
| 293 | + $this->addFieldOpt($this->current_field, $this->currentElement); |
|
| 294 | 294 | break; |
| 295 | 295 | default: |
| 296 | 296 | // print_r( array( $tag, $attributes ) ); |
@@ -302,19 +302,19 @@ discard block |
||
| 302 | 302 | * |
| 303 | 303 | * @access private |
| 304 | 304 | */ |
| 305 | - function _tag_cdata( &$parser, $cdata ) { |
|
| 306 | - switch( $this->currentElement ) { |
|
| 305 | + function _tag_cdata(&$parser, $cdata) { |
|
| 306 | + switch ($this->currentElement) { |
|
| 307 | 307 | // Table constraint |
| 308 | 308 | case 'CONSTRAINT': |
| 309 | - if( isset( $this->current_field ) ) { |
|
| 310 | - $this->addFieldOpt( $this->current_field, $this->currentElement, $cdata ); |
|
| 309 | + if (isset($this->current_field)) { |
|
| 310 | + $this->addFieldOpt($this->current_field, $this->currentElement, $cdata); |
|
| 311 | 311 | } else { |
| 312 | - $this->addTableOpt( $cdata ); |
|
| 312 | + $this->addTableOpt($cdata); |
|
| 313 | 313 | } |
| 314 | 314 | break; |
| 315 | 315 | // Table option |
| 316 | 316 | case 'OPT': |
| 317 | - $this->addTableOpt( $cdata ); |
|
| 317 | + $this->addTableOpt($cdata); |
|
| 318 | 318 | break; |
| 319 | 319 | default: |
| 320 | 320 | |
@@ -326,13 +326,13 @@ discard block |
||
| 326 | 326 | * |
| 327 | 327 | * @access private |
| 328 | 328 | */ |
| 329 | - function _tag_close( &$parser, $tag ) { |
|
| 329 | + function _tag_close(&$parser, $tag) { |
|
| 330 | 330 | $this->currentElement = ''; |
| 331 | 331 | |
| 332 | - switch( strtoupper( $tag ) ) { |
|
| 332 | + switch (strtoupper($tag)) { |
|
| 333 | 333 | case 'TABLE': |
| 334 | - $this->parent->addSQL( $this->create( $this->parent ) ); |
|
| 335 | - xml_set_object( $parser, $this->parent ); |
|
| 334 | + $this->parent->addSQL($this->create($this->parent)); |
|
| 335 | + xml_set_object($parser, $this->parent); |
|
| 336 | 336 | $this->destroy(); |
| 337 | 337 | break; |
| 338 | 338 | case 'FIELD': |
@@ -348,9 +348,9 @@ discard block |
||
| 348 | 348 | * @param array $attributes Index attributes |
| 349 | 349 | * @return object dbIndex object |
| 350 | 350 | */ |
| 351 | - function &addIndex( $attributes ) { |
|
| 352 | - $name = strtoupper( $attributes['NAME'] ); |
|
| 353 | - $this->indexes[$name] = new dbIndex( $this, $attributes ); |
|
| 351 | + function &addIndex($attributes) { |
|
| 352 | + $name = strtoupper($attributes['NAME']); |
|
| 353 | + $this->indexes[$name] = new dbIndex($this, $attributes); |
|
| 354 | 354 | return $this->indexes[$name]; |
| 355 | 355 | } |
| 356 | 356 | |
@@ -360,9 +360,9 @@ discard block |
||
| 360 | 360 | * @param array $attributes Data attributes |
| 361 | 361 | * @return object dbData object |
| 362 | 362 | */ |
| 363 | - function &addData( $attributes ) { |
|
| 364 | - if( !isset( $this->data ) ) { |
|
| 365 | - $this->data = new dbData( $this, $attributes ); |
|
| 363 | + function &addData($attributes) { |
|
| 364 | + if (!isset($this->data)) { |
|
| 365 | + $this->data = new dbData($this, $attributes); |
|
| 366 | 366 | } |
| 367 | 367 | return $this->data; |
| 368 | 368 | } |
@@ -396,8 +396,8 @@ discard block |
||
| 396 | 396 | * @param array $opts Field options array |
| 397 | 397 | * @return array Field specifier array |
| 398 | 398 | */ |
| 399 | - function addField( $name, $type, $size = NULL, $opts = NULL ) { |
|
| 400 | - $field_id = $this->FieldID( $name ); |
|
| 399 | + function addField($name, $type, $size = NULL, $opts = NULL) { |
|
| 400 | + $field_id = $this->FieldID($name); |
|
| 401 | 401 | |
| 402 | 402 | // Set the field index so we know where we are |
| 403 | 403 | $this->current_field = $field_id; |
@@ -409,12 +409,12 @@ discard block |
||
| 409 | 409 | $this->fields[$field_id]['TYPE'] = $type; |
| 410 | 410 | |
| 411 | 411 | // Set the field size (optional) |
| 412 | - if( isset( $size ) ) { |
|
| 412 | + if (isset($size)) { |
|
| 413 | 413 | $this->fields[$field_id]['SIZE'] = $size; |
| 414 | 414 | } |
| 415 | 415 | |
| 416 | 416 | // Set the field options |
| 417 | - if( isset( $opts ) ) { |
|
| 417 | + if (isset($opts)) { |
|
| 418 | 418 | $this->fields[$field_id]['OPTS'][] = $opts; |
| 419 | 419 | } |
| 420 | 420 | } |
@@ -430,12 +430,12 @@ discard block |
||
| 430 | 430 | * @param mixed $value Field option value |
| 431 | 431 | * @return array Field specifier array |
| 432 | 432 | */ |
| 433 | - function addFieldOpt( $field, $opt, $value = NULL ) { |
|
| 434 | - if( !isset( $value ) ) { |
|
| 435 | - $this->fields[$this->FieldID( $field )]['OPTS'][] = $opt; |
|
| 433 | + function addFieldOpt($field, $opt, $value = NULL) { |
|
| 434 | + if (!isset($value)) { |
|
| 435 | + $this->fields[$this->FieldID($field)]['OPTS'][] = $opt; |
|
| 436 | 436 | // Add the option and value |
| 437 | 437 | } else { |
| 438 | - $this->fields[$this->FieldID( $field )]['OPTS'][] = array( $opt => $value ); |
|
| 438 | + $this->fields[$this->FieldID($field)]['OPTS'][] = array($opt => $value); |
|
| 439 | 439 | } |
| 440 | 440 | } |
| 441 | 441 | |
@@ -448,7 +448,7 @@ discard block |
||
| 448 | 448 | * @param string $opt Table option |
| 449 | 449 | * @return array Options |
| 450 | 450 | */ |
| 451 | - function addTableOpt( $opt ) { |
|
| 451 | + function addTableOpt($opt) { |
|
| 452 | 452 | $this->opts[] = $opt; |
| 453 | 453 | |
| 454 | 454 | return $this->opts; |
@@ -460,39 +460,39 @@ discard block |
||
| 460 | 460 | * @param object $xmls adoSchema object |
| 461 | 461 | * @return array Array containing table creation SQL |
| 462 | 462 | */ |
| 463 | - function create( &$xmls ) { |
|
| 463 | + function create(&$xmls) { |
|
| 464 | 464 | $sql = array(); |
| 465 | 465 | |
| 466 | 466 | // drop any existing indexes |
| 467 | - if( is_array( $legacy_indexes = $xmls->dict->MetaIndexes( $this->name ) ) ) { |
|
| 468 | - foreach( $legacy_indexes as $index => $index_details ) { |
|
| 469 | - $sql[] = $xmls->dict->DropIndexSQL( $index, $this->name ); |
|
| 467 | + if (is_array($legacy_indexes = $xmls->dict->MetaIndexes($this->name))) { |
|
| 468 | + foreach ($legacy_indexes as $index => $index_details) { |
|
| 469 | + $sql[] = $xmls->dict->DropIndexSQL($index, $this->name); |
|
| 470 | 470 | } |
| 471 | 471 | } |
| 472 | 472 | |
| 473 | 473 | // remove fields to be dropped from table object |
| 474 | - foreach( $this->drop_field as $field ) { |
|
| 475 | - unset( $this->fields[$field] ); |
|
| 474 | + foreach ($this->drop_field as $field) { |
|
| 475 | + unset($this->fields[$field]); |
|
| 476 | 476 | } |
| 477 | 477 | |
| 478 | 478 | // if table exists |
| 479 | - if( is_array( $legacy_fields = $xmls->dict->MetaColumns( $this->name ) ) ) { |
|
| 479 | + if (is_array($legacy_fields = $xmls->dict->MetaColumns($this->name))) { |
|
| 480 | 480 | // drop table |
| 481 | - if( $this->drop_table ) { |
|
| 482 | - $sql[] = $xmls->dict->DropTableSQL( $this->name ); |
|
| 481 | + if ($this->drop_table) { |
|
| 482 | + $sql[] = $xmls->dict->DropTableSQL($this->name); |
|
| 483 | 483 | |
| 484 | 484 | return $sql; |
| 485 | 485 | } |
| 486 | 486 | |
| 487 | 487 | // drop any existing fields not in schema |
| 488 | - foreach( $legacy_fields as $field_id => $field ) { |
|
| 489 | - if( !isset( $this->fields[$field_id] ) ) { |
|
| 490 | - $sql[] = $xmls->dict->DropColumnSQL( $this->name, '`'.$field->name.'`' ); |
|
| 488 | + foreach ($legacy_fields as $field_id => $field) { |
|
| 489 | + if (!isset($this->fields[$field_id])) { |
|
| 490 | + $sql[] = $xmls->dict->DropColumnSQL($this->name, '`'.$field->name.'`'); |
|
| 491 | 491 | } |
| 492 | 492 | } |
| 493 | 493 | // if table doesn't exist |
| 494 | 494 | } else { |
| 495 | - if( $this->drop_table ) { |
|
| 495 | + if ($this->drop_table) { |
|
| 496 | 496 | return $sql; |
| 497 | 497 | } |
| 498 | 498 | |
@@ -502,9 +502,9 @@ discard block |
||
| 502 | 502 | // Loop through the field specifier array, building the associative array for the field options |
| 503 | 503 | $fldarray = array(); |
| 504 | 504 | |
| 505 | - foreach( $this->fields as $field_id => $finfo ) { |
|
| 505 | + foreach ($this->fields as $field_id => $finfo) { |
|
| 506 | 506 | // Set an empty size if it isn't supplied |
| 507 | - if( !isset( $finfo['SIZE'] ) ) { |
|
| 507 | + if (!isset($finfo['SIZE'])) { |
|
| 508 | 508 | $finfo['SIZE'] = ''; |
| 509 | 509 | } |
| 510 | 510 | |
@@ -516,12 +516,12 @@ discard block |
||
| 516 | 516 | ); |
| 517 | 517 | |
| 518 | 518 | // Loop through the options array and add the field options. |
| 519 | - if( isset( $finfo['OPTS'] ) ) { |
|
| 520 | - foreach( $finfo['OPTS'] as $opt ) { |
|
| 519 | + if (isset($finfo['OPTS'])) { |
|
| 520 | + foreach ($finfo['OPTS'] as $opt) { |
|
| 521 | 521 | // Option has an argument. |
| 522 | - if( is_array( $opt ) ) { |
|
| 523 | - $key = key( $opt ); |
|
| 524 | - $value = $opt[key( $opt )]; |
|
| 522 | + if (is_array($opt)) { |
|
| 523 | + $key = key($opt); |
|
| 524 | + $value = $opt[key($opt)]; |
|
| 525 | 525 | @$fldarray[$field_id][$key] .= $value; |
| 526 | 526 | // Option doesn't have arguments |
| 527 | 527 | } else { |
@@ -531,23 +531,23 @@ discard block |
||
| 531 | 531 | } |
| 532 | 532 | } |
| 533 | 533 | |
| 534 | - if( empty( $legacy_fields ) ) { |
|
| 534 | + if (empty($legacy_fields)) { |
|
| 535 | 535 | // Create the new table |
| 536 | - $sql[] = $xmls->dict->CreateTableSQL( $this->name, $fldarray, $this->opts ); |
|
| 537 | - logMsg( end( $sql ), 'Generated CreateTableSQL' ); |
|
| 536 | + $sql[] = $xmls->dict->CreateTableSQL($this->name, $fldarray, $this->opts); |
|
| 537 | + logMsg(end($sql), 'Generated CreateTableSQL'); |
|
| 538 | 538 | } else { |
| 539 | 539 | // Upgrade an existing table |
| 540 | - logMsg( "Upgrading {$this->name} using '{$xmls->upgrade}'" ); |
|
| 541 | - switch( $xmls->upgrade ) { |
|
| 540 | + logMsg("Upgrading {$this->name} using '{$xmls->upgrade}'"); |
|
| 541 | + switch ($xmls->upgrade) { |
|
| 542 | 542 | // Use ChangeTableSQL |
| 543 | 543 | case 'ALTER': |
| 544 | - logMsg( 'Generated ChangeTableSQL (ALTERing table)' ); |
|
| 545 | - $sql[] = $xmls->dict->ChangeTableSQL( $this->name, $fldarray, $this->opts ); |
|
| 544 | + logMsg('Generated ChangeTableSQL (ALTERing table)'); |
|
| 545 | + $sql[] = $xmls->dict->ChangeTableSQL($this->name, $fldarray, $this->opts); |
|
| 546 | 546 | break; |
| 547 | 547 | case 'REPLACE': |
| 548 | - logMsg( 'Doing upgrade REPLACE (testing)' ); |
|
| 549 | - $sql[] = $xmls->dict->DropTableSQL( $this->name ); |
|
| 550 | - $sql[] = $xmls->dict->CreateTableSQL( $this->name, $fldarray, $this->opts ); |
|
| 548 | + logMsg('Doing upgrade REPLACE (testing)'); |
|
| 549 | + $sql[] = $xmls->dict->DropTableSQL($this->name); |
|
| 550 | + $sql[] = $xmls->dict->CreateTableSQL($this->name, $fldarray, $this->opts); |
|
| 551 | 551 | break; |
| 552 | 552 | // ignore table |
| 553 | 553 | default: |
@@ -555,12 +555,12 @@ discard block |
||
| 555 | 555 | } |
| 556 | 556 | } |
| 557 | 557 | |
| 558 | - foreach( $this->indexes as $index ) { |
|
| 559 | - $sql[] = $index->create( $xmls ); |
|
| 558 | + foreach ($this->indexes as $index) { |
|
| 559 | + $sql[] = $index->create($xmls); |
|
| 560 | 560 | } |
| 561 | 561 | |
| 562 | - if( isset( $this->data ) ) { |
|
| 563 | - $sql[] = $this->data->create( $xmls ); |
|
| 562 | + if (isset($this->data)) { |
|
| 563 | + $sql[] = $this->data->create($xmls); |
|
| 564 | 564 | } |
| 565 | 565 | |
| 566 | 566 | return $sql; |
@@ -570,14 +570,14 @@ discard block |
||
| 570 | 570 | * Marks a field or table for destruction |
| 571 | 571 | */ |
| 572 | 572 | function drop() { |
| 573 | - if( isset( $this->current_field ) ) { |
|
| 573 | + if (isset($this->current_field)) { |
|
| 574 | 574 | // Drop the current field |
| 575 | - logMsg( "Dropping field '{$this->current_field}' from table '{$this->name}'" ); |
|
| 575 | + logMsg("Dropping field '{$this->current_field}' from table '{$this->name}'"); |
|
| 576 | 576 | // $this->drop_field[$this->current_field] = $xmls->dict->DropColumnSQL( $this->name, $this->current_field ); |
| 577 | 577 | $this->drop_field[$this->current_field] = $this->current_field; |
| 578 | 578 | } else { |
| 579 | 579 | // Drop the current table |
| 580 | - logMsg( "Dropping table '{$this->name}'" ); |
|
| 580 | + logMsg("Dropping table '{$this->name}'"); |
|
| 581 | 581 | // $this->drop_table = $xmls->dict->DropTableSQL( $this->name ); |
| 582 | 582 | $this->drop_table = TRUE; |
| 583 | 583 | } |
@@ -626,10 +626,10 @@ discard block |
||
| 626 | 626 | * |
| 627 | 627 | * @internal |
| 628 | 628 | */ |
| 629 | - function dbIndex( &$parent, $attributes = NULL ) { |
|
| 630 | - $this->parent =& $parent; |
|
| 629 | + function dbIndex(&$parent, $attributes = NULL) { |
|
| 630 | + $this->parent = & $parent; |
|
| 631 | 631 | |
| 632 | - $this->name = $this->prefix ($attributes['NAME']); |
|
| 632 | + $this->name = $this->prefix($attributes['NAME']); |
|
| 633 | 633 | } |
| 634 | 634 | |
| 635 | 635 | /** |
@@ -640,10 +640,10 @@ discard block |
||
| 640 | 640 | * |
| 641 | 641 | * @access private |
| 642 | 642 | */ |
| 643 | - function _tag_open( &$parser, $tag, $attributes ) { |
|
| 644 | - $this->currentElement = strtoupper( $tag ); |
|
| 643 | + function _tag_open(&$parser, $tag, $attributes) { |
|
| 644 | + $this->currentElement = strtoupper($tag); |
|
| 645 | 645 | |
| 646 | - switch( $this->currentElement ) { |
|
| 646 | + switch ($this->currentElement) { |
|
| 647 | 647 | case 'DROP': |
| 648 | 648 | $this->drop(); |
| 649 | 649 | break; |
@@ -653,7 +653,7 @@ discard block |
||
| 653 | 653 | case 'FULLTEXT': |
| 654 | 654 | case 'HASH': |
| 655 | 655 | // Add index Option |
| 656 | - $this->addIndexOpt( $this->currentElement ); |
|
| 656 | + $this->addIndexOpt($this->currentElement); |
|
| 657 | 657 | break; |
| 658 | 658 | default: |
| 659 | 659 | // print_r( array( $tag, $attributes ) ); |
@@ -667,11 +667,11 @@ discard block |
||
| 667 | 667 | * |
| 668 | 668 | * @access private |
| 669 | 669 | */ |
| 670 | - function _tag_cdata( &$parser, $cdata ) { |
|
| 671 | - switch( $this->currentElement ) { |
|
| 670 | + function _tag_cdata(&$parser, $cdata) { |
|
| 671 | + switch ($this->currentElement) { |
|
| 672 | 672 | // Index field name |
| 673 | 673 | case 'COL': |
| 674 | - $this->addField( $cdata ); |
|
| 674 | + $this->addField($cdata); |
|
| 675 | 675 | break; |
| 676 | 676 | default: |
| 677 | 677 | |
@@ -683,12 +683,12 @@ discard block |
||
| 683 | 683 | * |
| 684 | 684 | * @access private |
| 685 | 685 | */ |
| 686 | - function _tag_close( &$parser, $tag ) { |
|
| 686 | + function _tag_close(&$parser, $tag) { |
|
| 687 | 687 | $this->currentElement = ''; |
| 688 | 688 | |
| 689 | - switch( strtoupper( $tag ) ) { |
|
| 689 | + switch (strtoupper($tag)) { |
|
| 690 | 690 | case 'INDEX': |
| 691 | - xml_set_object( $parser, $this->parent ); |
|
| 691 | + xml_set_object($parser, $this->parent); |
|
| 692 | 692 | break; |
| 693 | 693 | } |
| 694 | 694 | } |
@@ -699,8 +699,8 @@ discard block |
||
| 699 | 699 | * @param string $name Field name |
| 700 | 700 | * @return string Field list |
| 701 | 701 | */ |
| 702 | - function addField( $name ) { |
|
| 703 | - $this->columns[$this->FieldID( $name )] = $name; |
|
| 702 | + function addField($name) { |
|
| 703 | + $this->columns[$this->FieldID($name)] = $name; |
|
| 704 | 704 | |
| 705 | 705 | // Return the field list |
| 706 | 706 | return $this->columns; |
@@ -712,7 +712,7 @@ discard block |
||
| 712 | 712 | * @param string $opt Comma-separated list of index options. |
| 713 | 713 | * @return string Option list |
| 714 | 714 | */ |
| 715 | - function addIndexOpt( $opt ) { |
|
| 715 | + function addIndexOpt($opt) { |
|
| 716 | 716 | $this->opts[] = $opt; |
| 717 | 717 | |
| 718 | 718 | // Return the options list |
@@ -725,19 +725,19 @@ discard block |
||
| 725 | 725 | * @param object $xmls adoSchema object |
| 726 | 726 | * @return array Array containing index creation SQL |
| 727 | 727 | */ |
| 728 | - function create( &$xmls ) { |
|
| 729 | - if( $this->drop ) { |
|
| 728 | + function create(&$xmls) { |
|
| 729 | + if ($this->drop) { |
|
| 730 | 730 | return NULL; |
| 731 | 731 | } |
| 732 | 732 | |
| 733 | 733 | // eliminate any columns that aren't in the table |
| 734 | - foreach( $this->columns as $id => $col ) { |
|
| 735 | - if( !isset( $this->parent->fields[$id] ) ) { |
|
| 736 | - unset( $this->columns[$id] ); |
|
| 734 | + foreach ($this->columns as $id => $col) { |
|
| 735 | + if (!isset($this->parent->fields[$id])) { |
|
| 736 | + unset($this->columns[$id]); |
|
| 737 | 737 | } |
| 738 | 738 | } |
| 739 | 739 | |
| 740 | - return $xmls->dict->CreateIndexSQL( $this->name, $this->parent->name, $this->columns, $this->opts ); |
|
| 740 | + return $xmls->dict->CreateIndexSQL($this->name, $this->parent->name, $this->columns, $this->opts); |
|
| 741 | 741 | } |
| 742 | 742 | |
| 743 | 743 | /** |
@@ -770,8 +770,8 @@ discard block |
||
| 770 | 770 | * |
| 771 | 771 | * @internal |
| 772 | 772 | */ |
| 773 | - function dbData( &$parent, $attributes = NULL ) { |
|
| 774 | - $this->parent =& $parent; |
|
| 773 | + function dbData(&$parent, $attributes = NULL) { |
|
| 774 | + $this->parent = & $parent; |
|
| 775 | 775 | } |
| 776 | 776 | |
| 777 | 777 | /** |
@@ -782,12 +782,12 @@ discard block |
||
| 782 | 782 | * |
| 783 | 783 | * @access private |
| 784 | 784 | */ |
| 785 | - function _tag_open( &$parser, $tag, $attributes ) { |
|
| 786 | - $this->currentElement = strtoupper( $tag ); |
|
| 785 | + function _tag_open(&$parser, $tag, $attributes) { |
|
| 786 | + $this->currentElement = strtoupper($tag); |
|
| 787 | 787 | |
| 788 | - switch( $this->currentElement ) { |
|
| 788 | + switch ($this->currentElement) { |
|
| 789 | 789 | case 'ROW': |
| 790 | - $this->row = count( $this->data ); |
|
| 790 | + $this->row = count($this->data); |
|
| 791 | 791 | $this->data[$this->row] = array(); |
| 792 | 792 | break; |
| 793 | 793 | case 'F': |
@@ -804,11 +804,11 @@ discard block |
||
| 804 | 804 | * |
| 805 | 805 | * @access private |
| 806 | 806 | */ |
| 807 | - function _tag_cdata( &$parser, $cdata ) { |
|
| 808 | - switch( $this->currentElement ) { |
|
| 807 | + function _tag_cdata(&$parser, $cdata) { |
|
| 808 | + switch ($this->currentElement) { |
|
| 809 | 809 | // Index field name |
| 810 | 810 | case 'F': |
| 811 | - $this->addData( $cdata ); |
|
| 811 | + $this->addData($cdata); |
|
| 812 | 812 | break; |
| 813 | 813 | default: |
| 814 | 814 | |
@@ -820,12 +820,12 @@ discard block |
||
| 820 | 820 | * |
| 821 | 821 | * @access private |
| 822 | 822 | */ |
| 823 | - function _tag_close( &$parser, $tag ) { |
|
| 823 | + function _tag_close(&$parser, $tag) { |
|
| 824 | 824 | $this->currentElement = ''; |
| 825 | 825 | |
| 826 | - switch( strtoupper( $tag ) ) { |
|
| 826 | + switch (strtoupper($tag)) { |
|
| 827 | 827 | case 'DATA': |
| 828 | - xml_set_object( $parser, $this->parent ); |
|
| 828 | + xml_set_object($parser, $this->parent); |
|
| 829 | 829 | break; |
| 830 | 830 | } |
| 831 | 831 | } |
@@ -836,15 +836,15 @@ discard block |
||
| 836 | 836 | * @param string $name Field name |
| 837 | 837 | * @return string Field list |
| 838 | 838 | */ |
| 839 | - function addField( $attributes ) { |
|
| 840 | - if( isset( $attributes['NAME'] ) ) { |
|
| 839 | + function addField($attributes) { |
|
| 840 | + if (isset($attributes['NAME'])) { |
|
| 841 | 841 | $name = $attributes['NAME']; |
| 842 | 842 | } else { |
| 843 | 843 | $name = count($this->data[$this->row]); |
| 844 | 844 | } |
| 845 | 845 | |
| 846 | 846 | // Set the field index so we know where we are |
| 847 | - $this->current_field = $this->FieldID( $name ); |
|
| 847 | + $this->current_field = $this->FieldID($name); |
|
| 848 | 848 | } |
| 849 | 849 | |
| 850 | 850 | /** |
@@ -853,12 +853,12 @@ discard block |
||
| 853 | 853 | * @param string $opt Comma-separated list of index options. |
| 854 | 854 | * @return string Option list |
| 855 | 855 | */ |
| 856 | - function addData( $cdata ) { |
|
| 857 | - if( !isset( $this->data[$this->row] ) ) { |
|
| 856 | + function addData($cdata) { |
|
| 857 | + if (!isset($this->data[$this->row])) { |
|
| 858 | 858 | $this->data[$this->row] = array(); |
| 859 | 859 | } |
| 860 | 860 | |
| 861 | - if( !isset( $this->data[$this->row][$this->current_field] ) ) { |
|
| 861 | + if (!isset($this->data[$this->row][$this->current_field])) { |
|
| 862 | 862 | $this->data[$this->row][$this->current_field] = ''; |
| 863 | 863 | } |
| 864 | 864 | |
@@ -871,20 +871,20 @@ discard block |
||
| 871 | 871 | * @param object $xmls adoSchema object |
| 872 | 872 | * @return array Array containing index creation SQL |
| 873 | 873 | */ |
| 874 | - function create( &$xmls ) { |
|
| 874 | + function create(&$xmls) { |
|
| 875 | 875 | $table = $xmls->dict->TableName($this->parent->name); |
| 876 | 876 | $table_field_count = count($this->parent->fields); |
| 877 | 877 | $sql = array(); |
| 878 | 878 | |
| 879 | 879 | // eliminate any columns that aren't in the table |
| 880 | - foreach( $this->data as $row ) { |
|
| 880 | + foreach ($this->data as $row) { |
|
| 881 | 881 | $table_fields = $this->parent->fields; |
| 882 | 882 | $fields = array(); |
| 883 | 883 | |
| 884 | - foreach( $row as $field_id => $field_data ) { |
|
| 885 | - if( !array_key_exists( $field_id, $table_fields ) ) { |
|
| 886 | - if( is_numeric( $field_id ) ) { |
|
| 887 | - $field_id = reset( array_keys( $table_fields ) ); |
|
| 884 | + foreach ($row as $field_id => $field_data) { |
|
| 885 | + if (!array_key_exists($field_id, $table_fields)) { |
|
| 886 | + if (is_numeric($field_id)) { |
|
| 887 | + $field_id = reset(array_keys($table_fields)); |
|
| 888 | 888 | } else { |
| 889 | 889 | continue; |
| 890 | 890 | } |
@@ -892,12 +892,12 @@ discard block |
||
| 892 | 892 | |
| 893 | 893 | $name = $table_fields[$field_id]['NAME']; |
| 894 | 894 | |
| 895 | - switch( $table_fields[$field_id]['TYPE'] ) { |
|
| 895 | + switch ($table_fields[$field_id]['TYPE']) { |
|
| 896 | 896 | case 'C': |
| 897 | 897 | case 'C2': |
| 898 | 898 | case 'X': |
| 899 | 899 | case 'X2': |
| 900 | - $fields[$name] = $xmls->db->qstr( $field_data ); |
|
| 900 | + $fields[$name] = $xmls->db->qstr($field_data); |
|
| 901 | 901 | break; |
| 902 | 902 | case 'I': |
| 903 | 903 | case 'I1': |
@@ -914,21 +914,21 @@ discard block |
||
| 914 | 914 | } |
| 915 | 915 | |
| 916 | 916 | // check that at least 1 column is specified |
| 917 | - if( empty( $fields ) ) { |
|
| 917 | + if (empty($fields)) { |
|
| 918 | 918 | continue; |
| 919 | 919 | } |
| 920 | 920 | |
| 921 | 921 | // check that no required columns are missing |
| 922 | - if( count( $fields ) < $table_field_count ) { |
|
| 923 | - foreach( $table_fields as $field ) { |
|
| 924 | - if (isset( $field['OPTS'] )) |
|
| 925 | - if( ( in_array( 'NOTNULL', $field['OPTS'] ) || in_array( 'KEY', $field['OPTS'] ) ) && !in_array( 'AUTOINCREMENT', $field['OPTS'] ) ) { |
|
| 922 | + if (count($fields) < $table_field_count) { |
|
| 923 | + foreach ($table_fields as $field) { |
|
| 924 | + if (isset($field['OPTS'])) |
|
| 925 | + if ((in_array('NOTNULL', $field['OPTS']) || in_array('KEY', $field['OPTS'])) && !in_array('AUTOINCREMENT', $field['OPTS'])) { |
|
| 926 | 926 | continue(2); |
| 927 | 927 | } |
| 928 | 928 | } |
| 929 | 929 | } |
| 930 | 930 | |
| 931 | - $sql[] = 'INSERT INTO '. $table .' ('. implode( ',', array_keys( $fields ) ) .') VALUES ('. implode( ',', $fields ) .')'; |
|
| 931 | + $sql[] = 'INSERT INTO '.$table.' ('.implode(',', array_keys($fields)).') VALUES ('.implode(',', $fields).')'; |
|
| 932 | 932 | } |
| 933 | 933 | |
| 934 | 934 | return $sql; |
@@ -969,18 +969,18 @@ discard block |
||
| 969 | 969 | * @param object $parent Parent object |
| 970 | 970 | * @param array $attributes Attributes |
| 971 | 971 | */ |
| 972 | - function dbQuerySet( &$parent, $attributes = NULL ) { |
|
| 973 | - $this->parent =& $parent; |
|
| 972 | + function dbQuerySet(&$parent, $attributes = NULL) { |
|
| 973 | + $this->parent = & $parent; |
|
| 974 | 974 | |
| 975 | 975 | // Overrides the manual prefix key |
| 976 | - if( isset( $attributes['KEY'] ) ) { |
|
| 976 | + if (isset($attributes['KEY'])) { |
|
| 977 | 977 | $this->prefixKey = $attributes['KEY']; |
| 978 | 978 | } |
| 979 | 979 | |
| 980 | - $prefixMethod = isset( $attributes['PREFIXMETHOD'] ) ? strtoupper( trim( $attributes['PREFIXMETHOD'] ) ) : ''; |
|
| 980 | + $prefixMethod = isset($attributes['PREFIXMETHOD']) ? strtoupper(trim($attributes['PREFIXMETHOD'])) : ''; |
|
| 981 | 981 | |
| 982 | 982 | // Enables or disables automatic prefix prepending |
| 983 | - switch( $prefixMethod ) { |
|
| 983 | + switch ($prefixMethod) { |
|
| 984 | 984 | case 'AUTO': |
| 985 | 985 | $this->prefixMethod = 'AUTO'; |
| 986 | 986 | break; |
@@ -999,15 +999,15 @@ discard block |
||
| 999 | 999 | * |
| 1000 | 1000 | * @access private |
| 1001 | 1001 | */ |
| 1002 | - function _tag_open( &$parser, $tag, $attributes ) { |
|
| 1003 | - $this->currentElement = strtoupper( $tag ); |
|
| 1002 | + function _tag_open(&$parser, $tag, $attributes) { |
|
| 1003 | + $this->currentElement = strtoupper($tag); |
|
| 1004 | 1004 | |
| 1005 | - switch( $this->currentElement ) { |
|
| 1005 | + switch ($this->currentElement) { |
|
| 1006 | 1006 | case 'QUERY': |
| 1007 | 1007 | // Create a new query in a SQL queryset. |
| 1008 | 1008 | // Ignore this query set if a platform is specified and it's different than the |
| 1009 | 1009 | // current connection platform. |
| 1010 | - if( !isset( $attributes['PLATFORM'] ) OR $this->supportedPlatform( $attributes['PLATFORM'] ) ) { |
|
| 1010 | + if (!isset($attributes['PLATFORM']) OR $this->supportedPlatform($attributes['PLATFORM'])) { |
|
| 1011 | 1011 | $this->newQuery(); |
| 1012 | 1012 | } else { |
| 1013 | 1013 | $this->discardQuery(); |
@@ -1021,11 +1021,11 @@ discard block |
||
| 1021 | 1021 | /** |
| 1022 | 1022 | * XML Callback to process CDATA elements |
| 1023 | 1023 | */ |
| 1024 | - function _tag_cdata( &$parser, $cdata ) { |
|
| 1025 | - switch( $this->currentElement ) { |
|
| 1024 | + function _tag_cdata(&$parser, $cdata) { |
|
| 1025 | + switch ($this->currentElement) { |
|
| 1026 | 1026 | // Line of queryset SQL data |
| 1027 | 1027 | case 'QUERY': |
| 1028 | - $this->buildQuery( $cdata ); |
|
| 1028 | + $this->buildQuery($cdata); |
|
| 1029 | 1029 | break; |
| 1030 | 1030 | default: |
| 1031 | 1031 | |
@@ -1037,17 +1037,17 @@ discard block |
||
| 1037 | 1037 | * |
| 1038 | 1038 | * @access private |
| 1039 | 1039 | */ |
| 1040 | - function _tag_close( &$parser, $tag ) { |
|
| 1040 | + function _tag_close(&$parser, $tag) { |
|
| 1041 | 1041 | $this->currentElement = ''; |
| 1042 | 1042 | |
| 1043 | - switch( strtoupper( $tag ) ) { |
|
| 1043 | + switch (strtoupper($tag)) { |
|
| 1044 | 1044 | case 'QUERY': |
| 1045 | 1045 | // Add the finished query to the open query set. |
| 1046 | 1046 | $this->addQuery(); |
| 1047 | 1047 | break; |
| 1048 | 1048 | case 'SQL': |
| 1049 | - $this->parent->addSQL( $this->create( $this->parent ) ); |
|
| 1050 | - xml_set_object( $parser, $this->parent ); |
|
| 1049 | + $this->parent->addSQL($this->create($this->parent)); |
|
| 1050 | + xml_set_object($parser, $this->parent); |
|
| 1051 | 1051 | $this->destroy(); |
| 1052 | 1052 | break; |
| 1053 | 1053 | default: |
@@ -1072,7 +1072,7 @@ discard block |
||
| 1072 | 1072 | * @return boolean TRUE |
| 1073 | 1073 | */ |
| 1074 | 1074 | function discardQuery() { |
| 1075 | - unset( $this->query ); |
|
| 1075 | + unset($this->query); |
|
| 1076 | 1076 | |
| 1077 | 1077 | return TRUE; |
| 1078 | 1078 | } |
@@ -1083,8 +1083,8 @@ discard block |
||
| 1083 | 1083 | * @param string $data Line of SQL data or NULL to initialize a new query |
| 1084 | 1084 | * @return string SQL query string. |
| 1085 | 1085 | */ |
| 1086 | - function buildQuery( $sql = NULL ) { |
|
| 1087 | - if( !isset( $this->query ) OR empty( $sql ) ) { |
|
| 1086 | + function buildQuery($sql = NULL) { |
|
| 1087 | + if (!isset($this->query) OR empty($sql)) { |
|
| 1088 | 1088 | return FALSE; |
| 1089 | 1089 | } |
| 1090 | 1090 | |
@@ -1099,13 +1099,13 @@ discard block |
||
| 1099 | 1099 | * @return string SQL of added query |
| 1100 | 1100 | */ |
| 1101 | 1101 | function addQuery() { |
| 1102 | - if( !isset( $this->query ) ) { |
|
| 1102 | + if (!isset($this->query)) { |
|
| 1103 | 1103 | return FALSE; |
| 1104 | 1104 | } |
| 1105 | 1105 | |
| 1106 | 1106 | $this->queries[] = $return = trim($this->query); |
| 1107 | 1107 | |
| 1108 | - unset( $this->query ); |
|
| 1108 | + unset($this->query); |
|
| 1109 | 1109 | |
| 1110 | 1110 | return $return; |
| 1111 | 1111 | } |
@@ -1116,17 +1116,17 @@ discard block |
||
| 1116 | 1116 | * @param object $xmls adoSchema object |
| 1117 | 1117 | * @return array Query set |
| 1118 | 1118 | */ |
| 1119 | - function create( &$xmls ) { |
|
| 1120 | - foreach( $this->queries as $id => $query ) { |
|
| 1121 | - switch( $this->prefixMethod ) { |
|
| 1119 | + function create(&$xmls) { |
|
| 1120 | + foreach ($this->queries as $id => $query) { |
|
| 1121 | + switch ($this->prefixMethod) { |
|
| 1122 | 1122 | case 'AUTO': |
| 1123 | 1123 | // Enable auto prefix replacement |
| 1124 | 1124 | |
| 1125 | 1125 | // Process object prefix. |
| 1126 | 1126 | // Evaluate SQL statements to prepend prefix to objects |
| 1127 | - $query = $this->prefixQuery( '/^\s*((?is)INSERT\s+(INTO\s+)?)((\w+\s*,?\s*)+)(\s.*$)/', $query, $xmls->objectPrefix ); |
|
| 1128 | - $query = $this->prefixQuery( '/^\s*((?is)UPDATE\s+(FROM\s+)?)((\w+\s*,?\s*)+)(\s.*$)/', $query, $xmls->objectPrefix ); |
|
| 1129 | - $query = $this->prefixQuery( '/^\s*((?is)DELETE\s+(FROM\s+)?)((\w+\s*,?\s*)+)(\s.*$)/', $query, $xmls->objectPrefix ); |
|
| 1127 | + $query = $this->prefixQuery('/^\s*((?is)INSERT\s+(INTO\s+)?)((\w+\s*,?\s*)+)(\s.*$)/', $query, $xmls->objectPrefix); |
|
| 1128 | + $query = $this->prefixQuery('/^\s*((?is)UPDATE\s+(FROM\s+)?)((\w+\s*,?\s*)+)(\s.*$)/', $query, $xmls->objectPrefix); |
|
| 1129 | + $query = $this->prefixQuery('/^\s*((?is)DELETE\s+(FROM\s+)?)((\w+\s*,?\s*)+)(\s.*$)/', $query, $xmls->objectPrefix); |
|
| 1130 | 1130 | |
| 1131 | 1131 | // SELECT statements aren't working yet |
| 1132 | 1132 | #$data = preg_replace( '/(?ias)(^\s*SELECT\s+.*\s+FROM)\s+(\W\s*,?\s*)+((?i)\s+WHERE.*$)/', "\1 $prefix\2 \3", $data ); |
@@ -1134,16 +1134,16 @@ discard block |
||
| 1134 | 1134 | case 'MANUAL': |
| 1135 | 1135 | // If prefixKey is set and has a value then we use it to override the default constant XMLS_PREFIX. |
| 1136 | 1136 | // If prefixKey is not set, we use the default constant XMLS_PREFIX |
| 1137 | - if( isset( $this->prefixKey ) AND( $this->prefixKey !== '' ) ) { |
|
| 1137 | + if (isset($this->prefixKey) AND ($this->prefixKey !== '')) { |
|
| 1138 | 1138 | // Enable prefix override |
| 1139 | - $query = str_replace( $this->prefixKey, $xmls->objectPrefix, $query ); |
|
| 1139 | + $query = str_replace($this->prefixKey, $xmls->objectPrefix, $query); |
|
| 1140 | 1140 | } else { |
| 1141 | 1141 | // Use default replacement |
| 1142 | - $query = str_replace( XMLS_PREFIX , $xmls->objectPrefix, $query ); |
|
| 1142 | + $query = str_replace(XMLS_PREFIX, $xmls->objectPrefix, $query); |
|
| 1143 | 1143 | } |
| 1144 | 1144 | } |
| 1145 | 1145 | |
| 1146 | - $this->queries[$id] = trim( $query ); |
|
| 1146 | + $this->queries[$id] = trim($query); |
|
| 1147 | 1147 | } |
| 1148 | 1148 | |
| 1149 | 1149 | // Return the query set array |
@@ -1158,28 +1158,28 @@ discard block |
||
| 1158 | 1158 | * @param string $prefix Prefix to be appended to tables, indices, etc. |
| 1159 | 1159 | * @return string Prefixed SQL query string. |
| 1160 | 1160 | */ |
| 1161 | - function prefixQuery( $regex, $query, $prefix = NULL ) { |
|
| 1162 | - if( !isset( $prefix ) ) { |
|
| 1161 | + function prefixQuery($regex, $query, $prefix = NULL) { |
|
| 1162 | + if (!isset($prefix)) { |
|
| 1163 | 1163 | return $query; |
| 1164 | 1164 | } |
| 1165 | 1165 | |
| 1166 | - if( preg_match( $regex, $query, $match ) ) { |
|
| 1166 | + if (preg_match($regex, $query, $match)) { |
|
| 1167 | 1167 | $preamble = $match[1]; |
| 1168 | 1168 | $postamble = $match[5]; |
| 1169 | - $objectList = explode( ',', $match[3] ); |
|
| 1169 | + $objectList = explode(',', $match[3]); |
|
| 1170 | 1170 | // $prefix = $prefix . '_'; |
| 1171 | 1171 | |
| 1172 | 1172 | $prefixedList = ''; |
| 1173 | 1173 | |
| 1174 | - foreach( $objectList as $object ) { |
|
| 1175 | - if( $prefixedList !== '' ) { |
|
| 1174 | + foreach ($objectList as $object) { |
|
| 1175 | + if ($prefixedList !== '') { |
|
| 1176 | 1176 | $prefixedList .= ', '; |
| 1177 | 1177 | } |
| 1178 | 1178 | |
| 1179 | - $prefixedList .= $prefix . trim( $object ); |
|
| 1179 | + $prefixedList .= $prefix.trim($object); |
|
| 1180 | 1180 | } |
| 1181 | 1181 | |
| 1182 | - $query = $preamble . ' ' . $prefixedList . ' ' . $postamble; |
|
| 1182 | + $query = $preamble.' '.$prefixedList.' '.$postamble; |
|
| 1183 | 1183 | } |
| 1184 | 1184 | |
| 1185 | 1185 | return $query; |
@@ -1285,18 +1285,18 @@ discard block |
||
| 1285 | 1285 | * |
| 1286 | 1286 | * @param object $db ADOdb database connection object. |
| 1287 | 1287 | */ |
| 1288 | - function adoSchema( &$db ) { |
|
| 1288 | + function adoSchema(&$db) { |
|
| 1289 | 1289 | // Initialize the environment |
| 1290 | 1290 | $this->mgq = get_magic_quotes_runtime(); |
| 1291 | 1291 | set_magic_quotes_runtime(0); |
| 1292 | 1292 | |
| 1293 | - $this->db =& $db; |
|
| 1293 | + $this->db = & $db; |
|
| 1294 | 1294 | $this->debug = $this->db->debug; |
| 1295 | - $this->dict = NewDataDictionary( $this->db ); |
|
| 1295 | + $this->dict = NewDataDictionary($this->db); |
|
| 1296 | 1296 | $this->sqlArray = array(); |
| 1297 | 1297 | $this->schemaVersion = XMLS_SCHEMA_VERSION; |
| 1298 | - $this->executeInline( XMLS_EXECUTE_INLINE ); |
|
| 1299 | - $this->continueOnError( XMLS_CONTINUE_ON_ERROR ); |
|
| 1298 | + $this->executeInline(XMLS_EXECUTE_INLINE); |
|
| 1299 | + $this->continueOnError(XMLS_CONTINUE_ON_ERROR); |
|
| 1300 | 1300 | $this->setUpgradeMethod(); |
| 1301 | 1301 | } |
| 1302 | 1302 | |
@@ -1316,15 +1316,15 @@ discard block |
||
| 1316 | 1316 | * @param string $method Upgrade method (ALTER|REPLACE|BEST|NONE) |
| 1317 | 1317 | * @returns string Upgrade method used |
| 1318 | 1318 | */ |
| 1319 | - function SetUpgradeMethod( $method = '' ) { |
|
| 1320 | - if( !is_string( $method ) ) { |
|
| 1319 | + function SetUpgradeMethod($method = '') { |
|
| 1320 | + if (!is_string($method)) { |
|
| 1321 | 1321 | return FALSE; |
| 1322 | 1322 | } |
| 1323 | 1323 | |
| 1324 | - $method = strtoupper( $method ); |
|
| 1324 | + $method = strtoupper($method); |
|
| 1325 | 1325 | |
| 1326 | 1326 | // Handle the upgrade methods |
| 1327 | - switch( $method ) { |
|
| 1327 | + switch ($method) { |
|
| 1328 | 1328 | case 'ALTER': |
| 1329 | 1329 | $this->upgrade = $method; |
| 1330 | 1330 | break; |
@@ -1358,8 +1358,8 @@ discard block |
||
| 1358 | 1358 | * |
| 1359 | 1359 | * @see ParseSchema(), ExecuteSchema() |
| 1360 | 1360 | */ |
| 1361 | - function ExecuteInline( $mode = NULL ) { |
|
| 1362 | - if( is_bool( $mode ) ) { |
|
| 1361 | + function ExecuteInline($mode = NULL) { |
|
| 1362 | + if (is_bool($mode)) { |
|
| 1363 | 1363 | $this->executeInline = $mode; |
| 1364 | 1364 | } |
| 1365 | 1365 | |
@@ -1379,8 +1379,8 @@ discard block |
||
| 1379 | 1379 | * |
| 1380 | 1380 | * @see addSQL(), ExecuteSchema() |
| 1381 | 1381 | */ |
| 1382 | - function ContinueOnError( $mode = NULL ) { |
|
| 1383 | - if( is_bool( $mode ) ) { |
|
| 1382 | + function ContinueOnError($mode = NULL) { |
|
| 1383 | + if (is_bool($mode)) { |
|
| 1384 | 1384 | $this->continueOnError = $mode; |
| 1385 | 1385 | } |
| 1386 | 1386 | |
@@ -1398,8 +1398,8 @@ discard block |
||
| 1398 | 1398 | * @param bool $returnSchema Return schema rather than parsing. |
| 1399 | 1399 | * @return array Array of SQL queries, ready to execute |
| 1400 | 1400 | */ |
| 1401 | - function ParseSchema( $filename, $returnSchema = FALSE ) { |
|
| 1402 | - return $this->ParseSchemaString( $this->ConvertSchemaFile( $filename ), $returnSchema ); |
|
| 1401 | + function ParseSchema($filename, $returnSchema = FALSE) { |
|
| 1402 | + return $this->ParseSchemaString($this->ConvertSchemaFile($filename), $returnSchema); |
|
| 1403 | 1403 | } |
| 1404 | 1404 | |
| 1405 | 1405 | /** |
@@ -1415,19 +1415,19 @@ discard block |
||
| 1415 | 1415 | * @deprecated Replaced by adoSchema::ParseSchema() and adoSchema::ParseSchemaString() |
| 1416 | 1416 | * @see ParseSchema(), ParseSchemaString() |
| 1417 | 1417 | */ |
| 1418 | - function ParseSchemaFile( $filename, $returnSchema = FALSE ) { |
|
| 1418 | + function ParseSchemaFile($filename, $returnSchema = FALSE) { |
|
| 1419 | 1419 | // Open the file |
| 1420 | - if( !($fp = fopen( $filename, 'r' )) ) { |
|
| 1420 | + if (!($fp = fopen($filename, 'r'))) { |
|
| 1421 | 1421 | // die( 'Unable to open file' ); |
| 1422 | 1422 | return FALSE; |
| 1423 | 1423 | } |
| 1424 | 1424 | |
| 1425 | 1425 | // do version detection here |
| 1426 | - if( $this->SchemaFileVersion( $filename ) != $this->schemaVersion ) { |
|
| 1426 | + if ($this->SchemaFileVersion($filename) != $this->schemaVersion) { |
|
| 1427 | 1427 | return FALSE; |
| 1428 | 1428 | } |
| 1429 | 1429 | |
| 1430 | - if ( $returnSchema ) |
|
| 1430 | + if ($returnSchema) |
|
| 1431 | 1431 | { |
| 1432 | 1432 | return $xmlstring; |
| 1433 | 1433 | } |
@@ -1437,17 +1437,17 @@ discard block |
||
| 1437 | 1437 | $xmlParser = $this->create_parser(); |
| 1438 | 1438 | |
| 1439 | 1439 | // Process the file |
| 1440 | - while( $data = fread( $fp, 4096 ) ) { |
|
| 1441 | - if( !xml_parse( $xmlParser, $data, feof( $fp ) ) ) { |
|
| 1442 | - die( sprintf( |
|
| 1440 | + while ($data = fread($fp, 4096)) { |
|
| 1441 | + if (!xml_parse($xmlParser, $data, feof($fp))) { |
|
| 1442 | + die(sprintf( |
|
| 1443 | 1443 | "XML error: %s at line %d", |
| 1444 | - xml_error_string( xml_get_error_code( $xmlParser) ), |
|
| 1445 | - xml_get_current_line_number( $xmlParser) |
|
| 1446 | - ) ); |
|
| 1444 | + xml_error_string(xml_get_error_code($xmlParser)), |
|
| 1445 | + xml_get_current_line_number($xmlParser) |
|
| 1446 | + )); |
|
| 1447 | 1447 | } |
| 1448 | 1448 | } |
| 1449 | 1449 | |
| 1450 | - xml_parser_free( $xmlParser ); |
|
| 1450 | + xml_parser_free($xmlParser); |
|
| 1451 | 1451 | |
| 1452 | 1452 | return $this->sqlArray; |
| 1453 | 1453 | } |
@@ -1463,17 +1463,17 @@ discard block |
||
| 1463 | 1463 | * @param bool $returnSchema Return schema rather than parsing. |
| 1464 | 1464 | * @return array Array of SQL queries, ready to execute. |
| 1465 | 1465 | */ |
| 1466 | - function ParseSchemaString( $xmlstring, $returnSchema = FALSE ) { |
|
| 1467 | - if( !is_string( $xmlstring ) OR empty( $xmlstring ) ) { |
|
| 1466 | + function ParseSchemaString($xmlstring, $returnSchema = FALSE) { |
|
| 1467 | + if (!is_string($xmlstring) OR empty($xmlstring)) { |
|
| 1468 | 1468 | return FALSE; |
| 1469 | 1469 | } |
| 1470 | 1470 | |
| 1471 | 1471 | // do version detection here |
| 1472 | - if( $this->SchemaStringVersion( $xmlstring ) != $this->schemaVersion ) { |
|
| 1472 | + if ($this->SchemaStringVersion($xmlstring) != $this->schemaVersion) { |
|
| 1473 | 1473 | return FALSE; |
| 1474 | 1474 | } |
| 1475 | 1475 | |
| 1476 | - if ( $returnSchema ) |
|
| 1476 | + if ($returnSchema) |
|
| 1477 | 1477 | { |
| 1478 | 1478 | return $xmlstring; |
| 1479 | 1479 | } |
@@ -1482,15 +1482,15 @@ discard block |
||
| 1482 | 1482 | |
| 1483 | 1483 | $xmlParser = $this->create_parser(); |
| 1484 | 1484 | |
| 1485 | - if( !xml_parse( $xmlParser, $xmlstring, TRUE ) ) { |
|
| 1486 | - die( sprintf( |
|
| 1485 | + if (!xml_parse($xmlParser, $xmlstring, TRUE)) { |
|
| 1486 | + die(sprintf( |
|
| 1487 | 1487 | "XML error: %s at line %d", |
| 1488 | - xml_error_string( xml_get_error_code( $xmlParser) ), |
|
| 1489 | - xml_get_current_line_number( $xmlParser) |
|
| 1490 | - ) ); |
|
| 1488 | + xml_error_string(xml_get_error_code($xmlParser)), |
|
| 1489 | + xml_get_current_line_number($xmlParser) |
|
| 1490 | + )); |
|
| 1491 | 1491 | } |
| 1492 | 1492 | |
| 1493 | - xml_parser_free( $xmlParser ); |
|
| 1493 | + xml_parser_free($xmlParser); |
|
| 1494 | 1494 | |
| 1495 | 1495 | return $this->sqlArray; |
| 1496 | 1496 | } |
@@ -1506,8 +1506,8 @@ discard block |
||
| 1506 | 1506 | * @param bool $returnSchema Return schema rather than parsing. |
| 1507 | 1507 | * @return array Array of SQL queries, ready to execute |
| 1508 | 1508 | */ |
| 1509 | - function RemoveSchema( $filename, $returnSchema = FALSE ) { |
|
| 1510 | - return $this->RemoveSchemaString( $this->ConvertSchemaFile( $filename ), $returnSchema ); |
|
| 1509 | + function RemoveSchema($filename, $returnSchema = FALSE) { |
|
| 1510 | + return $this->RemoveSchemaString($this->ConvertSchemaFile($filename), $returnSchema); |
|
| 1511 | 1511 | } |
| 1512 | 1512 | |
| 1513 | 1513 | /** |
@@ -1521,14 +1521,14 @@ discard block |
||
| 1521 | 1521 | * @param bool $returnSchema Return schema rather than parsing. |
| 1522 | 1522 | * @return array Array of SQL queries, ready to execute. |
| 1523 | 1523 | */ |
| 1524 | - function RemoveSchemaString( $schema, $returnSchema = FALSE ) { |
|
| 1524 | + function RemoveSchemaString($schema, $returnSchema = FALSE) { |
|
| 1525 | 1525 | |
| 1526 | 1526 | // grab current version |
| 1527 | - if( !( $version = $this->SchemaStringVersion( $schema ) ) ) { |
|
| 1527 | + if (!($version = $this->SchemaStringVersion($schema))) { |
|
| 1528 | 1528 | return FALSE; |
| 1529 | 1529 | } |
| 1530 | 1530 | |
| 1531 | - return $this->ParseSchemaString( $this->TransformSchema( $schema, 'remove-' . $version), $returnSchema ); |
|
| 1531 | + return $this->ParseSchemaString($this->TransformSchema($schema, 'remove-'.$version), $returnSchema); |
|
| 1532 | 1532 | } |
| 1533 | 1533 | |
| 1534 | 1534 | /** |
@@ -1544,19 +1544,19 @@ discard block |
||
| 1544 | 1544 | * @param boolean $continueOnErr Continue to apply the schema even if an error occurs. |
| 1545 | 1545 | * @returns integer 0 if failure, 1 if errors, 2 if successful. |
| 1546 | 1546 | */ |
| 1547 | - function ExecuteSchema( $sqlArray = NULL, $continueOnErr = NULL ) { |
|
| 1548 | - if( !is_bool( $continueOnErr ) ) { |
|
| 1547 | + function ExecuteSchema($sqlArray = NULL, $continueOnErr = NULL) { |
|
| 1548 | + if (!is_bool($continueOnErr)) { |
|
| 1549 | 1549 | $continueOnErr = $this->ContinueOnError(); |
| 1550 | 1550 | } |
| 1551 | 1551 | |
| 1552 | - if( !isset( $sqlArray ) ) { |
|
| 1552 | + if (!isset($sqlArray)) { |
|
| 1553 | 1553 | $sqlArray = $this->sqlArray; |
| 1554 | 1554 | } |
| 1555 | 1555 | |
| 1556 | - if( !is_array( $sqlArray ) ) { |
|
| 1556 | + if (!is_array($sqlArray)) { |
|
| 1557 | 1557 | $this->success = 0; |
| 1558 | 1558 | } else { |
| 1559 | - $this->success = $this->dict->ExecuteSQLArray( $sqlArray, $continueOnErr ); |
|
| 1559 | + $this->success = $this->dict->ExecuteSQLArray($sqlArray, $continueOnErr); |
|
| 1560 | 1560 | } |
| 1561 | 1561 | |
| 1562 | 1562 | return $this->success; |
@@ -1571,8 +1571,8 @@ discard block |
||
| 1571 | 1571 | * @param string $format Format: HTML, TEXT, or NONE (PHP array) |
| 1572 | 1572 | * @return array Array of SQL statements or FALSE if an error occurs |
| 1573 | 1573 | */ |
| 1574 | - function PrintSQL( $format = 'NONE' ) { |
|
| 1575 | - return $this->getSQL( $format, $sqlArray ); |
|
| 1574 | + function PrintSQL($format = 'NONE') { |
|
| 1575 | + return $this->getSQL($format, $sqlArray); |
|
| 1576 | 1576 | } |
| 1577 | 1577 | |
| 1578 | 1578 | /** |
@@ -1584,21 +1584,21 @@ discard block |
||
| 1584 | 1584 | * @param string $filename Path and name where the file should be saved. |
| 1585 | 1585 | * @return boolean TRUE if save is successful, else FALSE. |
| 1586 | 1586 | */ |
| 1587 | - function SaveSQL( $filename = './schema.sql' ) { |
|
| 1587 | + function SaveSQL($filename = './schema.sql') { |
|
| 1588 | 1588 | |
| 1589 | - if( !isset( $sqlArray ) ) { |
|
| 1589 | + if (!isset($sqlArray)) { |
|
| 1590 | 1590 | $sqlArray = $this->sqlArray; |
| 1591 | 1591 | } |
| 1592 | - if( !isset( $sqlArray ) ) { |
|
| 1592 | + if (!isset($sqlArray)) { |
|
| 1593 | 1593 | return FALSE; |
| 1594 | 1594 | } |
| 1595 | 1595 | |
| 1596 | - $fp = fopen( $filename, "w" ); |
|
| 1596 | + $fp = fopen($filename, "w"); |
|
| 1597 | 1597 | |
| 1598 | - foreach( $sqlArray as $key => $query ) { |
|
| 1599 | - fwrite( $fp, $query . ";\n" ); |
|
| 1598 | + foreach ($sqlArray as $key => $query) { |
|
| 1599 | + fwrite($fp, $query.";\n"); |
|
| 1600 | 1600 | } |
| 1601 | - fclose( $fp ); |
|
| 1601 | + fclose($fp); |
|
| 1602 | 1602 | } |
| 1603 | 1603 | |
| 1604 | 1604 | /** |
@@ -1611,11 +1611,11 @@ discard block |
||
| 1611 | 1611 | function &create_parser() { |
| 1612 | 1612 | // Create the parser |
| 1613 | 1613 | $xmlParser = xml_parser_create(); |
| 1614 | - xml_set_object( $xmlParser, $this ); |
|
| 1614 | + xml_set_object($xmlParser, $this); |
|
| 1615 | 1615 | |
| 1616 | 1616 | // Initialize the XML callback functions |
| 1617 | - xml_set_element_handler( $xmlParser, '_tag_open', '_tag_close' ); |
|
| 1618 | - xml_set_character_data_handler( $xmlParser, '_tag_cdata' ); |
|
| 1617 | + xml_set_element_handler($xmlParser, '_tag_open', '_tag_close'); |
|
| 1618 | + xml_set_character_data_handler($xmlParser, '_tag_cdata'); |
|
| 1619 | 1619 | |
| 1620 | 1620 | return $xmlParser; |
| 1621 | 1621 | } |
@@ -1625,16 +1625,16 @@ discard block |
||
| 1625 | 1625 | * |
| 1626 | 1626 | * @access private |
| 1627 | 1627 | */ |
| 1628 | - function _tag_open( &$parser, $tag, $attributes ) { |
|
| 1629 | - switch( strtoupper( $tag ) ) { |
|
| 1628 | + function _tag_open(&$parser, $tag, $attributes) { |
|
| 1629 | + switch (strtoupper($tag)) { |
|
| 1630 | 1630 | case 'TABLE': |
| 1631 | - $this->obj = new dbTable( $this, $attributes ); |
|
| 1632 | - xml_set_object( $parser, $this->obj ); |
|
| 1631 | + $this->obj = new dbTable($this, $attributes); |
|
| 1632 | + xml_set_object($parser, $this->obj); |
|
| 1633 | 1633 | break; |
| 1634 | 1634 | case 'SQL': |
| 1635 | - if( !isset( $attributes['PLATFORM'] ) OR $this->supportedPlatform( $attributes['PLATFORM'] ) ) { |
|
| 1636 | - $this->obj = new dbQuerySet( $this, $attributes ); |
|
| 1637 | - xml_set_object( $parser, $this->obj ); |
|
| 1635 | + if (!isset($attributes['PLATFORM']) OR $this->supportedPlatform($attributes['PLATFORM'])) { |
|
| 1636 | + $this->obj = new dbQuerySet($this, $attributes); |
|
| 1637 | + xml_set_object($parser, $this->obj); |
|
| 1638 | 1638 | } |
| 1639 | 1639 | break; |
| 1640 | 1640 | default: |
@@ -1648,7 +1648,7 @@ discard block |
||
| 1648 | 1648 | * |
| 1649 | 1649 | * @access private |
| 1650 | 1650 | */ |
| 1651 | - function _tag_cdata( &$parser, $cdata ) { |
|
| 1651 | + function _tag_cdata(&$parser, $cdata) { |
|
| 1652 | 1652 | } |
| 1653 | 1653 | |
| 1654 | 1654 | /** |
@@ -1657,7 +1657,7 @@ discard block |
||
| 1657 | 1657 | * @access private |
| 1658 | 1658 | * @internal |
| 1659 | 1659 | */ |
| 1660 | - function _tag_close( &$parser, $tag ) { |
|
| 1660 | + function _tag_close(&$parser, $tag) { |
|
| 1661 | 1661 | |
| 1662 | 1662 | } |
| 1663 | 1663 | |
@@ -1677,26 +1677,26 @@ discard block |
||
| 1677 | 1677 | * @param string $newFile File name of (converted) output file. |
| 1678 | 1678 | * @return string Converted XML schema or FALSE if an error occurs. |
| 1679 | 1679 | */ |
| 1680 | - function ConvertSchemaString( $schema, $newVersion = NULL, $newFile = NULL ) { |
|
| 1680 | + function ConvertSchemaString($schema, $newVersion = NULL, $newFile = NULL) { |
|
| 1681 | 1681 | |
| 1682 | 1682 | // grab current version |
| 1683 | - if( !( $version = $this->SchemaStringVersion( $schema ) ) ) { |
|
| 1683 | + if (!($version = $this->SchemaStringVersion($schema))) { |
|
| 1684 | 1684 | return FALSE; |
| 1685 | 1685 | } |
| 1686 | 1686 | |
| 1687 | - if( !isset ($newVersion) ) { |
|
| 1687 | + if (!isset ($newVersion)) { |
|
| 1688 | 1688 | $newVersion = $this->schemaVersion; |
| 1689 | 1689 | } |
| 1690 | 1690 | |
| 1691 | - if( $version == $newVersion ) { |
|
| 1691 | + if ($version == $newVersion) { |
|
| 1692 | 1692 | $result = $schema; |
| 1693 | 1693 | } else { |
| 1694 | - $result = $this->TransformSchema( $schema, 'convert-' . $version . '-' . $newVersion); |
|
| 1694 | + $result = $this->TransformSchema($schema, 'convert-'.$version.'-'.$newVersion); |
|
| 1695 | 1695 | } |
| 1696 | 1696 | |
| 1697 | - if( is_string( $result ) AND is_string( $newFile ) AND ( $fp = fopen( $newFile, 'w' ) ) ) { |
|
| 1698 | - fwrite( $fp, $result ); |
|
| 1699 | - fclose( $fp ); |
|
| 1697 | + if (is_string($result) AND is_string($newFile) AND ($fp = fopen($newFile, 'w'))) { |
|
| 1698 | + fwrite($fp, $result); |
|
| 1699 | + fclose($fp); |
|
| 1700 | 1700 | } |
| 1701 | 1701 | |
| 1702 | 1702 | return $result; |
@@ -1718,81 +1718,81 @@ discard block |
||
| 1718 | 1718 | * @param string $newFile File name of (converted) output file. |
| 1719 | 1719 | * @return string Converted XML schema or FALSE if an error occurs. |
| 1720 | 1720 | */ |
| 1721 | - function ConvertSchemaFile( $filename, $newVersion = NULL, $newFile = NULL ) { |
|
| 1721 | + function ConvertSchemaFile($filename, $newVersion = NULL, $newFile = NULL) { |
|
| 1722 | 1722 | |
| 1723 | 1723 | // grab current version |
| 1724 | - if( !( $version = $this->SchemaFileVersion( $filename ) ) ) { |
|
| 1724 | + if (!($version = $this->SchemaFileVersion($filename))) { |
|
| 1725 | 1725 | return FALSE; |
| 1726 | 1726 | } |
| 1727 | 1727 | |
| 1728 | - if( !isset ($newVersion) ) { |
|
| 1728 | + if (!isset ($newVersion)) { |
|
| 1729 | 1729 | $newVersion = $this->schemaVersion; |
| 1730 | 1730 | } |
| 1731 | 1731 | |
| 1732 | - if( $version == $newVersion ) { |
|
| 1733 | - $result = file_get_contents( $filename ); |
|
| 1732 | + if ($version == $newVersion) { |
|
| 1733 | + $result = file_get_contents($filename); |
|
| 1734 | 1734 | |
| 1735 | 1735 | // remove unicode BOM if present |
| 1736 | - if( substr( $result, 0, 3 ) == sprintf( '%c%c%c', 239, 187, 191 ) ) { |
|
| 1737 | - $result = substr( $result, 3 ); |
|
| 1736 | + if (substr($result, 0, 3) == sprintf('%c%c%c', 239, 187, 191)) { |
|
| 1737 | + $result = substr($result, 3); |
|
| 1738 | 1738 | } |
| 1739 | 1739 | } else { |
| 1740 | - $result = $this->TransformSchema( $filename, 'convert-' . $version . '-' . $newVersion, 'file' ); |
|
| 1740 | + $result = $this->TransformSchema($filename, 'convert-'.$version.'-'.$newVersion, 'file'); |
|
| 1741 | 1741 | } |
| 1742 | 1742 | |
| 1743 | - if( is_string( $result ) AND is_string( $newFile ) AND ( $fp = fopen( $newFile, 'w' ) ) ) { |
|
| 1744 | - fwrite( $fp, $result ); |
|
| 1745 | - fclose( $fp ); |
|
| 1743 | + if (is_string($result) AND is_string($newFile) AND ($fp = fopen($newFile, 'w'))) { |
|
| 1744 | + fwrite($fp, $result); |
|
| 1745 | + fclose($fp); |
|
| 1746 | 1746 | } |
| 1747 | 1747 | |
| 1748 | 1748 | return $result; |
| 1749 | 1749 | } |
| 1750 | 1750 | |
| 1751 | - function TransformSchema( $schema, $xsl, $schematype='string' ) |
|
| 1751 | + function TransformSchema($schema, $xsl, $schematype = 'string') |
|
| 1752 | 1752 | { |
| 1753 | 1753 | // Fail if XSLT extension is not available |
| 1754 | - if( ! function_exists( 'xslt_create' ) ) { |
|
| 1754 | + if (!function_exists('xslt_create')) { |
|
| 1755 | 1755 | return FALSE; |
| 1756 | 1756 | } |
| 1757 | 1757 | |
| 1758 | - $xsl_file = dirname( __FILE__ ) . '/xsl/' . $xsl . '.xsl'; |
|
| 1758 | + $xsl_file = dirname(__FILE__).'/xsl/'.$xsl.'.xsl'; |
|
| 1759 | 1759 | |
| 1760 | 1760 | // look for xsl |
| 1761 | - if( !is_readable( $xsl_file ) ) { |
|
| 1761 | + if (!is_readable($xsl_file)) { |
|
| 1762 | 1762 | return FALSE; |
| 1763 | 1763 | } |
| 1764 | 1764 | |
| 1765 | - switch( $schematype ) |
|
| 1765 | + switch ($schematype) |
|
| 1766 | 1766 | { |
| 1767 | 1767 | case 'file': |
| 1768 | - if( !is_readable( $schema ) ) { |
|
| 1768 | + if (!is_readable($schema)) { |
|
| 1769 | 1769 | return FALSE; |
| 1770 | 1770 | } |
| 1771 | 1771 | |
| 1772 | - $schema = file_get_contents( $schema ); |
|
| 1772 | + $schema = file_get_contents($schema); |
|
| 1773 | 1773 | break; |
| 1774 | 1774 | case 'string': |
| 1775 | 1775 | default: |
| 1776 | - if( !is_string( $schema ) ) { |
|
| 1776 | + if (!is_string($schema)) { |
|
| 1777 | 1777 | return FALSE; |
| 1778 | 1778 | } |
| 1779 | 1779 | } |
| 1780 | 1780 | |
| 1781 | - $arguments = array ( |
|
| 1781 | + $arguments = array( |
|
| 1782 | 1782 | '/_xml' => $schema, |
| 1783 | - '/_xsl' => file_get_contents( $xsl_file ) |
|
| 1783 | + '/_xsl' => file_get_contents($xsl_file) |
|
| 1784 | 1784 | ); |
| 1785 | 1785 | |
| 1786 | 1786 | // create an XSLT processor |
| 1787 | - $xh = xslt_create (); |
|
| 1787 | + $xh = xslt_create(); |
|
| 1788 | 1788 | |
| 1789 | 1789 | // set error handler |
| 1790 | - xslt_set_error_handler ($xh, array (&$this, 'xslt_error_handler')); |
|
| 1790 | + xslt_set_error_handler($xh, array(&$this, 'xslt_error_handler')); |
|
| 1791 | 1791 | |
| 1792 | 1792 | // process the schema |
| 1793 | - $result = xslt_process ($xh, 'arg:/_xml', 'arg:/_xsl', NULL, $arguments); |
|
| 1793 | + $result = xslt_process($xh, 'arg:/_xml', 'arg:/_xsl', NULL, $arguments); |
|
| 1794 | 1794 | |
| 1795 | - xslt_free ($xh); |
|
| 1795 | + xslt_free($xh); |
|
| 1796 | 1796 | |
| 1797 | 1797 | return $result; |
| 1798 | 1798 | } |
@@ -1807,17 +1807,17 @@ discard block |
||
| 1807 | 1807 | * |
| 1808 | 1808 | * @access private |
| 1809 | 1809 | */ |
| 1810 | - function xslt_error_handler( $parser, $errno, $level, $fields ) { |
|
| 1811 | - if( is_array( $fields ) ) { |
|
| 1810 | + function xslt_error_handler($parser, $errno, $level, $fields) { |
|
| 1811 | + if (is_array($fields)) { |
|
| 1812 | 1812 | $msg = array( |
| 1813 | - 'Message Type' => ucfirst( $fields['msgtype'] ), |
|
| 1813 | + 'Message Type' => ucfirst($fields['msgtype']), |
|
| 1814 | 1814 | 'Message Code' => $fields['code'], |
| 1815 | 1815 | 'Message' => $fields['msg'], |
| 1816 | 1816 | 'Error Number' => $errno, |
| 1817 | 1817 | 'Level' => $level |
| 1818 | 1818 | ); |
| 1819 | 1819 | |
| 1820 | - switch( $fields['URI'] ) { |
|
| 1820 | + switch ($fields['URI']) { |
|
| 1821 | 1821 | case 'arg:/_xml': |
| 1822 | 1822 | $msg['Input'] = 'XML'; |
| 1823 | 1823 | break; |
@@ -1834,20 +1834,20 @@ discard block |
||
| 1834 | 1834 | 'Message Type' => 'Error', |
| 1835 | 1835 | 'Error Number' => $errno, |
| 1836 | 1836 | 'Level' => $level, |
| 1837 | - 'Fields' => var_export( $fields, TRUE ) |
|
| 1837 | + 'Fields' => var_export($fields, TRUE) |
|
| 1838 | 1838 | ); |
| 1839 | 1839 | } |
| 1840 | 1840 | |
| 1841 | - $error_details = $msg['Message Type'] . ' in XSLT Transformation' . "\n" |
|
| 1842 | - . '<table>' . "\n"; |
|
| 1841 | + $error_details = $msg['Message Type'].' in XSLT Transformation'."\n" |
|
| 1842 | + . '<table>'."\n"; |
|
| 1843 | 1843 | |
| 1844 | - foreach( $msg as $label => $details ) { |
|
| 1845 | - $error_details .= '<tr><td><b>' . $label . ': </b></td><td>' . htmlentities( $details ) . '</td></tr>' . "\n"; |
|
| 1844 | + foreach ($msg as $label => $details) { |
|
| 1845 | + $error_details .= '<tr><td><b>'.$label.': </b></td><td>'.htmlentities($details).'</td></tr>'."\n"; |
|
| 1846 | 1846 | } |
| 1847 | 1847 | |
| 1848 | 1848 | $error_details .= '</table>'; |
| 1849 | 1849 | |
| 1850 | - trigger_error( $error_details, E_USER_ERROR ); |
|
| 1850 | + trigger_error($error_details, E_USER_ERROR); |
|
| 1851 | 1851 | } |
| 1852 | 1852 | |
| 1853 | 1853 | /** |
@@ -1859,17 +1859,17 @@ discard block |
||
| 1859 | 1859 | * @param string $filename AXMLS schema file |
| 1860 | 1860 | * @return string Schema version number or FALSE on error |
| 1861 | 1861 | */ |
| 1862 | - function SchemaFileVersion( $filename ) { |
|
| 1862 | + function SchemaFileVersion($filename) { |
|
| 1863 | 1863 | // Open the file |
| 1864 | - if( !($fp = fopen( $filename, 'r' )) ) { |
|
| 1864 | + if (!($fp = fopen($filename, 'r'))) { |
|
| 1865 | 1865 | // die( 'Unable to open file' ); |
| 1866 | 1866 | return FALSE; |
| 1867 | 1867 | } |
| 1868 | 1868 | |
| 1869 | 1869 | // Process the file |
| 1870 | - while( $data = fread( $fp, 4096 ) ) { |
|
| 1871 | - if( preg_match( $this->versionRegex, $data, $matches ) ) { |
|
| 1872 | - return !empty( $matches[2] ) ? $matches[2] : XMLS_DEFAULT_SCHEMA_VERSION; |
|
| 1870 | + while ($data = fread($fp, 4096)) { |
|
| 1871 | + if (preg_match($this->versionRegex, $data, $matches)) { |
|
| 1872 | + return !empty($matches[2]) ? $matches[2] : XMLS_DEFAULT_SCHEMA_VERSION; |
|
| 1873 | 1873 | } |
| 1874 | 1874 | } |
| 1875 | 1875 | |
@@ -1885,13 +1885,13 @@ discard block |
||
| 1885 | 1885 | * @param string $xmlstring XML schema string |
| 1886 | 1886 | * @return string Schema version number or FALSE on error |
| 1887 | 1887 | */ |
| 1888 | - function SchemaStringVersion( $xmlstring ) { |
|
| 1889 | - if( !is_string( $xmlstring ) OR empty( $xmlstring ) ) { |
|
| 1888 | + function SchemaStringVersion($xmlstring) { |
|
| 1889 | + if (!is_string($xmlstring) OR empty($xmlstring)) { |
|
| 1890 | 1890 | return FALSE; |
| 1891 | 1891 | } |
| 1892 | 1892 | |
| 1893 | - if( preg_match( $this->versionRegex, $xmlstring, $matches ) ) { |
|
| 1894 | - return !empty( $matches[2] ) ? $matches[2] : XMLS_DEFAULT_SCHEMA_VERSION; |
|
| 1893 | + if (preg_match($this->versionRegex, $xmlstring, $matches)) { |
|
| 1894 | + return !empty($matches[2]) ? $matches[2] : XMLS_DEFAULT_SCHEMA_VERSION; |
|
| 1895 | 1895 | } |
| 1896 | 1896 | |
| 1897 | 1897 | return FALSE; |
@@ -1907,98 +1907,98 @@ discard block |
||
| 1907 | 1907 | * @param boolean $data Include data in schema dump |
| 1908 | 1908 | * @return string Generated XML schema |
| 1909 | 1909 | */ |
| 1910 | - function ExtractSchema( $data = FALSE ) { |
|
| 1911 | - $old_mode = $this->db->SetFetchMode( ADODB_FETCH_NUM ); |
|
| 1910 | + function ExtractSchema($data = FALSE) { |
|
| 1911 | + $old_mode = $this->db->SetFetchMode(ADODB_FETCH_NUM); |
|
| 1912 | 1912 | |
| 1913 | - $schema = '<?xml version="1.0"?>' . "\n" |
|
| 1914 | - . '<schema version="' . $this->schemaVersion . '">' . "\n"; |
|
| 1913 | + $schema = '<?xml version="1.0"?>'."\n" |
|
| 1914 | + . '<schema version="'.$this->schemaVersion.'">'."\n"; |
|
| 1915 | 1915 | |
| 1916 | - if( is_array( $tables = $this->db->MetaTables( 'TABLES' ) ) ) { |
|
| 1917 | - foreach( $tables as $table ) { |
|
| 1918 | - $schema .= ' <table name="' . $table . '">' . "\n"; |
|
| 1916 | + if (is_array($tables = $this->db->MetaTables('TABLES'))) { |
|
| 1917 | + foreach ($tables as $table) { |
|
| 1918 | + $schema .= ' <table name="'.$table.'">'."\n"; |
|
| 1919 | 1919 | |
| 1920 | 1920 | // grab details from database |
| 1921 | - $rs = $this->db->Execute( 'SELECT * FROM ' . $table . ' WHERE 1=1' ); |
|
| 1922 | - $fields = $this->db->MetaColumns( $table ); |
|
| 1923 | - $indexes = $this->db->MetaIndexes( $table ); |
|
| 1921 | + $rs = $this->db->Execute('SELECT * FROM '.$table.' WHERE 1=1'); |
|
| 1922 | + $fields = $this->db->MetaColumns($table); |
|
| 1923 | + $indexes = $this->db->MetaIndexes($table); |
|
| 1924 | 1924 | |
| 1925 | - if( is_array( $fields ) ) { |
|
| 1926 | - foreach( $fields as $details ) { |
|
| 1925 | + if (is_array($fields)) { |
|
| 1926 | + foreach ($fields as $details) { |
|
| 1927 | 1927 | $extra = ''; |
| 1928 | 1928 | $content = array(); |
| 1929 | 1929 | |
| 1930 | - if( $details->max_length > 0 ) { |
|
| 1931 | - $extra .= ' size="' . $details->max_length . '"'; |
|
| 1930 | + if ($details->max_length > 0) { |
|
| 1931 | + $extra .= ' size="'.$details->max_length.'"'; |
|
| 1932 | 1932 | } |
| 1933 | 1933 | |
| 1934 | - if( $details->primary_key ) { |
|
| 1934 | + if ($details->primary_key) { |
|
| 1935 | 1935 | $content[] = '<KEY/>'; |
| 1936 | - } elseif( $details->not_null ) { |
|
| 1936 | + } elseif ($details->not_null) { |
|
| 1937 | 1937 | $content[] = '<NOTNULL/>'; |
| 1938 | 1938 | } |
| 1939 | 1939 | |
| 1940 | - if( $details->has_default ) { |
|
| 1941 | - $content[] = '<DEFAULT value="' . $details->default_value . '"/>'; |
|
| 1940 | + if ($details->has_default) { |
|
| 1941 | + $content[] = '<DEFAULT value="'.$details->default_value.'"/>'; |
|
| 1942 | 1942 | } |
| 1943 | 1943 | |
| 1944 | - if( $details->auto_increment ) { |
|
| 1944 | + if ($details->auto_increment) { |
|
| 1945 | 1945 | $content[] = '<AUTOINCREMENT/>'; |
| 1946 | 1946 | } |
| 1947 | 1947 | |
| 1948 | 1948 | // this stops the creation of 'R' columns, |
| 1949 | 1949 | // AUTOINCREMENT is used to create auto columns |
| 1950 | 1950 | $details->primary_key = 0; |
| 1951 | - $type = $rs->MetaType( $details ); |
|
| 1951 | + $type = $rs->MetaType($details); |
|
| 1952 | 1952 | |
| 1953 | - $schema .= ' <field name="' . $details->name . '" type="' . $type . '"' . $extra . '>'; |
|
| 1953 | + $schema .= ' <field name="'.$details->name.'" type="'.$type.'"'.$extra.'>'; |
|
| 1954 | 1954 | |
| 1955 | - if( !empty( $content ) ) { |
|
| 1956 | - $schema .= "\n " . implode( "\n ", $content ) . "\n "; |
|
| 1955 | + if (!empty($content)) { |
|
| 1956 | + $schema .= "\n ".implode("\n ", $content)."\n "; |
|
| 1957 | 1957 | } |
| 1958 | 1958 | |
| 1959 | - $schema .= '</field>' . "\n"; |
|
| 1959 | + $schema .= '</field>'."\n"; |
|
| 1960 | 1960 | } |
| 1961 | 1961 | } |
| 1962 | 1962 | |
| 1963 | - if( is_array( $indexes ) ) { |
|
| 1964 | - foreach( $indexes as $index => $details ) { |
|
| 1965 | - $schema .= ' <index name="' . $index . '">' . "\n"; |
|
| 1963 | + if (is_array($indexes)) { |
|
| 1964 | + foreach ($indexes as $index => $details) { |
|
| 1965 | + $schema .= ' <index name="'.$index.'">'."\n"; |
|
| 1966 | 1966 | |
| 1967 | - if( $details['unique'] ) { |
|
| 1968 | - $schema .= ' <UNIQUE/>' . "\n"; |
|
| 1967 | + if ($details['unique']) { |
|
| 1968 | + $schema .= ' <UNIQUE/>'."\n"; |
|
| 1969 | 1969 | } |
| 1970 | 1970 | |
| 1971 | - foreach( $details['columns'] as $column ) { |
|
| 1972 | - $schema .= ' <col>' . $column . '</col>' . "\n"; |
|
| 1971 | + foreach ($details['columns'] as $column) { |
|
| 1972 | + $schema .= ' <col>'.$column.'</col>'."\n"; |
|
| 1973 | 1973 | } |
| 1974 | 1974 | |
| 1975 | - $schema .= ' </index>' . "\n"; |
|
| 1975 | + $schema .= ' </index>'."\n"; |
|
| 1976 | 1976 | } |
| 1977 | 1977 | } |
| 1978 | 1978 | |
| 1979 | - if( $data ) { |
|
| 1980 | - $rs = $this->db->Execute( 'SELECT * FROM ' . $table ); |
|
| 1979 | + if ($data) { |
|
| 1980 | + $rs = $this->db->Execute('SELECT * FROM '.$table); |
|
| 1981 | 1981 | |
| 1982 | - if( is_object( $rs ) ) { |
|
| 1983 | - $schema .= ' <data>' . "\n"; |
|
| 1982 | + if (is_object($rs)) { |
|
| 1983 | + $schema .= ' <data>'."\n"; |
|
| 1984 | 1984 | |
| 1985 | - while( $row = $rs->FetchRow() ) { |
|
| 1986 | - foreach( $row as $key => $val ) { |
|
| 1985 | + while ($row = $rs->FetchRow()) { |
|
| 1986 | + foreach ($row as $key => $val) { |
|
| 1987 | 1987 | $row[$key] = htmlentities($val); |
| 1988 | 1988 | } |
| 1989 | 1989 | |
| 1990 | - $schema .= ' <row><f>' . implode( '</f><f>', $row ) . '</f></row>' . "\n"; |
|
| 1990 | + $schema .= ' <row><f>'.implode('</f><f>', $row).'</f></row>'."\n"; |
|
| 1991 | 1991 | } |
| 1992 | 1992 | |
| 1993 | - $schema .= ' </data>' . "\n"; |
|
| 1993 | + $schema .= ' </data>'."\n"; |
|
| 1994 | 1994 | } |
| 1995 | 1995 | } |
| 1996 | 1996 | |
| 1997 | - $schema .= ' </table>' . "\n"; |
|
| 1997 | + $schema .= ' </table>'."\n"; |
|
| 1998 | 1998 | } |
| 1999 | 1999 | } |
| 2000 | 2000 | |
| 2001 | - $this->db->SetFetchMode( $old_mode ); |
|
| 2001 | + $this->db->SetFetchMode($old_mode); |
|
| 2002 | 2002 | |
| 2003 | 2003 | $schema .= '</schema>'; |
| 2004 | 2004 | return $schema; |
@@ -2014,27 +2014,27 @@ discard block |
||
| 2014 | 2014 | * @param boolean $underscore If TRUE, automatically append an underscore character to the prefix. |
| 2015 | 2015 | * @return boolean TRUE if successful, else FALSE |
| 2016 | 2016 | */ |
| 2017 | - function SetPrefix( $prefix = '', $underscore = TRUE ) { |
|
| 2018 | - switch( TRUE ) { |
|
| 2017 | + function SetPrefix($prefix = '', $underscore = TRUE) { |
|
| 2018 | + switch (TRUE) { |
|
| 2019 | 2019 | // clear prefix |
| 2020 | - case empty( $prefix ): |
|
| 2021 | - logMsg( 'Cleared prefix' ); |
|
| 2020 | + case empty($prefix): |
|
| 2021 | + logMsg('Cleared prefix'); |
|
| 2022 | 2022 | $this->objectPrefix = ''; |
| 2023 | 2023 | return TRUE; |
| 2024 | 2024 | // prefix too long |
| 2025 | - case strlen( $prefix ) > XMLS_PREFIX_MAXLEN: |
|
| 2025 | + case strlen($prefix) > XMLS_PREFIX_MAXLEN: |
|
| 2026 | 2026 | // prefix contains invalid characters |
| 2027 | - case !preg_match( '/^[a-z][a-z0-9_]+$/i', $prefix ): |
|
| 2028 | - logMsg( 'Invalid prefix: ' . $prefix ); |
|
| 2027 | + case !preg_match('/^[a-z][a-z0-9_]+$/i', $prefix): |
|
| 2028 | + logMsg('Invalid prefix: '.$prefix); |
|
| 2029 | 2029 | return FALSE; |
| 2030 | 2030 | } |
| 2031 | 2031 | |
| 2032 | - if( $underscore AND substr( $prefix, -1 ) != '_' ) { |
|
| 2032 | + if ($underscore AND substr($prefix, -1) != '_') { |
|
| 2033 | 2033 | $prefix .= '_'; |
| 2034 | 2034 | } |
| 2035 | 2035 | |
| 2036 | 2036 | // prefix valid |
| 2037 | - logMsg( 'Set prefix: ' . $prefix ); |
|
| 2037 | + logMsg('Set prefix: '.$prefix); |
|
| 2038 | 2038 | $this->objectPrefix = $prefix; |
| 2039 | 2039 | return TRUE; |
| 2040 | 2040 | } |
@@ -2047,12 +2047,12 @@ discard block |
||
| 2047 | 2047 | * |
| 2048 | 2048 | * @access private |
| 2049 | 2049 | */ |
| 2050 | - function prefix( $name = '' ) { |
|
| 2050 | + function prefix($name = '') { |
|
| 2051 | 2051 | // if prefix is set |
| 2052 | - if( !empty( $this->objectPrefix ) ) { |
|
| 2052 | + if (!empty($this->objectPrefix)) { |
|
| 2053 | 2053 | // Prepend the object prefix to the table name |
| 2054 | 2054 | // prepend after quote if used |
| 2055 | - return preg_replace( '/^(`?)(.+)$/', '$1' . $this->objectPrefix . '$2', $name ); |
|
| 2055 | + return preg_replace('/^(`?)(.+)$/', '$1'.$this->objectPrefix.'$2', $name); |
|
| 2056 | 2056 | } |
| 2057 | 2057 | |
| 2058 | 2058 | // No prefix set. Use name provided. |
@@ -2067,14 +2067,14 @@ discard block |
||
| 2067 | 2067 | * |
| 2068 | 2068 | * @access private |
| 2069 | 2069 | */ |
| 2070 | - function supportedPlatform( $platform = NULL ) { |
|
| 2071 | - $regex = '/^(\w*\|)*' . $this->db->databaseType . '(\|\w*)*$/'; |
|
| 2070 | + function supportedPlatform($platform = NULL) { |
|
| 2071 | + $regex = '/^(\w*\|)*'.$this->db->databaseType.'(\|\w*)*$/'; |
|
| 2072 | 2072 | |
| 2073 | - if( !isset( $platform ) OR preg_match( $regex, $platform ) ) { |
|
| 2074 | - logMsg( "Platform $platform is supported" ); |
|
| 2073 | + if (!isset($platform) OR preg_match($regex, $platform)) { |
|
| 2074 | + logMsg("Platform $platform is supported"); |
|
| 2075 | 2075 | return TRUE; |
| 2076 | 2076 | } else { |
| 2077 | - logMsg( "Platform $platform is NOT supported" ); |
|
| 2077 | + logMsg("Platform $platform is NOT supported"); |
|
| 2078 | 2078 | return FALSE; |
| 2079 | 2079 | } |
| 2080 | 2080 | } |
@@ -2096,28 +2096,28 @@ discard block |
||
| 2096 | 2096 | * |
| 2097 | 2097 | * @access private |
| 2098 | 2098 | */ |
| 2099 | - function addSQL( $sql = NULL ) { |
|
| 2100 | - if( is_array( $sql ) ) { |
|
| 2101 | - foreach( $sql as $line ) { |
|
| 2102 | - $this->addSQL( $line ); |
|
| 2099 | + function addSQL($sql = NULL) { |
|
| 2100 | + if (is_array($sql)) { |
|
| 2101 | + foreach ($sql as $line) { |
|
| 2102 | + $this->addSQL($line); |
|
| 2103 | 2103 | } |
| 2104 | 2104 | |
| 2105 | 2105 | return TRUE; |
| 2106 | 2106 | } |
| 2107 | 2107 | |
| 2108 | - if( is_string( $sql ) ) { |
|
| 2108 | + if (is_string($sql)) { |
|
| 2109 | 2109 | $this->sqlArray[] = $sql; |
| 2110 | 2110 | |
| 2111 | 2111 | // if executeInline is enabled, and either no errors have occurred or continueOnError is enabled, execute SQL. |
| 2112 | - if( $this->ExecuteInline() && ( $this->success == 2 || $this->ContinueOnError() ) ) { |
|
| 2112 | + if ($this->ExecuteInline() && ($this->success == 2 || $this->ContinueOnError())) { |
|
| 2113 | 2113 | $saved = $this->db->debug; |
| 2114 | 2114 | $this->db->debug = $this->debug; |
| 2115 | - $ok = $this->db->Execute( $sql ); |
|
| 2115 | + $ok = $this->db->Execute($sql); |
|
| 2116 | 2116 | $this->db->debug = $saved; |
| 2117 | 2117 | |
| 2118 | - if( !$ok ) { |
|
| 2119 | - if( $this->debug ) { |
|
| 2120 | - ADOConnection::outp( $this->db->ErrorMsg() ); |
|
| 2118 | + if (!$ok) { |
|
| 2119 | + if ($this->debug) { |
|
| 2120 | + ADOConnection::outp($this->db->ErrorMsg()); |
|
| 2121 | 2121 | } |
| 2122 | 2122 | |
| 2123 | 2123 | $this->success = 1; |
@@ -2138,21 +2138,21 @@ discard block |
||
| 2138 | 2138 | * |
| 2139 | 2139 | * @access private |
| 2140 | 2140 | */ |
| 2141 | - function getSQL( $format = NULL, $sqlArray = NULL ) { |
|
| 2142 | - if( !is_array( $sqlArray ) ) { |
|
| 2141 | + function getSQL($format = NULL, $sqlArray = NULL) { |
|
| 2142 | + if (!is_array($sqlArray)) { |
|
| 2143 | 2143 | $sqlArray = $this->sqlArray; |
| 2144 | 2144 | } |
| 2145 | 2145 | |
| 2146 | - if( !is_array( $sqlArray ) ) { |
|
| 2146 | + if (!is_array($sqlArray)) { |
|
| 2147 | 2147 | return FALSE; |
| 2148 | 2148 | } |
| 2149 | 2149 | |
| 2150 | - switch( strtolower( $format ) ) { |
|
| 2150 | + switch (strtolower($format)) { |
|
| 2151 | 2151 | case 'string': |
| 2152 | 2152 | case 'text': |
| 2153 | - return !empty( $sqlArray ) ? implode( ";\n\n", $sqlArray ) . ';' : ''; |
|
| 2153 | + return !empty($sqlArray) ? implode(";\n\n", $sqlArray).';' : ''; |
|
| 2154 | 2154 | case'html': |
| 2155 | - return !empty( $sqlArray ) ? nl2br( htmlentities( implode( ";\n\n", $sqlArray ) . ';' ) ) : ''; |
|
| 2155 | + return !empty($sqlArray) ? nl2br(htmlentities(implode(";\n\n", $sqlArray).';')) : ''; |
|
| 2156 | 2156 | } |
| 2157 | 2157 | |
| 2158 | 2158 | return $this->sqlArray; |
@@ -2165,8 +2165,8 @@ discard block |
||
| 2165 | 2165 | * @deprecated adoSchema now cleans up automatically. |
| 2166 | 2166 | */ |
| 2167 | 2167 | function Destroy() { |
| 2168 | - set_magic_quotes_runtime( $this->mgq ); |
|
| 2169 | - unset( $this ); |
|
| 2168 | + set_magic_quotes_runtime($this->mgq); |
|
| 2169 | + unset($this); |
|
| 2170 | 2170 | } |
| 2171 | 2171 | } |
| 2172 | 2172 | |
@@ -2175,19 +2175,19 @@ discard block |
||
| 2175 | 2175 | * |
| 2176 | 2176 | * @access private |
| 2177 | 2177 | */ |
| 2178 | -function logMsg( $msg, $title = NULL, $force = FALSE ) { |
|
| 2179 | - if( XMLS_DEBUG or $force ) { |
|
| 2178 | +function logMsg($msg, $title = NULL, $force = FALSE) { |
|
| 2179 | + if (XMLS_DEBUG or $force) { |
|
| 2180 | 2180 | echo '<pre>'; |
| 2181 | 2181 | |
| 2182 | - if( isset( $title ) ) { |
|
| 2183 | - echo '<h3>' . htmlentities( $title ) . '</h3>'; |
|
| 2182 | + if (isset($title)) { |
|
| 2183 | + echo '<h3>'.htmlentities($title).'</h3>'; |
|
| 2184 | 2184 | } |
| 2185 | 2185 | |
| 2186 | - if( is_object( $this ) ) { |
|
| 2187 | - echo '[' . get_class( $this ) . '] '; |
|
| 2186 | + if (is_object($this)) { |
|
| 2187 | + echo '['.get_class($this).'] '; |
|
| 2188 | 2188 | } |
| 2189 | 2189 | |
| 2190 | - print_r( $msg ); |
|
| 2190 | + print_r($msg); |
|
| 2191 | 2191 | |
| 2192 | 2192 | echo '</pre>'; |
| 2193 | 2193 | } |
@@ -21,63 +21,72 @@ discard block |
||
| 21 | 21 | /** |
| 22 | 22 | * Debug on or off |
| 23 | 23 | */ |
| 24 | -if( !defined( 'XMLS_DEBUG' ) ) { |
|
| 24 | +if( !defined( 'XMLS_DEBUG' ) ) |
|
| 25 | +{ |
|
| 25 | 26 | define( 'XMLS_DEBUG', FALSE ); |
| 26 | 27 | } |
| 27 | 28 | |
| 28 | 29 | /** |
| 29 | 30 | * Default prefix key |
| 30 | 31 | */ |
| 31 | -if( !defined( 'XMLS_PREFIX' ) ) { |
|
| 32 | +if( !defined( 'XMLS_PREFIX' ) ) |
|
| 33 | +{ |
|
| 32 | 34 | define( 'XMLS_PREFIX', '%%P' ); |
| 33 | 35 | } |
| 34 | 36 | |
| 35 | 37 | /** |
| 36 | 38 | * Maximum length allowed for object prefix |
| 37 | 39 | */ |
| 38 | -if( !defined( 'XMLS_PREFIX_MAXLEN' ) ) { |
|
| 40 | +if( !defined( 'XMLS_PREFIX_MAXLEN' ) ) |
|
| 41 | +{ |
|
| 39 | 42 | define( 'XMLS_PREFIX_MAXLEN', 10 ); |
| 40 | 43 | } |
| 41 | 44 | |
| 42 | 45 | /** |
| 43 | 46 | * Execute SQL inline as it is generated |
| 44 | 47 | */ |
| 45 | -if( !defined( 'XMLS_EXECUTE_INLINE' ) ) { |
|
| 48 | +if( !defined( 'XMLS_EXECUTE_INLINE' ) ) |
|
| 49 | +{ |
|
| 46 | 50 | define( 'XMLS_EXECUTE_INLINE', FALSE ); |
| 47 | 51 | } |
| 48 | 52 | |
| 49 | 53 | /** |
| 50 | 54 | * Continue SQL Execution if an error occurs? |
| 51 | 55 | */ |
| 52 | -if( !defined( 'XMLS_CONTINUE_ON_ERROR' ) ) { |
|
| 56 | +if( !defined( 'XMLS_CONTINUE_ON_ERROR' ) ) |
|
| 57 | +{ |
|
| 53 | 58 | define( 'XMLS_CONTINUE_ON_ERROR', FALSE ); |
| 54 | 59 | } |
| 55 | 60 | |
| 56 | 61 | /** |
| 57 | 62 | * Current Schema Version |
| 58 | 63 | */ |
| 59 | -if( !defined( 'XMLS_SCHEMA_VERSION' ) ) { |
|
| 64 | +if( !defined( 'XMLS_SCHEMA_VERSION' ) ) |
|
| 65 | +{ |
|
| 60 | 66 | define( 'XMLS_SCHEMA_VERSION', '0.2' ); |
| 61 | 67 | } |
| 62 | 68 | |
| 63 | 69 | /** |
| 64 | 70 | * Default Schema Version. Used for Schemas without an explicit version set. |
| 65 | 71 | */ |
| 66 | -if( !defined( 'XMLS_DEFAULT_SCHEMA_VERSION' ) ) { |
|
| 72 | +if( !defined( 'XMLS_DEFAULT_SCHEMA_VERSION' ) ) |
|
| 73 | +{ |
|
| 67 | 74 | define( 'XMLS_DEFAULT_SCHEMA_VERSION', '0.1' ); |
| 68 | 75 | } |
| 69 | 76 | |
| 70 | 77 | /** |
| 71 | 78 | * Default Schema Version. Used for Schemas without an explicit version set. |
| 72 | 79 | */ |
| 73 | -if( !defined( 'XMLS_DEFAULT_UPGRADE_METHOD' ) ) { |
|
| 80 | +if( !defined( 'XMLS_DEFAULT_UPGRADE_METHOD' ) ) |
|
| 81 | +{ |
|
| 74 | 82 | define( 'XMLS_DEFAULT_UPGRADE_METHOD', 'ALTER' ); |
| 75 | 83 | } |
| 76 | 84 | |
| 77 | 85 | /** |
| 78 | 86 | * Include the main ADODB library |
| 79 | 87 | */ |
| 80 | -if( !defined( '_ADODB_LAYER' ) ) { |
|
| 88 | +if( !defined( '_ADODB_LAYER' ) ) |
|
| 89 | +{ |
|
| 81 | 90 | require( 'adodb.inc.php' ); |
| 82 | 91 | require( 'adodb-datadict.inc.php' ); |
| 83 | 92 | } |
@@ -89,7 +98,8 @@ discard block |
||
| 89 | 98 | * @package axmls |
| 90 | 99 | * @access private |
| 91 | 100 | */ |
| 92 | -class dbObject { |
|
| 101 | +class dbObject |
|
| 102 | +{ |
|
| 93 | 103 | |
| 94 | 104 | /** |
| 95 | 105 | * var object Parent |
@@ -104,7 +114,8 @@ discard block |
||
| 104 | 114 | /** |
| 105 | 115 | * NOP |
| 106 | 116 | */ |
| 107 | - function dbObject( &$parent, $attributes = NULL ) { |
|
| 117 | + function dbObject( &$parent, $attributes = NULL ) |
|
| 118 | + { |
|
| 108 | 119 | $this->parent =& $parent; |
| 109 | 120 | } |
| 110 | 121 | |
@@ -113,7 +124,8 @@ discard block |
||
| 113 | 124 | * |
| 114 | 125 | * @access private |
| 115 | 126 | */ |
| 116 | - function _tag_open( &$parser, $tag, $attributes ) { |
|
| 127 | + function _tag_open( &$parser, $tag, $attributes ) |
|
| 128 | + { |
|
| 117 | 129 | |
| 118 | 130 | } |
| 119 | 131 | |
@@ -122,7 +134,8 @@ discard block |
||
| 122 | 134 | * |
| 123 | 135 | * @access private |
| 124 | 136 | */ |
| 125 | - function _tag_cdata( &$parser, $cdata ) { |
|
| 137 | + function _tag_cdata( &$parser, $cdata ) |
|
| 138 | + { |
|
| 126 | 139 | |
| 127 | 140 | } |
| 128 | 141 | |
@@ -131,18 +144,21 @@ discard block |
||
| 131 | 144 | * |
| 132 | 145 | * @access private |
| 133 | 146 | */ |
| 134 | - function _tag_close( &$parser, $tag ) { |
|
| 147 | + function _tag_close( &$parser, $tag ) |
|
| 148 | + { |
|
| 135 | 149 | |
| 136 | 150 | } |
| 137 | 151 | |
| 138 | - function create() { |
|
| 152 | + function create() |
|
| 153 | + { |
|
| 139 | 154 | return array(); |
| 140 | 155 | } |
| 141 | 156 | |
| 142 | 157 | /** |
| 143 | 158 | * Destroys the object |
| 144 | 159 | */ |
| 145 | - function destroy() { |
|
| 160 | + function destroy() |
|
| 161 | + { |
|
| 146 | 162 | unset( $this ); |
| 147 | 163 | } |
| 148 | 164 | |
@@ -153,7 +169,8 @@ discard block |
||
| 153 | 169 | * @param string $platform RDBMS platform name (from ADODB platform list). |
| 154 | 170 | * @return boolean TRUE if RDBMS is supported; otherwise returns FALSE. |
| 155 | 171 | */ |
| 156 | - function supportedPlatform( $platform = NULL ) { |
|
| 172 | + function supportedPlatform( $platform = NULL ) |
|
| 173 | + { |
|
| 157 | 174 | return is_object( $this->parent ) ? $this->parent->supportedPlatform( $platform ) : TRUE; |
| 158 | 175 | } |
| 159 | 176 | |
@@ -163,7 +180,8 @@ discard block |
||
| 163 | 180 | * @param string $name Prefix string. |
| 164 | 181 | * @return string Prefix. |
| 165 | 182 | */ |
| 166 | - function prefix( $name = '' ) { |
|
| 183 | + function prefix( $name = '' ) |
|
| 184 | + { |
|
| 167 | 185 | return is_object( $this->parent ) ? $this->parent->prefix( $name ) : $name; |
| 168 | 186 | } |
| 169 | 187 | |
@@ -173,7 +191,8 @@ discard block |
||
| 173 | 191 | * @param string $field Field. |
| 174 | 192 | * @return string Field ID. |
| 175 | 193 | */ |
| 176 | - function FieldID( $field ) { |
|
| 194 | + function FieldID( $field ) |
|
| 195 | + { |
|
| 177 | 196 | return strtoupper( preg_replace( '/^`(.+)`$/', '$1', $field ) ); |
| 178 | 197 | } |
| 179 | 198 | } |
@@ -189,7 +208,8 @@ discard block |
||
| 189 | 208 | * @package axmls |
| 190 | 209 | * @access private |
| 191 | 210 | */ |
| 192 | -class dbTable extends dbObject { |
|
| 211 | +class dbTable extends dbObject |
|
| 212 | +{ |
|
| 193 | 213 | |
| 194 | 214 | /** |
| 195 | 215 | * @var string Table name |
@@ -234,7 +254,8 @@ discard block |
||
| 234 | 254 | * @param string $prefix DB Object prefix |
| 235 | 255 | * @param array $attributes Array of table attributes. |
| 236 | 256 | */ |
| 237 | - function dbTable( &$parent, $attributes = NULL ) { |
|
| 257 | + function dbTable( &$parent, $attributes = NULL ) |
|
| 258 | + { |
|
| 238 | 259 | $this->parent =& $parent; |
| 239 | 260 | $this->name = $this->prefix($attributes['NAME']); |
| 240 | 261 | } |
@@ -245,17 +266,21 @@ discard block |
||
| 245 | 266 | * |
| 246 | 267 | * @access private |
| 247 | 268 | */ |
| 248 | - function _tag_open( &$parser, $tag, $attributes ) { |
|
| 269 | + function _tag_open( &$parser, $tag, $attributes ) |
|
| 270 | + { |
|
| 249 | 271 | $this->currentElement = strtoupper( $tag ); |
| 250 | 272 | |
| 251 | - switch( $this->currentElement ) { |
|
| 273 | + switch( $this->currentElement ) |
|
| 274 | + { |
|
| 252 | 275 | case 'INDEX': |
| 253 | - if( !isset( $attributes['PLATFORM'] ) OR $this->supportedPlatform( $attributes['PLATFORM'] ) ) { |
|
| 276 | + if( !isset( $attributes['PLATFORM'] ) OR $this->supportedPlatform( $attributes['PLATFORM'] ) ) |
|
| 277 | + { |
|
| 254 | 278 | xml_set_object( $parser, $this->addIndex( $attributes ) ); |
| 255 | 279 | } |
| 256 | 280 | break; |
| 257 | 281 | case 'DATA': |
| 258 | - if( !isset( $attributes['PLATFORM'] ) OR $this->supportedPlatform( $attributes['PLATFORM'] ) ) { |
|
| 282 | + if( !isset( $attributes['PLATFORM'] ) OR $this->supportedPlatform( $attributes['PLATFORM'] ) ) |
|
| 283 | + { |
|
| 259 | 284 | xml_set_object( $parser, $this->addData( $attributes ) ); |
| 260 | 285 | } |
| 261 | 286 | break; |
@@ -281,7 +306,8 @@ discard block |
||
| 281 | 306 | // Add a field option to the table object |
| 282 | 307 | |
| 283 | 308 | // Work around ADOdb datadict issue that misinterprets empty strings. |
| 284 | - if( $attributes['VALUE'] == '' ) { |
|
| 309 | + if( $attributes['VALUE'] == '' ) |
|
| 310 | + { |
|
| 285 | 311 | $attributes['VALUE'] = " '' "; |
| 286 | 312 | } |
| 287 | 313 | |
@@ -302,13 +328,18 @@ discard block |
||
| 302 | 328 | * |
| 303 | 329 | * @access private |
| 304 | 330 | */ |
| 305 | - function _tag_cdata( &$parser, $cdata ) { |
|
| 306 | - switch( $this->currentElement ) { |
|
| 331 | + function _tag_cdata( &$parser, $cdata ) |
|
| 332 | + { |
|
| 333 | + switch( $this->currentElement ) |
|
| 334 | + { |
|
| 307 | 335 | // Table constraint |
| 308 | 336 | case 'CONSTRAINT': |
| 309 | - if( isset( $this->current_field ) ) { |
|
| 337 | + if( isset( $this->current_field ) ) |
|
| 338 | + { |
|
| 310 | 339 | $this->addFieldOpt( $this->current_field, $this->currentElement, $cdata ); |
| 311 | - } else { |
|
| 340 | + } |
|
| 341 | + else |
|
| 342 | + { |
|
| 312 | 343 | $this->addTableOpt( $cdata ); |
| 313 | 344 | } |
| 314 | 345 | break; |
@@ -326,10 +357,12 @@ discard block |
||
| 326 | 357 | * |
| 327 | 358 | * @access private |
| 328 | 359 | */ |
| 329 | - function _tag_close( &$parser, $tag ) { |
|
| 360 | + function _tag_close( &$parser, $tag ) |
|
| 361 | + { |
|
| 330 | 362 | $this->currentElement = ''; |
| 331 | 363 | |
| 332 | - switch( strtoupper( $tag ) ) { |
|
| 364 | + switch( strtoupper( $tag ) ) |
|
| 365 | + { |
|
| 333 | 366 | case 'TABLE': |
| 334 | 367 | $this->parent->addSQL( $this->create( $this->parent ) ); |
| 335 | 368 | xml_set_object( $parser, $this->parent ); |
@@ -361,7 +394,8 @@ discard block |
||
| 361 | 394 | * @return object dbData object |
| 362 | 395 | */ |
| 363 | 396 | function &addData( $attributes ) { |
| 364 | - if( !isset( $this->data ) ) { |
|
| 397 | + if( !isset( $this->data ) ) |
|
| 398 | + { |
|
| 365 | 399 | $this->data = new dbData( $this, $attributes ); |
| 366 | 400 | } |
| 367 | 401 | return $this->data; |
@@ -396,7 +430,8 @@ discard block |
||
| 396 | 430 | * @param array $opts Field options array |
| 397 | 431 | * @return array Field specifier array |
| 398 | 432 | */ |
| 399 | - function addField( $name, $type, $size = NULL, $opts = NULL ) { |
|
| 433 | + function addField( $name, $type, $size = NULL, $opts = NULL ) |
|
| 434 | + { |
|
| 400 | 435 | $field_id = $this->FieldID( $name ); |
| 401 | 436 | |
| 402 | 437 | // Set the field index so we know where we are |
@@ -409,12 +444,14 @@ discard block |
||
| 409 | 444 | $this->fields[$field_id]['TYPE'] = $type; |
| 410 | 445 | |
| 411 | 446 | // Set the field size (optional) |
| 412 | - if( isset( $size ) ) { |
|
| 447 | + if( isset( $size ) ) |
|
| 448 | + { |
|
| 413 | 449 | $this->fields[$field_id]['SIZE'] = $size; |
| 414 | 450 | } |
| 415 | 451 | |
| 416 | 452 | // Set the field options |
| 417 | - if( isset( $opts ) ) { |
|
| 453 | + if( isset( $opts ) ) |
|
| 454 | + { |
|
| 418 | 455 | $this->fields[$field_id]['OPTS'][] = $opts; |
| 419 | 456 | } |
| 420 | 457 | } |
@@ -430,11 +467,15 @@ discard block |
||
| 430 | 467 | * @param mixed $value Field option value |
| 431 | 468 | * @return array Field specifier array |
| 432 | 469 | */ |
| 433 | - function addFieldOpt( $field, $opt, $value = NULL ) { |
|
| 434 | - if( !isset( $value ) ) { |
|
| 470 | + function addFieldOpt( $field, $opt, $value = NULL ) |
|
| 471 | + { |
|
| 472 | + if( !isset( $value ) ) |
|
| 473 | + { |
|
| 435 | 474 | $this->fields[$this->FieldID( $field )]['OPTS'][] = $opt; |
| 436 | 475 | // Add the option and value |
| 437 | - } else { |
|
| 476 | + } |
|
| 477 | + else |
|
| 478 | + { |
|
| 438 | 479 | $this->fields[$this->FieldID( $field )]['OPTS'][] = array( $opt => $value ); |
| 439 | 480 | } |
| 440 | 481 | } |
@@ -448,7 +489,8 @@ discard block |
||
| 448 | 489 | * @param string $opt Table option |
| 449 | 490 | * @return array Options |
| 450 | 491 | */ |
| 451 | - function addTableOpt( $opt ) { |
|
| 492 | + function addTableOpt( $opt ) |
|
| 493 | + { |
|
| 452 | 494 | $this->opts[] = $opt; |
| 453 | 495 | |
| 454 | 496 | return $this->opts; |
@@ -460,39 +502,50 @@ discard block |
||
| 460 | 502 | * @param object $xmls adoSchema object |
| 461 | 503 | * @return array Array containing table creation SQL |
| 462 | 504 | */ |
| 463 | - function create( &$xmls ) { |
|
| 505 | + function create( &$xmls ) |
|
| 506 | + { |
|
| 464 | 507 | $sql = array(); |
| 465 | 508 | |
| 466 | 509 | // drop any existing indexes |
| 467 | - if( is_array( $legacy_indexes = $xmls->dict->MetaIndexes( $this->name ) ) ) { |
|
| 468 | - foreach( $legacy_indexes as $index => $index_details ) { |
|
| 510 | + if( is_array( $legacy_indexes = $xmls->dict->MetaIndexes( $this->name ) ) ) |
|
| 511 | + { |
|
| 512 | + foreach( $legacy_indexes as $index => $index_details ) |
|
| 513 | + { |
|
| 469 | 514 | $sql[] = $xmls->dict->DropIndexSQL( $index, $this->name ); |
| 470 | 515 | } |
| 471 | 516 | } |
| 472 | 517 | |
| 473 | 518 | // remove fields to be dropped from table object |
| 474 | - foreach( $this->drop_field as $field ) { |
|
| 519 | + foreach( $this->drop_field as $field ) |
|
| 520 | + { |
|
| 475 | 521 | unset( $this->fields[$field] ); |
| 476 | 522 | } |
| 477 | 523 | |
| 478 | 524 | // if table exists |
| 479 | - if( is_array( $legacy_fields = $xmls->dict->MetaColumns( $this->name ) ) ) { |
|
| 525 | + if( is_array( $legacy_fields = $xmls->dict->MetaColumns( $this->name ) ) ) |
|
| 526 | + { |
|
| 480 | 527 | // drop table |
| 481 | - if( $this->drop_table ) { |
|
| 528 | + if( $this->drop_table ) |
|
| 529 | + { |
|
| 482 | 530 | $sql[] = $xmls->dict->DropTableSQL( $this->name ); |
| 483 | 531 | |
| 484 | 532 | return $sql; |
| 485 | 533 | } |
| 486 | 534 | |
| 487 | 535 | // drop any existing fields not in schema |
| 488 | - foreach( $legacy_fields as $field_id => $field ) { |
|
| 489 | - if( !isset( $this->fields[$field_id] ) ) { |
|
| 536 | + foreach( $legacy_fields as $field_id => $field ) |
|
| 537 | + { |
|
| 538 | + if( !isset( $this->fields[$field_id] ) ) |
|
| 539 | + { |
|
| 490 | 540 | $sql[] = $xmls->dict->DropColumnSQL( $this->name, '`'.$field->name.'`' ); |
| 491 | 541 | } |
| 492 | 542 | } |
| 493 | 543 | // if table doesn't exist |
| 494 | - } else { |
|
| 495 | - if( $this->drop_table ) { |
|
| 544 | + } |
|
| 545 | + else |
|
| 546 | + { |
|
| 547 | + if( $this->drop_table ) |
|
| 548 | + { |
|
| 496 | 549 | return $sql; |
| 497 | 550 | } |
| 498 | 551 | |
@@ -502,9 +555,11 @@ discard block |
||
| 502 | 555 | // Loop through the field specifier array, building the associative array for the field options |
| 503 | 556 | $fldarray = array(); |
| 504 | 557 | |
| 505 | - foreach( $this->fields as $field_id => $finfo ) { |
|
| 558 | + foreach( $this->fields as $field_id => $finfo ) |
|
| 559 | + { |
|
| 506 | 560 | // Set an empty size if it isn't supplied |
| 507 | - if( !isset( $finfo['SIZE'] ) ) { |
|
| 561 | + if( !isset( $finfo['SIZE'] ) ) |
|
| 562 | + { |
|
| 508 | 563 | $finfo['SIZE'] = ''; |
| 509 | 564 | } |
| 510 | 565 | |
@@ -516,29 +571,38 @@ discard block |
||
| 516 | 571 | ); |
| 517 | 572 | |
| 518 | 573 | // Loop through the options array and add the field options. |
| 519 | - if( isset( $finfo['OPTS'] ) ) { |
|
| 520 | - foreach( $finfo['OPTS'] as $opt ) { |
|
| 574 | + if( isset( $finfo['OPTS'] ) ) |
|
| 575 | + { |
|
| 576 | + foreach( $finfo['OPTS'] as $opt ) |
|
| 577 | + { |
|
| 521 | 578 | // Option has an argument. |
| 522 | - if( is_array( $opt ) ) { |
|
| 579 | + if( is_array( $opt ) ) |
|
| 580 | + { |
|
| 523 | 581 | $key = key( $opt ); |
| 524 | 582 | $value = $opt[key( $opt )]; |
| 525 | 583 | @$fldarray[$field_id][$key] .= $value; |
| 526 | 584 | // Option doesn't have arguments |
| 527 | - } else { |
|
| 585 | + } |
|
| 586 | + else |
|
| 587 | + { |
|
| 528 | 588 | $fldarray[$field_id][$opt] = $opt; |
| 529 | 589 | } |
| 530 | 590 | } |
| 531 | 591 | } |
| 532 | 592 | } |
| 533 | 593 | |
| 534 | - if( empty( $legacy_fields ) ) { |
|
| 594 | + if( empty( $legacy_fields ) ) |
|
| 595 | + { |
|
| 535 | 596 | // Create the new table |
| 536 | 597 | $sql[] = $xmls->dict->CreateTableSQL( $this->name, $fldarray, $this->opts ); |
| 537 | 598 | logMsg( end( $sql ), 'Generated CreateTableSQL' ); |
| 538 | - } else { |
|
| 599 | + } |
|
| 600 | + else |
|
| 601 | + { |
|
| 539 | 602 | // Upgrade an existing table |
| 540 | 603 | logMsg( "Upgrading {$this->name} using '{$xmls->upgrade}'" ); |
| 541 | - switch( $xmls->upgrade ) { |
|
| 604 | + switch( $xmls->upgrade ) |
|
| 605 | + { |
|
| 542 | 606 | // Use ChangeTableSQL |
| 543 | 607 | case 'ALTER': |
| 544 | 608 | logMsg( 'Generated ChangeTableSQL (ALTERing table)' ); |
@@ -555,11 +619,13 @@ discard block |
||
| 555 | 619 | } |
| 556 | 620 | } |
| 557 | 621 | |
| 558 | - foreach( $this->indexes as $index ) { |
|
| 622 | + foreach( $this->indexes as $index ) |
|
| 623 | + { |
|
| 559 | 624 | $sql[] = $index->create( $xmls ); |
| 560 | 625 | } |
| 561 | 626 | |
| 562 | - if( isset( $this->data ) ) { |
|
| 627 | + if( isset( $this->data ) ) |
|
| 628 | + { |
|
| 563 | 629 | $sql[] = $this->data->create( $xmls ); |
| 564 | 630 | } |
| 565 | 631 | |
@@ -569,13 +635,17 @@ discard block |
||
| 569 | 635 | /** |
| 570 | 636 | * Marks a field or table for destruction |
| 571 | 637 | */ |
| 572 | - function drop() { |
|
| 573 | - if( isset( $this->current_field ) ) { |
|
| 638 | + function drop() |
|
| 639 | + { |
|
| 640 | + if( isset( $this->current_field ) ) |
|
| 641 | + { |
|
| 574 | 642 | // Drop the current field |
| 575 | 643 | logMsg( "Dropping field '{$this->current_field}' from table '{$this->name}'" ); |
| 576 | 644 | // $this->drop_field[$this->current_field] = $xmls->dict->DropColumnSQL( $this->name, $this->current_field ); |
| 577 | 645 | $this->drop_field[$this->current_field] = $this->current_field; |
| 578 | - } else { |
|
| 646 | + } |
|
| 647 | + else |
|
| 648 | + { |
|
| 579 | 649 | // Drop the current table |
| 580 | 650 | logMsg( "Dropping table '{$this->name}'" ); |
| 581 | 651 | // $this->drop_table = $xmls->dict->DropTableSQL( $this->name ); |
@@ -595,7 +665,8 @@ discard block |
||
| 595 | 665 | * @package axmls |
| 596 | 666 | * @access private |
| 597 | 667 | */ |
| 598 | -class dbIndex extends dbObject { |
|
| 668 | +class dbIndex extends dbObject |
|
| 669 | +{ |
|
| 599 | 670 | |
| 600 | 671 | /** |
| 601 | 672 | * @var string Index name |
@@ -626,7 +697,8 @@ discard block |
||
| 626 | 697 | * |
| 627 | 698 | * @internal |
| 628 | 699 | */ |
| 629 | - function dbIndex( &$parent, $attributes = NULL ) { |
|
| 700 | + function dbIndex( &$parent, $attributes = NULL ) |
|
| 701 | + { |
|
| 630 | 702 | $this->parent =& $parent; |
| 631 | 703 | |
| 632 | 704 | $this->name = $this->prefix ($attributes['NAME']); |
@@ -640,10 +712,12 @@ discard block |
||
| 640 | 712 | * |
| 641 | 713 | * @access private |
| 642 | 714 | */ |
| 643 | - function _tag_open( &$parser, $tag, $attributes ) { |
|
| 715 | + function _tag_open( &$parser, $tag, $attributes ) |
|
| 716 | + { |
|
| 644 | 717 | $this->currentElement = strtoupper( $tag ); |
| 645 | 718 | |
| 646 | - switch( $this->currentElement ) { |
|
| 719 | + switch( $this->currentElement ) |
|
| 720 | + { |
|
| 647 | 721 | case 'DROP': |
| 648 | 722 | $this->drop(); |
| 649 | 723 | break; |
@@ -667,8 +741,10 @@ discard block |
||
| 667 | 741 | * |
| 668 | 742 | * @access private |
| 669 | 743 | */ |
| 670 | - function _tag_cdata( &$parser, $cdata ) { |
|
| 671 | - switch( $this->currentElement ) { |
|
| 744 | + function _tag_cdata( &$parser, $cdata ) |
|
| 745 | + { |
|
| 746 | + switch( $this->currentElement ) |
|
| 747 | + { |
|
| 672 | 748 | // Index field name |
| 673 | 749 | case 'COL': |
| 674 | 750 | $this->addField( $cdata ); |
@@ -683,10 +759,12 @@ discard block |
||
| 683 | 759 | * |
| 684 | 760 | * @access private |
| 685 | 761 | */ |
| 686 | - function _tag_close( &$parser, $tag ) { |
|
| 762 | + function _tag_close( &$parser, $tag ) |
|
| 763 | + { |
|
| 687 | 764 | $this->currentElement = ''; |
| 688 | 765 | |
| 689 | - switch( strtoupper( $tag ) ) { |
|
| 766 | + switch( strtoupper( $tag ) ) |
|
| 767 | + { |
|
| 690 | 768 | case 'INDEX': |
| 691 | 769 | xml_set_object( $parser, $this->parent ); |
| 692 | 770 | break; |
@@ -699,7 +777,8 @@ discard block |
||
| 699 | 777 | * @param string $name Field name |
| 700 | 778 | * @return string Field list |
| 701 | 779 | */ |
| 702 | - function addField( $name ) { |
|
| 780 | + function addField( $name ) |
|
| 781 | + { |
|
| 703 | 782 | $this->columns[$this->FieldID( $name )] = $name; |
| 704 | 783 | |
| 705 | 784 | // Return the field list |
@@ -712,7 +791,8 @@ discard block |
||
| 712 | 791 | * @param string $opt Comma-separated list of index options. |
| 713 | 792 | * @return string Option list |
| 714 | 793 | */ |
| 715 | - function addIndexOpt( $opt ) { |
|
| 794 | + function addIndexOpt( $opt ) |
|
| 795 | + { |
|
| 716 | 796 | $this->opts[] = $opt; |
| 717 | 797 | |
| 718 | 798 | // Return the options list |
@@ -725,14 +805,18 @@ discard block |
||
| 725 | 805 | * @param object $xmls adoSchema object |
| 726 | 806 | * @return array Array containing index creation SQL |
| 727 | 807 | */ |
| 728 | - function create( &$xmls ) { |
|
| 729 | - if( $this->drop ) { |
|
| 808 | + function create( &$xmls ) |
|
| 809 | + { |
|
| 810 | + if( $this->drop ) |
|
| 811 | + { |
|
| 730 | 812 | return NULL; |
| 731 | 813 | } |
| 732 | 814 | |
| 733 | 815 | // eliminate any columns that aren't in the table |
| 734 | - foreach( $this->columns as $id => $col ) { |
|
| 735 | - if( !isset( $this->parent->fields[$id] ) ) { |
|
| 816 | + foreach( $this->columns as $id => $col ) |
|
| 817 | + { |
|
| 818 | + if( !isset( $this->parent->fields[$id] ) ) |
|
| 819 | + { |
|
| 736 | 820 | unset( $this->columns[$id] ); |
| 737 | 821 | } |
| 738 | 822 | } |
@@ -743,7 +827,8 @@ discard block |
||
| 743 | 827 | /** |
| 744 | 828 | * Marks an index for destruction |
| 745 | 829 | */ |
| 746 | - function drop() { |
|
| 830 | + function drop() |
|
| 831 | + { |
|
| 747 | 832 | $this->drop = TRUE; |
| 748 | 833 | } |
| 749 | 834 | } |
@@ -756,7 +841,8 @@ discard block |
||
| 756 | 841 | * @package axmls |
| 757 | 842 | * @access private |
| 758 | 843 | */ |
| 759 | -class dbData extends dbObject { |
|
| 844 | +class dbData extends dbObject |
|
| 845 | +{ |
|
| 760 | 846 | |
| 761 | 847 | var $data = array(); |
| 762 | 848 | |
@@ -770,7 +856,8 @@ discard block |
||
| 770 | 856 | * |
| 771 | 857 | * @internal |
| 772 | 858 | */ |
| 773 | - function dbData( &$parent, $attributes = NULL ) { |
|
| 859 | + function dbData( &$parent, $attributes = NULL ) |
|
| 860 | + { |
|
| 774 | 861 | $this->parent =& $parent; |
| 775 | 862 | } |
| 776 | 863 | |
@@ -782,10 +869,12 @@ discard block |
||
| 782 | 869 | * |
| 783 | 870 | * @access private |
| 784 | 871 | */ |
| 785 | - function _tag_open( &$parser, $tag, $attributes ) { |
|
| 872 | + function _tag_open( &$parser, $tag, $attributes ) |
|
| 873 | + { |
|
| 786 | 874 | $this->currentElement = strtoupper( $tag ); |
| 787 | 875 | |
| 788 | - switch( $this->currentElement ) { |
|
| 876 | + switch( $this->currentElement ) |
|
| 877 | + { |
|
| 789 | 878 | case 'ROW': |
| 790 | 879 | $this->row = count( $this->data ); |
| 791 | 880 | $this->data[$this->row] = array(); |
@@ -804,8 +893,10 @@ discard block |
||
| 804 | 893 | * |
| 805 | 894 | * @access private |
| 806 | 895 | */ |
| 807 | - function _tag_cdata( &$parser, $cdata ) { |
|
| 808 | - switch( $this->currentElement ) { |
|
| 896 | + function _tag_cdata( &$parser, $cdata ) |
|
| 897 | + { |
|
| 898 | + switch( $this->currentElement ) |
|
| 899 | + { |
|
| 809 | 900 | // Index field name |
| 810 | 901 | case 'F': |
| 811 | 902 | $this->addData( $cdata ); |
@@ -820,10 +911,12 @@ discard block |
||
| 820 | 911 | * |
| 821 | 912 | * @access private |
| 822 | 913 | */ |
| 823 | - function _tag_close( &$parser, $tag ) { |
|
| 914 | + function _tag_close( &$parser, $tag ) |
|
| 915 | + { |
|
| 824 | 916 | $this->currentElement = ''; |
| 825 | 917 | |
| 826 | - switch( strtoupper( $tag ) ) { |
|
| 918 | + switch( strtoupper( $tag ) ) |
|
| 919 | + { |
|
| 827 | 920 | case 'DATA': |
| 828 | 921 | xml_set_object( $parser, $this->parent ); |
| 829 | 922 | break; |
@@ -836,10 +929,14 @@ discard block |
||
| 836 | 929 | * @param string $name Field name |
| 837 | 930 | * @return string Field list |
| 838 | 931 | */ |
| 839 | - function addField( $attributes ) { |
|
| 840 | - if( isset( $attributes['NAME'] ) ) { |
|
| 932 | + function addField( $attributes ) |
|
| 933 | + { |
|
| 934 | + if( isset( $attributes['NAME'] ) ) |
|
| 935 | + { |
|
| 841 | 936 | $name = $attributes['NAME']; |
| 842 | - } else { |
|
| 937 | + } |
|
| 938 | + else |
|
| 939 | + { |
|
| 843 | 940 | $name = count($this->data[$this->row]); |
| 844 | 941 | } |
| 845 | 942 | |
@@ -853,12 +950,15 @@ discard block |
||
| 853 | 950 | * @param string $opt Comma-separated list of index options. |
| 854 | 951 | * @return string Option list |
| 855 | 952 | */ |
| 856 | - function addData( $cdata ) { |
|
| 857 | - if( !isset( $this->data[$this->row] ) ) { |
|
| 953 | + function addData( $cdata ) |
|
| 954 | + { |
|
| 955 | + if( !isset( $this->data[$this->row] ) ) |
|
| 956 | + { |
|
| 858 | 957 | $this->data[$this->row] = array(); |
| 859 | 958 | } |
| 860 | 959 | |
| 861 | - if( !isset( $this->data[$this->row][$this->current_field] ) ) { |
|
| 960 | + if( !isset( $this->data[$this->row][$this->current_field] ) ) |
|
| 961 | + { |
|
| 862 | 962 | $this->data[$this->row][$this->current_field] = ''; |
| 863 | 963 | } |
| 864 | 964 | |
@@ -871,28 +971,36 @@ discard block |
||
| 871 | 971 | * @param object $xmls adoSchema object |
| 872 | 972 | * @return array Array containing index creation SQL |
| 873 | 973 | */ |
| 874 | - function create( &$xmls ) { |
|
| 974 | + function create( &$xmls ) |
|
| 975 | + { |
|
| 875 | 976 | $table = $xmls->dict->TableName($this->parent->name); |
| 876 | 977 | $table_field_count = count($this->parent->fields); |
| 877 | 978 | $sql = array(); |
| 878 | 979 | |
| 879 | 980 | // eliminate any columns that aren't in the table |
| 880 | - foreach( $this->data as $row ) { |
|
| 981 | + foreach( $this->data as $row ) |
|
| 982 | + { |
|
| 881 | 983 | $table_fields = $this->parent->fields; |
| 882 | 984 | $fields = array(); |
| 883 | 985 | |
| 884 | - foreach( $row as $field_id => $field_data ) { |
|
| 885 | - if( !array_key_exists( $field_id, $table_fields ) ) { |
|
| 886 | - if( is_numeric( $field_id ) ) { |
|
| 986 | + foreach( $row as $field_id => $field_data ) |
|
| 987 | + { |
|
| 988 | + if( !array_key_exists( $field_id, $table_fields ) ) |
|
| 989 | + { |
|
| 990 | + if( is_numeric( $field_id ) ) |
|
| 991 | + { |
|
| 887 | 992 | $field_id = reset( array_keys( $table_fields ) ); |
| 888 | - } else { |
|
| 993 | + } |
|
| 994 | + else |
|
| 995 | + { |
|
| 889 | 996 | continue; |
| 890 | 997 | } |
| 891 | 998 | } |
| 892 | 999 | |
| 893 | 1000 | $name = $table_fields[$field_id]['NAME']; |
| 894 | 1001 | |
| 895 | - switch( $table_fields[$field_id]['TYPE'] ) { |
|
| 1002 | + switch( $table_fields[$field_id]['TYPE'] ) |
|
| 1003 | + { |
|
| 896 | 1004 | case 'C': |
| 897 | 1005 | case 'C2': |
| 898 | 1006 | case 'X': |
@@ -914,16 +1022,21 @@ discard block |
||
| 914 | 1022 | } |
| 915 | 1023 | |
| 916 | 1024 | // check that at least 1 column is specified |
| 917 | - if( empty( $fields ) ) { |
|
| 1025 | + if( empty( $fields ) ) |
|
| 1026 | + { |
|
| 918 | 1027 | continue; |
| 919 | 1028 | } |
| 920 | 1029 | |
| 921 | 1030 | // check that no required columns are missing |
| 922 | - if( count( $fields ) < $table_field_count ) { |
|
| 923 | - foreach( $table_fields as $field ) { |
|
| 1031 | + if( count( $fields ) < $table_field_count ) |
|
| 1032 | + { |
|
| 1033 | + foreach( $table_fields as $field ) |
|
| 1034 | + { |
|
| 924 | 1035 | if (isset( $field['OPTS'] )) |
| 925 | - if( ( in_array( 'NOTNULL', $field['OPTS'] ) || in_array( 'KEY', $field['OPTS'] ) ) && !in_array( 'AUTOINCREMENT', $field['OPTS'] ) ) { |
|
| 1036 | + { |
|
| 1037 | + if( ( in_array( 'NOTNULL', $field['OPTS'] ) || in_array( 'KEY', $field['OPTS'] ) ) && !in_array( 'AUTOINCREMENT', $field['OPTS'] ) ) { |
|
| 926 | 1038 | continue(2); |
| 1039 | + } |
|
| 927 | 1040 | } |
| 928 | 1041 | } |
| 929 | 1042 | } |
@@ -941,7 +1054,8 @@ discard block |
||
| 941 | 1054 | * @package axmls |
| 942 | 1055 | * @access private |
| 943 | 1056 | */ |
| 944 | -class dbQuerySet extends dbObject { |
|
| 1057 | +class dbQuerySet extends dbObject |
|
| 1058 | +{ |
|
| 945 | 1059 | |
| 946 | 1060 | /** |
| 947 | 1061 | * @var array List of SQL queries |
@@ -969,18 +1083,21 @@ discard block |
||
| 969 | 1083 | * @param object $parent Parent object |
| 970 | 1084 | * @param array $attributes Attributes |
| 971 | 1085 | */ |
| 972 | - function dbQuerySet( &$parent, $attributes = NULL ) { |
|
| 1086 | + function dbQuerySet( &$parent, $attributes = NULL ) |
|
| 1087 | + { |
|
| 973 | 1088 | $this->parent =& $parent; |
| 974 | 1089 | |
| 975 | 1090 | // Overrides the manual prefix key |
| 976 | - if( isset( $attributes['KEY'] ) ) { |
|
| 1091 | + if( isset( $attributes['KEY'] ) ) |
|
| 1092 | + { |
|
| 977 | 1093 | $this->prefixKey = $attributes['KEY']; |
| 978 | 1094 | } |
| 979 | 1095 | |
| 980 | 1096 | $prefixMethod = isset( $attributes['PREFIXMETHOD'] ) ? strtoupper( trim( $attributes['PREFIXMETHOD'] ) ) : ''; |
| 981 | 1097 | |
| 982 | 1098 | // Enables or disables automatic prefix prepending |
| 983 | - switch( $prefixMethod ) { |
|
| 1099 | + switch( $prefixMethod ) |
|
| 1100 | + { |
|
| 984 | 1101 | case 'AUTO': |
| 985 | 1102 | $this->prefixMethod = 'AUTO'; |
| 986 | 1103 | break; |
@@ -999,17 +1116,22 @@ discard block |
||
| 999 | 1116 | * |
| 1000 | 1117 | * @access private |
| 1001 | 1118 | */ |
| 1002 | - function _tag_open( &$parser, $tag, $attributes ) { |
|
| 1119 | + function _tag_open( &$parser, $tag, $attributes ) |
|
| 1120 | + { |
|
| 1003 | 1121 | $this->currentElement = strtoupper( $tag ); |
| 1004 | 1122 | |
| 1005 | - switch( $this->currentElement ) { |
|
| 1123 | + switch( $this->currentElement ) |
|
| 1124 | + { |
|
| 1006 | 1125 | case 'QUERY': |
| 1007 | 1126 | // Create a new query in a SQL queryset. |
| 1008 | 1127 | // Ignore this query set if a platform is specified and it's different than the |
| 1009 | 1128 | // current connection platform. |
| 1010 | - if( !isset( $attributes['PLATFORM'] ) OR $this->supportedPlatform( $attributes['PLATFORM'] ) ) { |
|
| 1129 | + if( !isset( $attributes['PLATFORM'] ) OR $this->supportedPlatform( $attributes['PLATFORM'] ) ) |
|
| 1130 | + { |
|
| 1011 | 1131 | $this->newQuery(); |
| 1012 | - } else { |
|
| 1132 | + } |
|
| 1133 | + else |
|
| 1134 | + { |
|
| 1013 | 1135 | $this->discardQuery(); |
| 1014 | 1136 | } |
| 1015 | 1137 | break; |
@@ -1021,8 +1143,10 @@ discard block |
||
| 1021 | 1143 | /** |
| 1022 | 1144 | * XML Callback to process CDATA elements |
| 1023 | 1145 | */ |
| 1024 | - function _tag_cdata( &$parser, $cdata ) { |
|
| 1025 | - switch( $this->currentElement ) { |
|
| 1146 | + function _tag_cdata( &$parser, $cdata ) |
|
| 1147 | + { |
|
| 1148 | + switch( $this->currentElement ) |
|
| 1149 | + { |
|
| 1026 | 1150 | // Line of queryset SQL data |
| 1027 | 1151 | case 'QUERY': |
| 1028 | 1152 | $this->buildQuery( $cdata ); |
@@ -1037,10 +1161,12 @@ discard block |
||
| 1037 | 1161 | * |
| 1038 | 1162 | * @access private |
| 1039 | 1163 | */ |
| 1040 | - function _tag_close( &$parser, $tag ) { |
|
| 1164 | + function _tag_close( &$parser, $tag ) |
|
| 1165 | + { |
|
| 1041 | 1166 | $this->currentElement = ''; |
| 1042 | 1167 | |
| 1043 | - switch( strtoupper( $tag ) ) { |
|
| 1168 | + switch( strtoupper( $tag ) ) |
|
| 1169 | + { |
|
| 1044 | 1170 | case 'QUERY': |
| 1045 | 1171 | // Add the finished query to the open query set. |
| 1046 | 1172 | $this->addQuery(); |
@@ -1060,7 +1186,8 @@ discard block |
||
| 1060 | 1186 | * |
| 1061 | 1187 | * @return boolean TRUE |
| 1062 | 1188 | */ |
| 1063 | - function newQuery() { |
|
| 1189 | + function newQuery() |
|
| 1190 | + { |
|
| 1064 | 1191 | $this->query = ''; |
| 1065 | 1192 | |
| 1066 | 1193 | return TRUE; |
@@ -1071,7 +1198,8 @@ discard block |
||
| 1071 | 1198 | * |
| 1072 | 1199 | * @return boolean TRUE |
| 1073 | 1200 | */ |
| 1074 | - function discardQuery() { |
|
| 1201 | + function discardQuery() |
|
| 1202 | + { |
|
| 1075 | 1203 | unset( $this->query ); |
| 1076 | 1204 | |
| 1077 | 1205 | return TRUE; |
@@ -1083,8 +1211,10 @@ discard block |
||
| 1083 | 1211 | * @param string $data Line of SQL data or NULL to initialize a new query |
| 1084 | 1212 | * @return string SQL query string. |
| 1085 | 1213 | */ |
| 1086 | - function buildQuery( $sql = NULL ) { |
|
| 1087 | - if( !isset( $this->query ) OR empty( $sql ) ) { |
|
| 1214 | + function buildQuery( $sql = NULL ) |
|
| 1215 | + { |
|
| 1216 | + if( !isset( $this->query ) OR empty( $sql ) ) |
|
| 1217 | + { |
|
| 1088 | 1218 | return FALSE; |
| 1089 | 1219 | } |
| 1090 | 1220 | |
@@ -1098,8 +1228,10 @@ discard block |
||
| 1098 | 1228 | * |
| 1099 | 1229 | * @return string SQL of added query |
| 1100 | 1230 | */ |
| 1101 | - function addQuery() { |
|
| 1102 | - if( !isset( $this->query ) ) { |
|
| 1231 | + function addQuery() |
|
| 1232 | + { |
|
| 1233 | + if( !isset( $this->query ) ) |
|
| 1234 | + { |
|
| 1103 | 1235 | return FALSE; |
| 1104 | 1236 | } |
| 1105 | 1237 | |
@@ -1116,9 +1248,12 @@ discard block |
||
| 1116 | 1248 | * @param object $xmls adoSchema object |
| 1117 | 1249 | * @return array Query set |
| 1118 | 1250 | */ |
| 1119 | - function create( &$xmls ) { |
|
| 1120 | - foreach( $this->queries as $id => $query ) { |
|
| 1121 | - switch( $this->prefixMethod ) { |
|
| 1251 | + function create( &$xmls ) |
|
| 1252 | + { |
|
| 1253 | + foreach( $this->queries as $id => $query ) |
|
| 1254 | + { |
|
| 1255 | + switch( $this->prefixMethod ) |
|
| 1256 | + { |
|
| 1122 | 1257 | case 'AUTO': |
| 1123 | 1258 | // Enable auto prefix replacement |
| 1124 | 1259 | |
@@ -1134,10 +1269,13 @@ discard block |
||
| 1134 | 1269 | case 'MANUAL': |
| 1135 | 1270 | // If prefixKey is set and has a value then we use it to override the default constant XMLS_PREFIX. |
| 1136 | 1271 | // If prefixKey is not set, we use the default constant XMLS_PREFIX |
| 1137 | - if( isset( $this->prefixKey ) AND( $this->prefixKey !== '' ) ) { |
|
| 1272 | + if( isset( $this->prefixKey ) AND( $this->prefixKey !== '' ) ) |
|
| 1273 | + { |
|
| 1138 | 1274 | // Enable prefix override |
| 1139 | 1275 | $query = str_replace( $this->prefixKey, $xmls->objectPrefix, $query ); |
| 1140 | - } else { |
|
| 1276 | + } |
|
| 1277 | + else |
|
| 1278 | + { |
|
| 1141 | 1279 | // Use default replacement |
| 1142 | 1280 | $query = str_replace( XMLS_PREFIX , $xmls->objectPrefix, $query ); |
| 1143 | 1281 | } |
@@ -1158,12 +1296,15 @@ discard block |
||
| 1158 | 1296 | * @param string $prefix Prefix to be appended to tables, indices, etc. |
| 1159 | 1297 | * @return string Prefixed SQL query string. |
| 1160 | 1298 | */ |
| 1161 | - function prefixQuery( $regex, $query, $prefix = NULL ) { |
|
| 1162 | - if( !isset( $prefix ) ) { |
|
| 1299 | + function prefixQuery( $regex, $query, $prefix = NULL ) |
|
| 1300 | + { |
|
| 1301 | + if( !isset( $prefix ) ) |
|
| 1302 | + { |
|
| 1163 | 1303 | return $query; |
| 1164 | 1304 | } |
| 1165 | 1305 | |
| 1166 | - if( preg_match( $regex, $query, $match ) ) { |
|
| 1306 | + if( preg_match( $regex, $query, $match ) ) |
|
| 1307 | + { |
|
| 1167 | 1308 | $preamble = $match[1]; |
| 1168 | 1309 | $postamble = $match[5]; |
| 1169 | 1310 | $objectList = explode( ',', $match[3] ); |
@@ -1171,8 +1312,10 @@ discard block |
||
| 1171 | 1312 | |
| 1172 | 1313 | $prefixedList = ''; |
| 1173 | 1314 | |
| 1174 | - foreach( $objectList as $object ) { |
|
| 1175 | - if( $prefixedList !== '' ) { |
|
| 1315 | + foreach( $objectList as $object ) |
|
| 1316 | + { |
|
| 1317 | + if( $prefixedList !== '' ) |
|
| 1318 | + { |
|
| 1176 | 1319 | $prefixedList .= ', '; |
| 1177 | 1320 | } |
| 1178 | 1321 | |
@@ -1199,7 +1342,8 @@ discard block |
||
| 1199 | 1342 | * |
| 1200 | 1343 | * @package axmls |
| 1201 | 1344 | */ |
| 1202 | -class adoSchema { |
|
| 1345 | +class adoSchema |
|
| 1346 | +{ |
|
| 1203 | 1347 | |
| 1204 | 1348 | /** |
| 1205 | 1349 | * @var array Array containing SQL queries to generate all objects |
@@ -1285,7 +1429,8 @@ discard block |
||
| 1285 | 1429 | * |
| 1286 | 1430 | * @param object $db ADOdb database connection object. |
| 1287 | 1431 | */ |
| 1288 | - function adoSchema( &$db ) { |
|
| 1432 | + function adoSchema( &$db ) |
|
| 1433 | + { |
|
| 1289 | 1434 | // Initialize the environment |
| 1290 | 1435 | $this->mgq = get_magic_quotes_runtime(); |
| 1291 | 1436 | set_magic_quotes_runtime(0); |
@@ -1316,15 +1461,18 @@ discard block |
||
| 1316 | 1461 | * @param string $method Upgrade method (ALTER|REPLACE|BEST|NONE) |
| 1317 | 1462 | * @returns string Upgrade method used |
| 1318 | 1463 | */ |
| 1319 | - function SetUpgradeMethod( $method = '' ) { |
|
| 1320 | - if( !is_string( $method ) ) { |
|
| 1464 | + function SetUpgradeMethod( $method = '' ) |
|
| 1465 | + { |
|
| 1466 | + if( !is_string( $method ) ) |
|
| 1467 | + { |
|
| 1321 | 1468 | return FALSE; |
| 1322 | 1469 | } |
| 1323 | 1470 | |
| 1324 | 1471 | $method = strtoupper( $method ); |
| 1325 | 1472 | |
| 1326 | 1473 | // Handle the upgrade methods |
| 1327 | - switch( $method ) { |
|
| 1474 | + switch( $method ) |
|
| 1475 | + { |
|
| 1328 | 1476 | case 'ALTER': |
| 1329 | 1477 | $this->upgrade = $method; |
| 1330 | 1478 | break; |
@@ -1358,8 +1506,10 @@ discard block |
||
| 1358 | 1506 | * |
| 1359 | 1507 | * @see ParseSchema(), ExecuteSchema() |
| 1360 | 1508 | */ |
| 1361 | - function ExecuteInline( $mode = NULL ) { |
|
| 1362 | - if( is_bool( $mode ) ) { |
|
| 1509 | + function ExecuteInline( $mode = NULL ) |
|
| 1510 | + { |
|
| 1511 | + if( is_bool( $mode ) ) |
|
| 1512 | + { |
|
| 1363 | 1513 | $this->executeInline = $mode; |
| 1364 | 1514 | } |
| 1365 | 1515 | |
@@ -1379,8 +1529,10 @@ discard block |
||
| 1379 | 1529 | * |
| 1380 | 1530 | * @see addSQL(), ExecuteSchema() |
| 1381 | 1531 | */ |
| 1382 | - function ContinueOnError( $mode = NULL ) { |
|
| 1383 | - if( is_bool( $mode ) ) { |
|
| 1532 | + function ContinueOnError( $mode = NULL ) |
|
| 1533 | + { |
|
| 1534 | + if( is_bool( $mode ) ) |
|
| 1535 | + { |
|
| 1384 | 1536 | $this->continueOnError = $mode; |
| 1385 | 1537 | } |
| 1386 | 1538 | |
@@ -1398,7 +1550,8 @@ discard block |
||
| 1398 | 1550 | * @param bool $returnSchema Return schema rather than parsing. |
| 1399 | 1551 | * @return array Array of SQL queries, ready to execute |
| 1400 | 1552 | */ |
| 1401 | - function ParseSchema( $filename, $returnSchema = FALSE ) { |
|
| 1553 | + function ParseSchema( $filename, $returnSchema = FALSE ) |
|
| 1554 | + { |
|
| 1402 | 1555 | return $this->ParseSchemaString( $this->ConvertSchemaFile( $filename ), $returnSchema ); |
| 1403 | 1556 | } |
| 1404 | 1557 | |
@@ -1415,15 +1568,18 @@ discard block |
||
| 1415 | 1568 | * @deprecated Replaced by adoSchema::ParseSchema() and adoSchema::ParseSchemaString() |
| 1416 | 1569 | * @see ParseSchema(), ParseSchemaString() |
| 1417 | 1570 | */ |
| 1418 | - function ParseSchemaFile( $filename, $returnSchema = FALSE ) { |
|
| 1571 | + function ParseSchemaFile( $filename, $returnSchema = FALSE ) |
|
| 1572 | + { |
|
| 1419 | 1573 | // Open the file |
| 1420 | - if( !($fp = fopen( $filename, 'r' )) ) { |
|
| 1574 | + if( !($fp = fopen( $filename, 'r' )) ) |
|
| 1575 | + { |
|
| 1421 | 1576 | // die( 'Unable to open file' ); |
| 1422 | 1577 | return FALSE; |
| 1423 | 1578 | } |
| 1424 | 1579 | |
| 1425 | 1580 | // do version detection here |
| 1426 | - if( $this->SchemaFileVersion( $filename ) != $this->schemaVersion ) { |
|
| 1581 | + if( $this->SchemaFileVersion( $filename ) != $this->schemaVersion ) |
|
| 1582 | + { |
|
| 1427 | 1583 | return FALSE; |
| 1428 | 1584 | } |
| 1429 | 1585 | |
@@ -1437,8 +1593,10 @@ discard block |
||
| 1437 | 1593 | $xmlParser = $this->create_parser(); |
| 1438 | 1594 | |
| 1439 | 1595 | // Process the file |
| 1440 | - while( $data = fread( $fp, 4096 ) ) { |
|
| 1441 | - if( !xml_parse( $xmlParser, $data, feof( $fp ) ) ) { |
|
| 1596 | + while( $data = fread( $fp, 4096 ) ) |
|
| 1597 | + { |
|
| 1598 | + if( !xml_parse( $xmlParser, $data, feof( $fp ) ) ) |
|
| 1599 | + { |
|
| 1442 | 1600 | die( sprintf( |
| 1443 | 1601 | "XML error: %s at line %d", |
| 1444 | 1602 | xml_error_string( xml_get_error_code( $xmlParser) ), |
@@ -1463,13 +1621,16 @@ discard block |
||
| 1463 | 1621 | * @param bool $returnSchema Return schema rather than parsing. |
| 1464 | 1622 | * @return array Array of SQL queries, ready to execute. |
| 1465 | 1623 | */ |
| 1466 | - function ParseSchemaString( $xmlstring, $returnSchema = FALSE ) { |
|
| 1467 | - if( !is_string( $xmlstring ) OR empty( $xmlstring ) ) { |
|
| 1624 | + function ParseSchemaString( $xmlstring, $returnSchema = FALSE ) |
|
| 1625 | + { |
|
| 1626 | + if( !is_string( $xmlstring ) OR empty( $xmlstring ) ) |
|
| 1627 | + { |
|
| 1468 | 1628 | return FALSE; |
| 1469 | 1629 | } |
| 1470 | 1630 | |
| 1471 | 1631 | // do version detection here |
| 1472 | - if( $this->SchemaStringVersion( $xmlstring ) != $this->schemaVersion ) { |
|
| 1632 | + if( $this->SchemaStringVersion( $xmlstring ) != $this->schemaVersion ) |
|
| 1633 | + { |
|
| 1473 | 1634 | return FALSE; |
| 1474 | 1635 | } |
| 1475 | 1636 | |
@@ -1482,7 +1643,8 @@ discard block |
||
| 1482 | 1643 | |
| 1483 | 1644 | $xmlParser = $this->create_parser(); |
| 1484 | 1645 | |
| 1485 | - if( !xml_parse( $xmlParser, $xmlstring, TRUE ) ) { |
|
| 1646 | + if( !xml_parse( $xmlParser, $xmlstring, TRUE ) ) |
|
| 1647 | + { |
|
| 1486 | 1648 | die( sprintf( |
| 1487 | 1649 | "XML error: %s at line %d", |
| 1488 | 1650 | xml_error_string( xml_get_error_code( $xmlParser) ), |
@@ -1506,7 +1668,8 @@ discard block |
||
| 1506 | 1668 | * @param bool $returnSchema Return schema rather than parsing. |
| 1507 | 1669 | * @return array Array of SQL queries, ready to execute |
| 1508 | 1670 | */ |
| 1509 | - function RemoveSchema( $filename, $returnSchema = FALSE ) { |
|
| 1671 | + function RemoveSchema( $filename, $returnSchema = FALSE ) |
|
| 1672 | + { |
|
| 1510 | 1673 | return $this->RemoveSchemaString( $this->ConvertSchemaFile( $filename ), $returnSchema ); |
| 1511 | 1674 | } |
| 1512 | 1675 | |
@@ -1521,10 +1684,12 @@ discard block |
||
| 1521 | 1684 | * @param bool $returnSchema Return schema rather than parsing. |
| 1522 | 1685 | * @return array Array of SQL queries, ready to execute. |
| 1523 | 1686 | */ |
| 1524 | - function RemoveSchemaString( $schema, $returnSchema = FALSE ) { |
|
| 1687 | + function RemoveSchemaString( $schema, $returnSchema = FALSE ) |
|
| 1688 | + { |
|
| 1525 | 1689 | |
| 1526 | 1690 | // grab current version |
| 1527 | - if( !( $version = $this->SchemaStringVersion( $schema ) ) ) { |
|
| 1691 | + if( !( $version = $this->SchemaStringVersion( $schema ) ) ) |
|
| 1692 | + { |
|
| 1528 | 1693 | return FALSE; |
| 1529 | 1694 | } |
| 1530 | 1695 | |
@@ -1544,18 +1709,24 @@ discard block |
||
| 1544 | 1709 | * @param boolean $continueOnErr Continue to apply the schema even if an error occurs. |
| 1545 | 1710 | * @returns integer 0 if failure, 1 if errors, 2 if successful. |
| 1546 | 1711 | */ |
| 1547 | - function ExecuteSchema( $sqlArray = NULL, $continueOnErr = NULL ) { |
|
| 1548 | - if( !is_bool( $continueOnErr ) ) { |
|
| 1712 | + function ExecuteSchema( $sqlArray = NULL, $continueOnErr = NULL ) |
|
| 1713 | + { |
|
| 1714 | + if( !is_bool( $continueOnErr ) ) |
|
| 1715 | + { |
|
| 1549 | 1716 | $continueOnErr = $this->ContinueOnError(); |
| 1550 | 1717 | } |
| 1551 | 1718 | |
| 1552 | - if( !isset( $sqlArray ) ) { |
|
| 1719 | + if( !isset( $sqlArray ) ) |
|
| 1720 | + { |
|
| 1553 | 1721 | $sqlArray = $this->sqlArray; |
| 1554 | 1722 | } |
| 1555 | 1723 | |
| 1556 | - if( !is_array( $sqlArray ) ) { |
|
| 1724 | + if( !is_array( $sqlArray ) ) |
|
| 1725 | + { |
|
| 1557 | 1726 | $this->success = 0; |
| 1558 | - } else { |
|
| 1727 | + } |
|
| 1728 | + else |
|
| 1729 | + { |
|
| 1559 | 1730 | $this->success = $this->dict->ExecuteSQLArray( $sqlArray, $continueOnErr ); |
| 1560 | 1731 | } |
| 1561 | 1732 | |
@@ -1571,7 +1742,8 @@ discard block |
||
| 1571 | 1742 | * @param string $format Format: HTML, TEXT, or NONE (PHP array) |
| 1572 | 1743 | * @return array Array of SQL statements or FALSE if an error occurs |
| 1573 | 1744 | */ |
| 1574 | - function PrintSQL( $format = 'NONE' ) { |
|
| 1745 | + function PrintSQL( $format = 'NONE' ) |
|
| 1746 | + { |
|
| 1575 | 1747 | return $this->getSQL( $format, $sqlArray ); |
| 1576 | 1748 | } |
| 1577 | 1749 | |
@@ -1584,18 +1756,22 @@ discard block |
||
| 1584 | 1756 | * @param string $filename Path and name where the file should be saved. |
| 1585 | 1757 | * @return boolean TRUE if save is successful, else FALSE. |
| 1586 | 1758 | */ |
| 1587 | - function SaveSQL( $filename = './schema.sql' ) { |
|
| 1759 | + function SaveSQL( $filename = './schema.sql' ) |
|
| 1760 | + { |
|
| 1588 | 1761 | |
| 1589 | - if( !isset( $sqlArray ) ) { |
|
| 1762 | + if( !isset( $sqlArray ) ) |
|
| 1763 | + { |
|
| 1590 | 1764 | $sqlArray = $this->sqlArray; |
| 1591 | 1765 | } |
| 1592 | - if( !isset( $sqlArray ) ) { |
|
| 1766 | + if( !isset( $sqlArray ) ) |
|
| 1767 | + { |
|
| 1593 | 1768 | return FALSE; |
| 1594 | 1769 | } |
| 1595 | 1770 | |
| 1596 | 1771 | $fp = fopen( $filename, "w" ); |
| 1597 | 1772 | |
| 1598 | - foreach( $sqlArray as $key => $query ) { |
|
| 1773 | + foreach( $sqlArray as $key => $query ) |
|
| 1774 | + { |
|
| 1599 | 1775 | fwrite( $fp, $query . ";\n" ); |
| 1600 | 1776 | } |
| 1601 | 1777 | fclose( $fp ); |
@@ -1625,14 +1801,17 @@ discard block |
||
| 1625 | 1801 | * |
| 1626 | 1802 | * @access private |
| 1627 | 1803 | */ |
| 1628 | - function _tag_open( &$parser, $tag, $attributes ) { |
|
| 1629 | - switch( strtoupper( $tag ) ) { |
|
| 1804 | + function _tag_open( &$parser, $tag, $attributes ) |
|
| 1805 | + { |
|
| 1806 | + switch( strtoupper( $tag ) ) |
|
| 1807 | + { |
|
| 1630 | 1808 | case 'TABLE': |
| 1631 | 1809 | $this->obj = new dbTable( $this, $attributes ); |
| 1632 | 1810 | xml_set_object( $parser, $this->obj ); |
| 1633 | 1811 | break; |
| 1634 | 1812 | case 'SQL': |
| 1635 | - if( !isset( $attributes['PLATFORM'] ) OR $this->supportedPlatform( $attributes['PLATFORM'] ) ) { |
|
| 1813 | + if( !isset( $attributes['PLATFORM'] ) OR $this->supportedPlatform( $attributes['PLATFORM'] ) ) |
|
| 1814 | + { |
|
| 1636 | 1815 | $this->obj = new dbQuerySet( $this, $attributes ); |
| 1637 | 1816 | xml_set_object( $parser, $this->obj ); |
| 1638 | 1817 | } |
@@ -1648,7 +1827,8 @@ discard block |
||
| 1648 | 1827 | * |
| 1649 | 1828 | * @access private |
| 1650 | 1829 | */ |
| 1651 | - function _tag_cdata( &$parser, $cdata ) { |
|
| 1830 | + function _tag_cdata( &$parser, $cdata ) |
|
| 1831 | + { |
|
| 1652 | 1832 | } |
| 1653 | 1833 | |
| 1654 | 1834 | /** |
@@ -1657,7 +1837,8 @@ discard block |
||
| 1657 | 1837 | * @access private |
| 1658 | 1838 | * @internal |
| 1659 | 1839 | */ |
| 1660 | - function _tag_close( &$parser, $tag ) { |
|
| 1840 | + function _tag_close( &$parser, $tag ) |
|
| 1841 | + { |
|
| 1661 | 1842 | |
| 1662 | 1843 | } |
| 1663 | 1844 | |
@@ -1677,24 +1858,31 @@ discard block |
||
| 1677 | 1858 | * @param string $newFile File name of (converted) output file. |
| 1678 | 1859 | * @return string Converted XML schema or FALSE if an error occurs. |
| 1679 | 1860 | */ |
| 1680 | - function ConvertSchemaString( $schema, $newVersion = NULL, $newFile = NULL ) { |
|
| 1861 | + function ConvertSchemaString( $schema, $newVersion = NULL, $newFile = NULL ) |
|
| 1862 | + { |
|
| 1681 | 1863 | |
| 1682 | 1864 | // grab current version |
| 1683 | - if( !( $version = $this->SchemaStringVersion( $schema ) ) ) { |
|
| 1865 | + if( !( $version = $this->SchemaStringVersion( $schema ) ) ) |
|
| 1866 | + { |
|
| 1684 | 1867 | return FALSE; |
| 1685 | 1868 | } |
| 1686 | 1869 | |
| 1687 | - if( !isset ($newVersion) ) { |
|
| 1870 | + if( !isset ($newVersion) ) |
|
| 1871 | + { |
|
| 1688 | 1872 | $newVersion = $this->schemaVersion; |
| 1689 | 1873 | } |
| 1690 | 1874 | |
| 1691 | - if( $version == $newVersion ) { |
|
| 1875 | + if( $version == $newVersion ) |
|
| 1876 | + { |
|
| 1692 | 1877 | $result = $schema; |
| 1693 | - } else { |
|
| 1878 | + } |
|
| 1879 | + else |
|
| 1880 | + { |
|
| 1694 | 1881 | $result = $this->TransformSchema( $schema, 'convert-' . $version . '-' . $newVersion); |
| 1695 | 1882 | } |
| 1696 | 1883 | |
| 1697 | - if( is_string( $result ) AND is_string( $newFile ) AND ( $fp = fopen( $newFile, 'w' ) ) ) { |
|
| 1884 | + if( is_string( $result ) AND is_string( $newFile ) AND ( $fp = fopen( $newFile, 'w' ) ) ) |
|
| 1885 | + { |
|
| 1698 | 1886 | fwrite( $fp, $result ); |
| 1699 | 1887 | fclose( $fp ); |
| 1700 | 1888 | } |
@@ -1718,29 +1906,37 @@ discard block |
||
| 1718 | 1906 | * @param string $newFile File name of (converted) output file. |
| 1719 | 1907 | * @return string Converted XML schema or FALSE if an error occurs. |
| 1720 | 1908 | */ |
| 1721 | - function ConvertSchemaFile( $filename, $newVersion = NULL, $newFile = NULL ) { |
|
| 1909 | + function ConvertSchemaFile( $filename, $newVersion = NULL, $newFile = NULL ) |
|
| 1910 | + { |
|
| 1722 | 1911 | |
| 1723 | 1912 | // grab current version |
| 1724 | - if( !( $version = $this->SchemaFileVersion( $filename ) ) ) { |
|
| 1913 | + if( !( $version = $this->SchemaFileVersion( $filename ) ) ) |
|
| 1914 | + { |
|
| 1725 | 1915 | return FALSE; |
| 1726 | 1916 | } |
| 1727 | 1917 | |
| 1728 | - if( !isset ($newVersion) ) { |
|
| 1918 | + if( !isset ($newVersion) ) |
|
| 1919 | + { |
|
| 1729 | 1920 | $newVersion = $this->schemaVersion; |
| 1730 | 1921 | } |
| 1731 | 1922 | |
| 1732 | - if( $version == $newVersion ) { |
|
| 1923 | + if( $version == $newVersion ) |
|
| 1924 | + { |
|
| 1733 | 1925 | $result = file_get_contents( $filename ); |
| 1734 | 1926 | |
| 1735 | 1927 | // remove unicode BOM if present |
| 1736 | - if( substr( $result, 0, 3 ) == sprintf( '%c%c%c', 239, 187, 191 ) ) { |
|
| 1928 | + if( substr( $result, 0, 3 ) == sprintf( '%c%c%c', 239, 187, 191 ) ) |
|
| 1929 | + { |
|
| 1737 | 1930 | $result = substr( $result, 3 ); |
| 1738 | 1931 | } |
| 1739 | - } else { |
|
| 1932 | + } |
|
| 1933 | + else |
|
| 1934 | + { |
|
| 1740 | 1935 | $result = $this->TransformSchema( $filename, 'convert-' . $version . '-' . $newVersion, 'file' ); |
| 1741 | 1936 | } |
| 1742 | 1937 | |
| 1743 | - if( is_string( $result ) AND is_string( $newFile ) AND ( $fp = fopen( $newFile, 'w' ) ) ) { |
|
| 1938 | + if( is_string( $result ) AND is_string( $newFile ) AND ( $fp = fopen( $newFile, 'w' ) ) ) |
|
| 1939 | + { |
|
| 1744 | 1940 | fwrite( $fp, $result ); |
| 1745 | 1941 | fclose( $fp ); |
| 1746 | 1942 | } |
@@ -1751,21 +1947,24 @@ discard block |
||
| 1751 | 1947 | function TransformSchema( $schema, $xsl, $schematype='string' ) |
| 1752 | 1948 | { |
| 1753 | 1949 | // Fail if XSLT extension is not available |
| 1754 | - if( ! function_exists( 'xslt_create' ) ) { |
|
| 1950 | + if( ! function_exists( 'xslt_create' ) ) |
|
| 1951 | + { |
|
| 1755 | 1952 | return FALSE; |
| 1756 | 1953 | } |
| 1757 | 1954 | |
| 1758 | 1955 | $xsl_file = dirname( __FILE__ ) . '/xsl/' . $xsl . '.xsl'; |
| 1759 | 1956 | |
| 1760 | 1957 | // look for xsl |
| 1761 | - if( !is_readable( $xsl_file ) ) { |
|
| 1958 | + if( !is_readable( $xsl_file ) ) |
|
| 1959 | + { |
|
| 1762 | 1960 | return FALSE; |
| 1763 | 1961 | } |
| 1764 | 1962 | |
| 1765 | 1963 | switch( $schematype ) |
| 1766 | 1964 | { |
| 1767 | 1965 | case 'file': |
| 1768 | - if( !is_readable( $schema ) ) { |
|
| 1966 | + if( !is_readable( $schema ) ) |
|
| 1967 | + { |
|
| 1769 | 1968 | return FALSE; |
| 1770 | 1969 | } |
| 1771 | 1970 | |
@@ -1773,7 +1972,8 @@ discard block |
||
| 1773 | 1972 | break; |
| 1774 | 1973 | case 'string': |
| 1775 | 1974 | default: |
| 1776 | - if( !is_string( $schema ) ) { |
|
| 1975 | + if( !is_string( $schema ) ) |
|
| 1976 | + { |
|
| 1777 | 1977 | return FALSE; |
| 1778 | 1978 | } |
| 1779 | 1979 | } |
@@ -1807,8 +2007,10 @@ discard block |
||
| 1807 | 2007 | * |
| 1808 | 2008 | * @access private |
| 1809 | 2009 | */ |
| 1810 | - function xslt_error_handler( $parser, $errno, $level, $fields ) { |
|
| 1811 | - if( is_array( $fields ) ) { |
|
| 2010 | + function xslt_error_handler( $parser, $errno, $level, $fields ) |
|
| 2011 | + { |
|
| 2012 | + if( is_array( $fields ) ) |
|
| 2013 | + { |
|
| 1812 | 2014 | $msg = array( |
| 1813 | 2015 | 'Message Type' => ucfirst( $fields['msgtype'] ), |
| 1814 | 2016 | 'Message Code' => $fields['code'], |
@@ -1817,7 +2019,8 @@ discard block |
||
| 1817 | 2019 | 'Level' => $level |
| 1818 | 2020 | ); |
| 1819 | 2021 | |
| 1820 | - switch( $fields['URI'] ) { |
|
| 2022 | + switch( $fields['URI'] ) |
|
| 2023 | + { |
|
| 1821 | 2024 | case 'arg:/_xml': |
| 1822 | 2025 | $msg['Input'] = 'XML'; |
| 1823 | 2026 | break; |
@@ -1829,7 +2032,9 @@ discard block |
||
| 1829 | 2032 | } |
| 1830 | 2033 | |
| 1831 | 2034 | $msg['Line'] = $fields['line']; |
| 1832 | - } else { |
|
| 2035 | + } |
|
| 2036 | + else |
|
| 2037 | + { |
|
| 1833 | 2038 | $msg = array( |
| 1834 | 2039 | 'Message Type' => 'Error', |
| 1835 | 2040 | 'Error Number' => $errno, |
@@ -1841,7 +2046,8 @@ discard block |
||
| 1841 | 2046 | $error_details = $msg['Message Type'] . ' in XSLT Transformation' . "\n" |
| 1842 | 2047 | . '<table>' . "\n"; |
| 1843 | 2048 | |
| 1844 | - foreach( $msg as $label => $details ) { |
|
| 2049 | + foreach( $msg as $label => $details ) |
|
| 2050 | + { |
|
| 1845 | 2051 | $error_details .= '<tr><td><b>' . $label . ': </b></td><td>' . htmlentities( $details ) . '</td></tr>' . "\n"; |
| 1846 | 2052 | } |
| 1847 | 2053 | |
@@ -1859,16 +2065,20 @@ discard block |
||
| 1859 | 2065 | * @param string $filename AXMLS schema file |
| 1860 | 2066 | * @return string Schema version number or FALSE on error |
| 1861 | 2067 | */ |
| 1862 | - function SchemaFileVersion( $filename ) { |
|
| 2068 | + function SchemaFileVersion( $filename ) |
|
| 2069 | + { |
|
| 1863 | 2070 | // Open the file |
| 1864 | - if( !($fp = fopen( $filename, 'r' )) ) { |
|
| 2071 | + if( !($fp = fopen( $filename, 'r' )) ) |
|
| 2072 | + { |
|
| 1865 | 2073 | // die( 'Unable to open file' ); |
| 1866 | 2074 | return FALSE; |
| 1867 | 2075 | } |
| 1868 | 2076 | |
| 1869 | 2077 | // Process the file |
| 1870 | - while( $data = fread( $fp, 4096 ) ) { |
|
| 1871 | - if( preg_match( $this->versionRegex, $data, $matches ) ) { |
|
| 2078 | + while( $data = fread( $fp, 4096 ) ) |
|
| 2079 | + { |
|
| 2080 | + if( preg_match( $this->versionRegex, $data, $matches ) ) |
|
| 2081 | + { |
|
| 1872 | 2082 | return !empty( $matches[2] ) ? $matches[2] : XMLS_DEFAULT_SCHEMA_VERSION; |
| 1873 | 2083 | } |
| 1874 | 2084 | } |
@@ -1885,12 +2095,15 @@ discard block |
||
| 1885 | 2095 | * @param string $xmlstring XML schema string |
| 1886 | 2096 | * @return string Schema version number or FALSE on error |
| 1887 | 2097 | */ |
| 1888 | - function SchemaStringVersion( $xmlstring ) { |
|
| 1889 | - if( !is_string( $xmlstring ) OR empty( $xmlstring ) ) { |
|
| 2098 | + function SchemaStringVersion( $xmlstring ) |
|
| 2099 | + { |
|
| 2100 | + if( !is_string( $xmlstring ) OR empty( $xmlstring ) ) |
|
| 2101 | + { |
|
| 1890 | 2102 | return FALSE; |
| 1891 | 2103 | } |
| 1892 | 2104 | |
| 1893 | - if( preg_match( $this->versionRegex, $xmlstring, $matches ) ) { |
|
| 2105 | + if( preg_match( $this->versionRegex, $xmlstring, $matches ) ) |
|
| 2106 | + { |
|
| 1894 | 2107 | return !empty( $matches[2] ) ? $matches[2] : XMLS_DEFAULT_SCHEMA_VERSION; |
| 1895 | 2108 | } |
| 1896 | 2109 | |
@@ -1907,14 +2120,17 @@ discard block |
||
| 1907 | 2120 | * @param boolean $data Include data in schema dump |
| 1908 | 2121 | * @return string Generated XML schema |
| 1909 | 2122 | */ |
| 1910 | - function ExtractSchema( $data = FALSE ) { |
|
| 2123 | + function ExtractSchema( $data = FALSE ) |
|
| 2124 | + { |
|
| 1911 | 2125 | $old_mode = $this->db->SetFetchMode( ADODB_FETCH_NUM ); |
| 1912 | 2126 | |
| 1913 | 2127 | $schema = '<?xml version="1.0"?>' . "\n" |
| 1914 | 2128 | . '<schema version="' . $this->schemaVersion . '">' . "\n"; |
| 1915 | 2129 | |
| 1916 | - if( is_array( $tables = $this->db->MetaTables( 'TABLES' ) ) ) { |
|
| 1917 | - foreach( $tables as $table ) { |
|
| 2130 | + if( is_array( $tables = $this->db->MetaTables( 'TABLES' ) ) ) |
|
| 2131 | + { |
|
| 2132 | + foreach( $tables as $table ) |
|
| 2133 | + { |
|
| 1918 | 2134 | $schema .= ' <table name="' . $table . '">' . "\n"; |
| 1919 | 2135 | |
| 1920 | 2136 | // grab details from database |
@@ -1922,26 +2138,34 @@ discard block |
||
| 1922 | 2138 | $fields = $this->db->MetaColumns( $table ); |
| 1923 | 2139 | $indexes = $this->db->MetaIndexes( $table ); |
| 1924 | 2140 | |
| 1925 | - if( is_array( $fields ) ) { |
|
| 1926 | - foreach( $fields as $details ) { |
|
| 2141 | + if( is_array( $fields ) ) |
|
| 2142 | + { |
|
| 2143 | + foreach( $fields as $details ) |
|
| 2144 | + { |
|
| 1927 | 2145 | $extra = ''; |
| 1928 | 2146 | $content = array(); |
| 1929 | 2147 | |
| 1930 | - if( $details->max_length > 0 ) { |
|
| 2148 | + if( $details->max_length > 0 ) |
|
| 2149 | + { |
|
| 1931 | 2150 | $extra .= ' size="' . $details->max_length . '"'; |
| 1932 | 2151 | } |
| 1933 | 2152 | |
| 1934 | - if( $details->primary_key ) { |
|
| 2153 | + if( $details->primary_key ) |
|
| 2154 | + { |
|
| 1935 | 2155 | $content[] = '<KEY/>'; |
| 1936 | - } elseif( $details->not_null ) { |
|
| 2156 | + } |
|
| 2157 | + elseif( $details->not_null ) |
|
| 2158 | + { |
|
| 1937 | 2159 | $content[] = '<NOTNULL/>'; |
| 1938 | 2160 | } |
| 1939 | 2161 | |
| 1940 | - if( $details->has_default ) { |
|
| 2162 | + if( $details->has_default ) |
|
| 2163 | + { |
|
| 1941 | 2164 | $content[] = '<DEFAULT value="' . $details->default_value . '"/>'; |
| 1942 | 2165 | } |
| 1943 | 2166 | |
| 1944 | - if( $details->auto_increment ) { |
|
| 2167 | + if( $details->auto_increment ) |
|
| 2168 | + { |
|
| 1945 | 2169 | $content[] = '<AUTOINCREMENT/>'; |
| 1946 | 2170 | } |
| 1947 | 2171 | |
@@ -1952,7 +2176,8 @@ discard block |
||
| 1952 | 2176 | |
| 1953 | 2177 | $schema .= ' <field name="' . $details->name . '" type="' . $type . '"' . $extra . '>'; |
| 1954 | 2178 | |
| 1955 | - if( !empty( $content ) ) { |
|
| 2179 | + if( !empty( $content ) ) |
|
| 2180 | + { |
|
| 1956 | 2181 | $schema .= "\n " . implode( "\n ", $content ) . "\n "; |
| 1957 | 2182 | } |
| 1958 | 2183 | |
@@ -1960,15 +2185,19 @@ discard block |
||
| 1960 | 2185 | } |
| 1961 | 2186 | } |
| 1962 | 2187 | |
| 1963 | - if( is_array( $indexes ) ) { |
|
| 1964 | - foreach( $indexes as $index => $details ) { |
|
| 2188 | + if( is_array( $indexes ) ) |
|
| 2189 | + { |
|
| 2190 | + foreach( $indexes as $index => $details ) |
|
| 2191 | + { |
|
| 1965 | 2192 | $schema .= ' <index name="' . $index . '">' . "\n"; |
| 1966 | 2193 | |
| 1967 | - if( $details['unique'] ) { |
|
| 2194 | + if( $details['unique'] ) |
|
| 2195 | + { |
|
| 1968 | 2196 | $schema .= ' <UNIQUE/>' . "\n"; |
| 1969 | 2197 | } |
| 1970 | 2198 | |
| 1971 | - foreach( $details['columns'] as $column ) { |
|
| 2199 | + foreach( $details['columns'] as $column ) |
|
| 2200 | + { |
|
| 1972 | 2201 | $schema .= ' <col>' . $column . '</col>' . "\n"; |
| 1973 | 2202 | } |
| 1974 | 2203 | |
@@ -1976,14 +2205,18 @@ discard block |
||
| 1976 | 2205 | } |
| 1977 | 2206 | } |
| 1978 | 2207 | |
| 1979 | - if( $data ) { |
|
| 2208 | + if( $data ) |
|
| 2209 | + { |
|
| 1980 | 2210 | $rs = $this->db->Execute( 'SELECT * FROM ' . $table ); |
| 1981 | 2211 | |
| 1982 | - if( is_object( $rs ) ) { |
|
| 2212 | + if( is_object( $rs ) ) |
|
| 2213 | + { |
|
| 1983 | 2214 | $schema .= ' <data>' . "\n"; |
| 1984 | 2215 | |
| 1985 | - while( $row = $rs->FetchRow() ) { |
|
| 1986 | - foreach( $row as $key => $val ) { |
|
| 2216 | + while( $row = $rs->FetchRow() ) |
|
| 2217 | + { |
|
| 2218 | + foreach( $row as $key => $val ) |
|
| 2219 | + { |
|
| 1987 | 2220 | $row[$key] = htmlentities($val); |
| 1988 | 2221 | } |
| 1989 | 2222 | |
@@ -2014,8 +2247,10 @@ discard block |
||
| 2014 | 2247 | * @param boolean $underscore If TRUE, automatically append an underscore character to the prefix. |
| 2015 | 2248 | * @return boolean TRUE if successful, else FALSE |
| 2016 | 2249 | */ |
| 2017 | - function SetPrefix( $prefix = '', $underscore = TRUE ) { |
|
| 2018 | - switch( TRUE ) { |
|
| 2250 | + function SetPrefix( $prefix = '', $underscore = TRUE ) |
|
| 2251 | + { |
|
| 2252 | + switch( TRUE ) |
|
| 2253 | + { |
|
| 2019 | 2254 | // clear prefix |
| 2020 | 2255 | case empty( $prefix ): |
| 2021 | 2256 | logMsg( 'Cleared prefix' ); |
@@ -2029,7 +2264,8 @@ discard block |
||
| 2029 | 2264 | return FALSE; |
| 2030 | 2265 | } |
| 2031 | 2266 | |
| 2032 | - if( $underscore AND substr( $prefix, -1 ) != '_' ) { |
|
| 2267 | + if( $underscore AND substr( $prefix, -1 ) != '_' ) |
|
| 2268 | + { |
|
| 2033 | 2269 | $prefix .= '_'; |
| 2034 | 2270 | } |
| 2035 | 2271 | |
@@ -2047,9 +2283,11 @@ discard block |
||
| 2047 | 2283 | * |
| 2048 | 2284 | * @access private |
| 2049 | 2285 | */ |
| 2050 | - function prefix( $name = '' ) { |
|
| 2286 | + function prefix( $name = '' ) |
|
| 2287 | + { |
|
| 2051 | 2288 | // if prefix is set |
| 2052 | - if( !empty( $this->objectPrefix ) ) { |
|
| 2289 | + if( !empty( $this->objectPrefix ) ) |
|
| 2290 | + { |
|
| 2053 | 2291 | // Prepend the object prefix to the table name |
| 2054 | 2292 | // prepend after quote if used |
| 2055 | 2293 | return preg_replace( '/^(`?)(.+)$/', '$1' . $this->objectPrefix . '$2', $name ); |
@@ -2067,13 +2305,17 @@ discard block |
||
| 2067 | 2305 | * |
| 2068 | 2306 | * @access private |
| 2069 | 2307 | */ |
| 2070 | - function supportedPlatform( $platform = NULL ) { |
|
| 2308 | + function supportedPlatform( $platform = NULL ) |
|
| 2309 | + { |
|
| 2071 | 2310 | $regex = '/^(\w*\|)*' . $this->db->databaseType . '(\|\w*)*$/'; |
| 2072 | 2311 | |
| 2073 | - if( !isset( $platform ) OR preg_match( $regex, $platform ) ) { |
|
| 2312 | + if( !isset( $platform ) OR preg_match( $regex, $platform ) ) |
|
| 2313 | + { |
|
| 2074 | 2314 | logMsg( "Platform $platform is supported" ); |
| 2075 | 2315 | return TRUE; |
| 2076 | - } else { |
|
| 2316 | + } |
|
| 2317 | + else |
|
| 2318 | + { |
|
| 2077 | 2319 | logMsg( "Platform $platform is NOT supported" ); |
| 2078 | 2320 | return FALSE; |
| 2079 | 2321 | } |
@@ -2084,7 +2326,8 @@ discard block |
||
| 2084 | 2326 | * |
| 2085 | 2327 | * @access private |
| 2086 | 2328 | */ |
| 2087 | - function clearSQL() { |
|
| 2329 | + function clearSQL() |
|
| 2330 | + { |
|
| 2088 | 2331 | $this->sqlArray = array(); |
| 2089 | 2332 | } |
| 2090 | 2333 | |
@@ -2096,27 +2339,34 @@ discard block |
||
| 2096 | 2339 | * |
| 2097 | 2340 | * @access private |
| 2098 | 2341 | */ |
| 2099 | - function addSQL( $sql = NULL ) { |
|
| 2100 | - if( is_array( $sql ) ) { |
|
| 2101 | - foreach( $sql as $line ) { |
|
| 2342 | + function addSQL( $sql = NULL ) |
|
| 2343 | + { |
|
| 2344 | + if( is_array( $sql ) ) |
|
| 2345 | + { |
|
| 2346 | + foreach( $sql as $line ) |
|
| 2347 | + { |
|
| 2102 | 2348 | $this->addSQL( $line ); |
| 2103 | 2349 | } |
| 2104 | 2350 | |
| 2105 | 2351 | return TRUE; |
| 2106 | 2352 | } |
| 2107 | 2353 | |
| 2108 | - if( is_string( $sql ) ) { |
|
| 2354 | + if( is_string( $sql ) ) |
|
| 2355 | + { |
|
| 2109 | 2356 | $this->sqlArray[] = $sql; |
| 2110 | 2357 | |
| 2111 | 2358 | // if executeInline is enabled, and either no errors have occurred or continueOnError is enabled, execute SQL. |
| 2112 | - if( $this->ExecuteInline() && ( $this->success == 2 || $this->ContinueOnError() ) ) { |
|
| 2359 | + if( $this->ExecuteInline() && ( $this->success == 2 || $this->ContinueOnError() ) ) |
|
| 2360 | + { |
|
| 2113 | 2361 | $saved = $this->db->debug; |
| 2114 | 2362 | $this->db->debug = $this->debug; |
| 2115 | 2363 | $ok = $this->db->Execute( $sql ); |
| 2116 | 2364 | $this->db->debug = $saved; |
| 2117 | 2365 | |
| 2118 | - if( !$ok ) { |
|
| 2119 | - if( $this->debug ) { |
|
| 2366 | + if( !$ok ) |
|
| 2367 | + { |
|
| 2368 | + if( $this->debug ) |
|
| 2369 | + { |
|
| 2120 | 2370 | ADOConnection::outp( $this->db->ErrorMsg() ); |
| 2121 | 2371 | } |
| 2122 | 2372 | |
@@ -2138,16 +2388,20 @@ discard block |
||
| 2138 | 2388 | * |
| 2139 | 2389 | * @access private |
| 2140 | 2390 | */ |
| 2141 | - function getSQL( $format = NULL, $sqlArray = NULL ) { |
|
| 2142 | - if( !is_array( $sqlArray ) ) { |
|
| 2391 | + function getSQL( $format = NULL, $sqlArray = NULL ) |
|
| 2392 | + { |
|
| 2393 | + if( !is_array( $sqlArray ) ) |
|
| 2394 | + { |
|
| 2143 | 2395 | $sqlArray = $this->sqlArray; |
| 2144 | 2396 | } |
| 2145 | 2397 | |
| 2146 | - if( !is_array( $sqlArray ) ) { |
|
| 2398 | + if( !is_array( $sqlArray ) ) |
|
| 2399 | + { |
|
| 2147 | 2400 | return FALSE; |
| 2148 | 2401 | } |
| 2149 | 2402 | |
| 2150 | - switch( strtolower( $format ) ) { |
|
| 2403 | + switch( strtolower( $format ) ) |
|
| 2404 | + { |
|
| 2151 | 2405 | case 'string': |
| 2152 | 2406 | case 'text': |
| 2153 | 2407 | return !empty( $sqlArray ) ? implode( ";\n\n", $sqlArray ) . ';' : ''; |
@@ -2164,7 +2418,8 @@ discard block |
||
| 2164 | 2418 | * Call this method to clean up after an adoSchema object that is no longer in use. |
| 2165 | 2419 | * @deprecated adoSchema now cleans up automatically. |
| 2166 | 2420 | */ |
| 2167 | - function Destroy() { |
|
| 2421 | + function Destroy() |
|
| 2422 | + { |
|
| 2168 | 2423 | set_magic_quotes_runtime( $this->mgq ); |
| 2169 | 2424 | unset( $this ); |
| 2170 | 2425 | } |
@@ -2175,15 +2430,19 @@ discard block |
||
| 2175 | 2430 | * |
| 2176 | 2431 | * @access private |
| 2177 | 2432 | */ |
| 2178 | -function logMsg( $msg, $title = NULL, $force = FALSE ) { |
|
| 2179 | - if( XMLS_DEBUG or $force ) { |
|
| 2433 | +function logMsg( $msg, $title = NULL, $force = FALSE ) |
|
| 2434 | +{ |
|
| 2435 | + if( XMLS_DEBUG or $force ) |
|
| 2436 | + { |
|
| 2180 | 2437 | echo '<pre>'; |
| 2181 | 2438 | |
| 2182 | - if( isset( $title ) ) { |
|
| 2439 | + if( isset( $title ) ) |
|
| 2440 | + { |
|
| 2183 | 2441 | echo '<h3>' . htmlentities( $title ) . '</h3>'; |
| 2184 | 2442 | } |
| 2185 | 2443 | |
| 2186 | - if( is_object( $this ) ) { |
|
| 2444 | + if( is_object( $this ) ) |
|
| 2445 | + { |
|
| 2187 | 2446 | echo '[' . get_class( $this ) . '] '; |
| 2188 | 2447 | } |
| 2189 | 2448 | |
@@ -250,12 +250,12 @@ discard block |
||
| 250 | 250 | |
| 251 | 251 | switch( $this->currentElement ) { |
| 252 | 252 | case 'INDEX': |
| 253 | - if( !isset( $attributes['PLATFORM'] ) OR $this->supportedPlatform( $attributes['PLATFORM'] ) ) { |
|
| 253 | + if( !isset( $attributes['PLATFORM'] ) or $this->supportedPlatform( $attributes['PLATFORM'] ) ) { |
|
| 254 | 254 | xml_set_object( $parser, $this->addIndex( $attributes ) ); |
| 255 | 255 | } |
| 256 | 256 | break; |
| 257 | 257 | case 'DATA': |
| 258 | - if( !isset( $attributes['PLATFORM'] ) OR $this->supportedPlatform( $attributes['PLATFORM'] ) ) { |
|
| 258 | + if( !isset( $attributes['PLATFORM'] ) or $this->supportedPlatform( $attributes['PLATFORM'] ) ) { |
|
| 259 | 259 | xml_set_object( $parser, $this->addData( $attributes ) ); |
| 260 | 260 | } |
| 261 | 261 | break; |
@@ -537,7 +537,7 @@ discard block |
||
| 537 | 537 | logMsg( end( $sql ), 'Generated CreateTableSQL' ); |
| 538 | 538 | } else { |
| 539 | 539 | // Upgrade an existing table |
| 540 | - logMsg( "Upgrading {$this->name} using '{$xmls->upgrade}'" ); |
|
| 540 | + logMsg( "upgrading {$this->name} using '{$xmls->upgrade}'" ); |
|
| 541 | 541 | switch( $xmls->upgrade ) { |
| 542 | 542 | // Use ChangeTableSQL |
| 543 | 543 | case 'ALTER': |
@@ -1007,7 +1007,7 @@ discard block |
||
| 1007 | 1007 | // Create a new query in a SQL queryset. |
| 1008 | 1008 | // Ignore this query set if a platform is specified and it's different than the |
| 1009 | 1009 | // current connection platform. |
| 1010 | - if( !isset( $attributes['PLATFORM'] ) OR $this->supportedPlatform( $attributes['PLATFORM'] ) ) { |
|
| 1010 | + if( !isset( $attributes['PLATFORM'] ) or $this->supportedPlatform( $attributes['PLATFORM'] ) ) { |
|
| 1011 | 1011 | $this->newQuery(); |
| 1012 | 1012 | } else { |
| 1013 | 1013 | $this->discardQuery(); |
@@ -1084,7 +1084,7 @@ discard block |
||
| 1084 | 1084 | * @return string SQL query string. |
| 1085 | 1085 | */ |
| 1086 | 1086 | function buildQuery( $sql = NULL ) { |
| 1087 | - if( !isset( $this->query ) OR empty( $sql ) ) { |
|
| 1087 | + if( !isset( $this->query ) or empty( $sql ) ) { |
|
| 1088 | 1088 | return FALSE; |
| 1089 | 1089 | } |
| 1090 | 1090 | |
@@ -1134,7 +1134,7 @@ discard block |
||
| 1134 | 1134 | case 'MANUAL': |
| 1135 | 1135 | // If prefixKey is set and has a value then we use it to override the default constant XMLS_PREFIX. |
| 1136 | 1136 | // If prefixKey is not set, we use the default constant XMLS_PREFIX |
| 1137 | - if( isset( $this->prefixKey ) AND( $this->prefixKey !== '' ) ) { |
|
| 1137 | + if( isset( $this->prefixKey ) and( $this->prefixKey !== '' ) ) { |
|
| 1138 | 1138 | // Enable prefix override |
| 1139 | 1139 | $query = str_replace( $this->prefixKey, $xmls->objectPrefix, $query ); |
| 1140 | 1140 | } else { |
@@ -1464,7 +1464,7 @@ discard block |
||
| 1464 | 1464 | * @return array Array of SQL queries, ready to execute. |
| 1465 | 1465 | */ |
| 1466 | 1466 | function ParseSchemaString( $xmlstring, $returnSchema = FALSE ) { |
| 1467 | - if( !is_string( $xmlstring ) OR empty( $xmlstring ) ) { |
|
| 1467 | + if( !is_string( $xmlstring ) or empty( $xmlstring ) ) { |
|
| 1468 | 1468 | return FALSE; |
| 1469 | 1469 | } |
| 1470 | 1470 | |
@@ -1632,7 +1632,7 @@ discard block |
||
| 1632 | 1632 | xml_set_object( $parser, $this->obj ); |
| 1633 | 1633 | break; |
| 1634 | 1634 | case 'SQL': |
| 1635 | - if( !isset( $attributes['PLATFORM'] ) OR $this->supportedPlatform( $attributes['PLATFORM'] ) ) { |
|
| 1635 | + if( !isset( $attributes['PLATFORM'] ) or $this->supportedPlatform( $attributes['PLATFORM'] ) ) { |
|
| 1636 | 1636 | $this->obj = new dbQuerySet( $this, $attributes ); |
| 1637 | 1637 | xml_set_object( $parser, $this->obj ); |
| 1638 | 1638 | } |
@@ -1694,7 +1694,7 @@ discard block |
||
| 1694 | 1694 | $result = $this->TransformSchema( $schema, 'convert-' . $version . '-' . $newVersion); |
| 1695 | 1695 | } |
| 1696 | 1696 | |
| 1697 | - if( is_string( $result ) AND is_string( $newFile ) AND ( $fp = fopen( $newFile, 'w' ) ) ) { |
|
| 1697 | + if( is_string( $result ) and is_string( $newFile ) and ( $fp = fopen( $newFile, 'w' ) ) ) { |
|
| 1698 | 1698 | fwrite( $fp, $result ); |
| 1699 | 1699 | fclose( $fp ); |
| 1700 | 1700 | } |
@@ -1740,7 +1740,7 @@ discard block |
||
| 1740 | 1740 | $result = $this->TransformSchema( $filename, 'convert-' . $version . '-' . $newVersion, 'file' ); |
| 1741 | 1741 | } |
| 1742 | 1742 | |
| 1743 | - if( is_string( $result ) AND is_string( $newFile ) AND ( $fp = fopen( $newFile, 'w' ) ) ) { |
|
| 1743 | + if( is_string( $result ) and is_string( $newFile ) and ( $fp = fopen( $newFile, 'w' ) ) ) { |
|
| 1744 | 1744 | fwrite( $fp, $result ); |
| 1745 | 1745 | fclose( $fp ); |
| 1746 | 1746 | } |
@@ -1886,7 +1886,7 @@ discard block |
||
| 1886 | 1886 | * @return string Schema version number or FALSE on error |
| 1887 | 1887 | */ |
| 1888 | 1888 | function SchemaStringVersion( $xmlstring ) { |
| 1889 | - if( !is_string( $xmlstring ) OR empty( $xmlstring ) ) { |
|
| 1889 | + if( !is_string( $xmlstring ) or empty( $xmlstring ) ) { |
|
| 1890 | 1890 | return FALSE; |
| 1891 | 1891 | } |
| 1892 | 1892 | |
@@ -2029,7 +2029,7 @@ discard block |
||
| 2029 | 2029 | return FALSE; |
| 2030 | 2030 | } |
| 2031 | 2031 | |
| 2032 | - if( $underscore AND substr( $prefix, -1 ) != '_' ) { |
|
| 2032 | + if( $underscore and substr( $prefix, -1 ) != '_' ) { |
|
| 2033 | 2033 | $prefix .= '_'; |
| 2034 | 2034 | } |
| 2035 | 2035 | |
@@ -2070,11 +2070,11 @@ discard block |
||
| 2070 | 2070 | function supportedPlatform( $platform = NULL ) { |
| 2071 | 2071 | $regex = '/^(\w*\|)*' . $this->db->databaseType . '(\|\w*)*$/'; |
| 2072 | 2072 | |
| 2073 | - if( !isset( $platform ) OR preg_match( $regex, $platform ) ) { |
|
| 2074 | - logMsg( "Platform $platform is supported" ); |
|
| 2073 | + if( !isset( $platform ) or preg_match( $regex, $platform ) ) { |
|
| 2074 | + logMsg( "platform $platform is supported" ); |
|
| 2075 | 2075 | return TRUE; |
| 2076 | 2076 | } else { |
| 2077 | - logMsg( "Platform $platform is NOT supported" ); |
|
| 2077 | + logMsg( "platform $platform is NOT supported" ); |
|
| 2078 | 2078 | return FALSE; |
| 2079 | 2079 | } |
| 2080 | 2080 | } |
@@ -86,6 +86,9 @@ discard block |
||
| 86 | 86 | } |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | + /** |
|
| 90 | + * @param string $meta |
|
| 91 | + */ |
|
| 89 | 92 | function ActualType($meta) |
| 90 | 93 | { |
| 91 | 94 | switch($meta) { |
@@ -261,6 +264,9 @@ discard block |
||
| 261 | 264 | return $aSql; |
| 262 | 265 | } |
| 263 | 266 | |
| 267 | + /** |
|
| 268 | + * @param string $tabname |
|
| 269 | + */ |
|
| 264 | 270 | function DropTableSQL($tabname) |
| 265 | 271 | { |
| 266 | 272 | $sql = ADODB_DataDict::DropTableSQL($tabname); |
@@ -7,8 +7,7 @@ |
||
| 7 | 7 | the BSD license will take precedence. |
| 8 | 8 | |
| 9 | 9 | Set tabs to 4 for best viewing. |
| 10 | - |
|
| 11 | -*/ |
|
| 10 | + */ |
|
| 12 | 11 | |
| 13 | 12 | // security - hide paths |
| 14 | 13 | if (!defined('ADODB_DIR')) die(); |
@@ -89,29 +89,29 @@ |
||
| 89 | 89 | function ActualType($meta) |
| 90 | 90 | { |
| 91 | 91 | switch($meta) { |
| 92 | - case 'C': return 'VARCHAR'; |
|
| 93 | - case 'XL': |
|
| 94 | - case 'X': return 'TEXT'; |
|
| 92 | + case 'C': return 'VARCHAR'; |
|
| 93 | + case 'XL': |
|
| 94 | + case 'X': return 'TEXT'; |
|
| 95 | 95 | |
| 96 | - case 'C2': return 'VARCHAR'; |
|
| 97 | - case 'X2': return 'TEXT'; |
|
| 96 | + case 'C2': return 'VARCHAR'; |
|
| 97 | + case 'X2': return 'TEXT'; |
|
| 98 | 98 | |
| 99 | - case 'B': return 'BYTEA'; |
|
| 99 | + case 'B': return 'BYTEA'; |
|
| 100 | 100 | |
| 101 | - case 'D': return 'DATE'; |
|
| 102 | - case 'T': return 'TIMESTAMP'; |
|
| 101 | + case 'D': return 'DATE'; |
|
| 102 | + case 'T': return 'TIMESTAMP'; |
|
| 103 | 103 | |
| 104 | - case 'L': return 'BOOLEAN'; |
|
| 105 | - case 'I': return 'INTEGER'; |
|
| 106 | - case 'I1': return 'SMALLINT'; |
|
| 107 | - case 'I2': return 'INT2'; |
|
| 108 | - case 'I4': return 'INT4'; |
|
| 109 | - case 'I8': return 'INT8'; |
|
| 104 | + case 'L': return 'BOOLEAN'; |
|
| 105 | + case 'I': return 'INTEGER'; |
|
| 106 | + case 'I1': return 'SMALLINT'; |
|
| 107 | + case 'I2': return 'INT2'; |
|
| 108 | + case 'I4': return 'INT4'; |
|
| 109 | + case 'I8': return 'INT8'; |
|
| 110 | 110 | |
| 111 | - case 'F': return 'FLOAT8'; |
|
| 112 | - case 'N': return 'NUMERIC'; |
|
| 113 | - default: |
|
| 114 | - return $meta; |
|
| 111 | + case 'F': return 'FLOAT8'; |
|
| 112 | + case 'N': return 'NUMERIC'; |
|
| 113 | + default: |
|
| 114 | + return $meta; |
|
| 115 | 115 | } |
| 116 | 116 | } |
| 117 | 117 | |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | var $quote = '"'; |
| 23 | 23 | var $renameTable = 'ALTER TABLE %s RENAME TO %s'; // at least since 7.1 |
| 24 | 24 | |
| 25 | - function MetaType($t,$len=-1,$fieldobj=false) |
|
| 25 | + function MetaType($t, $len = -1, $fieldobj = false) |
|
| 26 | 26 | { |
| 27 | 27 | if (is_object($t)) { |
| 28 | 28 | $fieldobj = $t; |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | $len = $fieldobj->max_length; |
| 31 | 31 | } |
| 32 | 32 | $is_serial = is_object($fieldobj) && $fieldobj->primary_key && $fieldobj->unique && |
| 33 | - $fieldobj->has_default && substr($fieldobj->default_value,0,8) == 'nextval('; |
|
| 33 | + $fieldobj->has_default && substr($fieldobj->default_value, 0, 8) == 'nextval('; |
|
| 34 | 34 | |
| 35 | 35 | switch (strtoupper($t)) { |
| 36 | 36 | case 'INTERVAL': |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | |
| 89 | 89 | function ActualType($meta) |
| 90 | 90 | { |
| 91 | - switch($meta) { |
|
| 91 | + switch ($meta) { |
|
| 92 | 92 | case 'C': return 'VARCHAR'; |
| 93 | 93 | case 'XL': |
| 94 | 94 | case 'X': return 'TEXT'; |
@@ -126,24 +126,24 @@ discard block |
||
| 126 | 126 | */ |
| 127 | 127 | function AddColumnSQL($tabname, $flds) |
| 128 | 128 | { |
| 129 | - $tabname = $this->TableName ($tabname); |
|
| 129 | + $tabname = $this->TableName($tabname); |
|
| 130 | 130 | $sql = array(); |
| 131 | - list($lines,$pkey) = $this->_GenFields($flds); |
|
| 132 | - $alter = 'ALTER TABLE ' . $tabname . $this->addCol . ' '; |
|
| 133 | - foreach($lines as $v) { |
|
| 134 | - if (($not_null = preg_match('/NOT NULL/i',$v))) { |
|
| 135 | - $v = preg_replace('/NOT NULL/i','',$v); |
|
| 131 | + list($lines, $pkey) = $this->_GenFields($flds); |
|
| 132 | + $alter = 'ALTER TABLE '.$tabname.$this->addCol.' '; |
|
| 133 | + foreach ($lines as $v) { |
|
| 134 | + if (($not_null = preg_match('/NOT NULL/i', $v))) { |
|
| 135 | + $v = preg_replace('/NOT NULL/i', '', $v); |
|
| 136 | 136 | } |
| 137 | - if (preg_match('/^([^ ]+) .*DEFAULT ([^ ]+)/',$v,$matches)) { |
|
| 138 | - list(,$colname,$default) = $matches; |
|
| 139 | - $sql[] = $alter . str_replace('DEFAULT '.$default,'',$v); |
|
| 137 | + if (preg_match('/^([^ ]+) .*DEFAULT ([^ ]+)/', $v, $matches)) { |
|
| 138 | + list(,$colname, $default) = $matches; |
|
| 139 | + $sql[] = $alter.str_replace('DEFAULT '.$default, '', $v); |
|
| 140 | 140 | $sql[] = 'UPDATE '.$tabname.' SET '.$colname.'='.$default; |
| 141 | - $sql[] = 'ALTER TABLE '.$tabname.' ALTER COLUMN '.$colname.' SET DEFAULT ' . $default; |
|
| 141 | + $sql[] = 'ALTER TABLE '.$tabname.' ALTER COLUMN '.$colname.' SET DEFAULT '.$default; |
|
| 142 | 142 | } else { |
| 143 | - $sql[] = $alter . $v; |
|
| 143 | + $sql[] = $alter.$v; |
|
| 144 | 144 | } |
| 145 | 145 | if ($not_null) { |
| 146 | - list($colname) = explode(' ',$v); |
|
| 146 | + list($colname) = explode(' ', $v); |
|
| 147 | 147 | $sql[] = 'ALTER TABLE '.$tabname.' ALTER COLUMN '.$colname.' SET NOT NULL'; |
| 148 | 148 | } |
| 149 | 149 | } |
@@ -161,13 +161,13 @@ discard block |
||
| 161 | 161 | * @param array/ $tableoptions options for the new table see CreateTableSQL, default '' |
| 162 | 162 | * @return array with SQL strings |
| 163 | 163 | */ |
| 164 | - function AlterColumnSQL($tabname, $flds, $tableflds='',$tableoptions='') |
|
| 164 | + function AlterColumnSQL($tabname, $flds, $tableflds = '', $tableoptions = '') |
|
| 165 | 165 | { |
| 166 | 166 | if (!$tableflds) { |
| 167 | 167 | if ($this->debug) ADOConnection::outp("AlterColumnSQL needs a complete table-definiton for PostgreSQL"); |
| 168 | 168 | return array(); |
| 169 | 169 | } |
| 170 | - return $this->_recreate_copy_table($tabname,False,$tableflds,$tableoptions); |
|
| 170 | + return $this->_recreate_copy_table($tabname, False, $tableflds, $tableoptions); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | /** |
@@ -181,9 +181,9 @@ discard block |
||
| 181 | 181 | * @param array/ $tableoptions options for the new table see CreateTableSQL, default '' |
| 182 | 182 | * @return array with SQL strings |
| 183 | 183 | */ |
| 184 | - function DropColumnSQL($tabname, $flds, $tableflds='',$tableoptions='') |
|
| 184 | + function DropColumnSQL($tabname, $flds, $tableflds = '', $tableoptions = '') |
|
| 185 | 185 | { |
| 186 | - $has_drop_column = 7.3 <= (float) @$this->serverInfo['version']; |
|
| 186 | + $has_drop_column = 7.3 <= (float)@$this->serverInfo['version']; |
|
| 187 | 187 | if (!$has_drop_column && !$tableflds) { |
| 188 | 188 | if ($this->debug) ADOConnection::outp("DropColumnSQL needs complete table-definiton for PostgreSQL < 7.3"); |
| 189 | 189 | return array(); |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | if ($has_drop_column) { |
| 192 | 192 | return ADODB_DataDict::DropColumnSQL($tabname, $flds); |
| 193 | 193 | } |
| 194 | - return $this->_recreate_copy_table($tabname,$flds,$tableflds,$tableoptions); |
|
| 194 | + return $this->_recreate_copy_table($tabname, $flds, $tableflds, $tableoptions); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | /** |
@@ -206,17 +206,17 @@ discard block |
||
| 206 | 206 | * @param array/string $tableoptions options for the new table see CreateTableSQL, default '' |
| 207 | 207 | * @return array with SQL strings |
| 208 | 208 | */ |
| 209 | - function _recreate_copy_table($tabname,$dropflds,$tableflds,$tableoptions='') |
|
| 209 | + function _recreate_copy_table($tabname, $dropflds, $tableflds, $tableoptions = '') |
|
| 210 | 210 | { |
| 211 | - if ($dropflds && !is_array($dropflds)) $dropflds = explode(',',$dropflds); |
|
| 211 | + if ($dropflds && !is_array($dropflds)) $dropflds = explode(',', $dropflds); |
|
| 212 | 212 | $copyflds = array(); |
| 213 | - foreach(($meta=$this->MetaColumns($tabname)) as $fld) { |
|
| 214 | - if (!$dropflds || !in_array($fld->name,$dropflds)) { |
|
| 213 | + foreach (($meta = $this->MetaColumns($tabname)) as $fld) { |
|
| 214 | + if (!$dropflds || !in_array($fld->name, $dropflds)) { |
|
| 215 | 215 | // we need to explicit convert varchar to a number to be able to do an AlterColumn of a char column to a nummeric one |
| 216 | - if (preg_match('/'.$fld->name.' (I|I2|I4|I8|N|F)/i',$tableflds,$matches) && |
|
| 217 | - in_array($fld->type,array('varchar','char','text','bytea'))) { |
|
| 216 | + if (preg_match('/'.$fld->name.' (I|I2|I4|I8|N|F)/i', $tableflds, $matches) && |
|
| 217 | + in_array($fld->type, array('varchar', 'char', 'text', 'bytea'))) { |
|
| 218 | 218 | $copyflds[] = "to_number($fld->name,'S9999999999999D99')"; |
| 219 | - } elseif (preg_match('/'.$fld->name.' ([\w]+)/i',$tableflds,$matches) && |
|
| 219 | + } elseif (preg_match('/'.$fld->name.' ([\w]+)/i', $tableflds, $matches) && |
|
| 220 | 220 | strtoupper($fld->type) != ($type = $this->ActualType($matches[1]))) { |
| 221 | 221 | if ($type == 'BYTEA' && $fld->type == 'text') { |
| 222 | 222 | $copyflds[] = "DECODE($fld->name, 'escape')"; |
@@ -230,30 +230,30 @@ discard block |
||
| 230 | 230 | } |
| 231 | 231 | // identify the sequence name and the fld its on |
| 232 | 232 | if ($fld->primary_key && $fld->has_default && |
| 233 | - preg_match("/nextval\('([^']+)'::(text|regclass)\)/",$fld->default_value,$matches)) { |
|
| 233 | + preg_match("/nextval\('([^']+)'::(text|regclass)\)/", $fld->default_value, $matches)) { |
|
| 234 | 234 | $seq_name = $matches[1]; |
| 235 | 235 | $seq_fld = $fld->name; |
| 236 | 236 | } |
| 237 | 237 | } |
| 238 | 238 | } |
| 239 | - $copyflds = implode(', ',$copyflds); |
|
| 239 | + $copyflds = implode(', ', $copyflds); |
|
| 240 | 240 | |
| 241 | 241 | $tempname = $tabname.'_tmp'; |
| 242 | - $aSql[] = 'BEGIN'; // we use a transaction, to make sure not to loose the content of the table |
|
| 242 | + $aSql[] = 'BEGIN'; // we use a transaction, to make sure not to loose the content of the table |
|
| 243 | 243 | $aSql[] = "SELECT * INTO TEMPORARY TABLE $tempname FROM $tabname"; |
| 244 | - $aSql = array_merge($aSql,$this->DropTableSQL($tabname)); |
|
| 245 | - $aSql = array_merge($aSql,$this->CreateTableSQL($tabname,$tableflds,$tableoptions)); |
|
| 244 | + $aSql = array_merge($aSql, $this->DropTableSQL($tabname)); |
|
| 245 | + $aSql = array_merge($aSql, $this->CreateTableSQL($tabname, $tableflds, $tableoptions)); |
|
| 246 | 246 | $aSql[] = "INSERT INTO $tabname SELECT $copyflds FROM $tempname"; |
| 247 | 247 | if ($seq_name && $seq_fld) { // if we have a sequence we need to set it again |
| 248 | - $seq_name = $tabname.'_'.$seq_fld.'_seq'; // has to be the name of the new implicit sequence |
|
| 248 | + $seq_name = $tabname.'_'.$seq_fld.'_seq'; // has to be the name of the new implicit sequence |
|
| 249 | 249 | $aSql[] = "SELECT setval('$seq_name',MAX($seq_fld)) FROM $tabname"; |
| 250 | 250 | } |
| 251 | 251 | $aSql[] = "DROP TABLE $tempname"; |
| 252 | 252 | // recreate the indexes, if they not contain one of the droped columns |
| 253 | - foreach($this->MetaIndexes($tabname) as $idx_name => $idx_data) |
|
| 253 | + foreach ($this->MetaIndexes($tabname) as $idx_name => $idx_data) |
|
| 254 | 254 | { |
| 255 | - if (substr($idx_name,-5) != '_pkey' && (!$dropflds || !count(array_intersect($dropflds,$idx_data['columns'])))) { |
|
| 256 | - $aSql = array_merge($aSql,$this->CreateIndexSQL($idx_name,$tabname,$idx_data['columns'], |
|
| 255 | + if (substr($idx_name, -5) != '_pkey' && (!$dropflds || !count(array_intersect($dropflds, $idx_data['columns'])))) { |
|
| 256 | + $aSql = array_merge($aSql, $this->CreateIndexSQL($idx_name, $tabname, $idx_data['columns'], |
|
| 257 | 257 | $idx_data['unique'] ? array('UNIQUE') : False)); |
| 258 | 258 | } |
| 259 | 259 | } |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | // return string must begin with space |
| 275 | - function _CreateSuffix($fname, &$ftype, $fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned) |
|
| 275 | + function _CreateSuffix($fname, &$ftype, $fnotnull, $fdefault, $fautoinc, $fconstraint, $funsigned) |
|
| 276 | 276 | { |
| 277 | 277 | if ($fautoinc) { |
| 278 | 278 | $ftype = 'SERIAL'; |
@@ -338,29 +338,29 @@ discard block |
||
| 338 | 338 | { |
| 339 | 339 | $sql = array(); |
| 340 | 340 | |
| 341 | - if ( isset($idxoptions['REPLACE']) || isset($idxoptions['DROP']) ) { |
|
| 342 | - $sql[] = sprintf ($this->dropIndex, $idxname, $tabname); |
|
| 343 | - if ( isset($idxoptions['DROP']) ) |
|
| 341 | + if (isset($idxoptions['REPLACE']) || isset($idxoptions['DROP'])) { |
|
| 342 | + $sql[] = sprintf($this->dropIndex, $idxname, $tabname); |
|
| 343 | + if (isset($idxoptions['DROP'])) |
|
| 344 | 344 | return $sql; |
| 345 | 345 | } |
| 346 | 346 | |
| 347 | - if ( empty ($flds) ) { |
|
| 347 | + if (empty ($flds)) { |
|
| 348 | 348 | return $sql; |
| 349 | 349 | } |
| 350 | 350 | |
| 351 | 351 | $unique = isset($idxoptions['UNIQUE']) ? ' UNIQUE' : ''; |
| 352 | 352 | |
| 353 | - $s = 'CREATE' . $unique . ' INDEX ' . $idxname . ' ON ' . $tabname . ' '; |
|
| 353 | + $s = 'CREATE'.$unique.' INDEX '.$idxname.' ON '.$tabname.' '; |
|
| 354 | 354 | |
| 355 | 355 | if (isset($idxoptions['HASH'])) |
| 356 | 356 | $s .= 'USING HASH '; |
| 357 | 357 | |
| 358 | - if ( isset($idxoptions[$this->upperName]) ) |
|
| 358 | + if (isset($idxoptions[$this->upperName])) |
|
| 359 | 359 | $s .= $idxoptions[$this->upperName]; |
| 360 | 360 | |
| 361 | - if ( is_array($flds) ) |
|
| 362 | - $flds = implode(', ',$flds); |
|
| 363 | - $s .= '(' . $flds . ')'; |
|
| 361 | + if (is_array($flds)) |
|
| 362 | + $flds = implode(', ', $flds); |
|
| 363 | + $s .= '('.$flds.')'; |
|
| 364 | 364 | $sql[] = $s; |
| 365 | 365 | |
| 366 | 366 | return $sql; |
@@ -11,9 +11,13 @@ discard block |
||
| 11 | 11 | */ |
| 12 | 12 | |
| 13 | 13 | // security - hide paths |
| 14 | -if (!defined('ADODB_DIR')) die(); |
|
| 14 | +if (!defined('ADODB_DIR')) |
|
| 15 | +{ |
|
| 16 | + die(); |
|
| 17 | +} |
|
| 15 | 18 | |
| 16 | -class ADODB2_postgres extends ADODB_DataDict { |
|
| 19 | +class ADODB2_postgres extends ADODB_DataDict |
|
| 20 | +{ |
|
| 17 | 21 | |
| 18 | 22 | var $databaseType = 'postgres'; |
| 19 | 23 | var $seqField = false; |
@@ -24,7 +28,8 @@ discard block |
||
| 24 | 28 | |
| 25 | 29 | function MetaType($t,$len=-1,$fieldobj=false) |
| 26 | 30 | { |
| 27 | - if (is_object($t)) { |
|
| 31 | + if (is_object($t)) |
|
| 32 | + { |
|
| 28 | 33 | $fieldobj = $t; |
| 29 | 34 | $t = $fieldobj->type; |
| 30 | 35 | $len = $fieldobj->max_length; |
@@ -32,14 +37,18 @@ discard block |
||
| 32 | 37 | $is_serial = is_object($fieldobj) && $fieldobj->primary_key && $fieldobj->unique && |
| 33 | 38 | $fieldobj->has_default && substr($fieldobj->default_value,0,8) == 'nextval('; |
| 34 | 39 | |
| 35 | - switch (strtoupper($t)) { |
|
| 40 | + switch (strtoupper($t)) |
|
| 41 | + { |
|
| 36 | 42 | case 'INTERVAL': |
| 37 | 43 | case 'CHAR': |
| 38 | 44 | case 'CHARACTER': |
| 39 | 45 | case 'VARCHAR': |
| 40 | 46 | case 'NAME': |
| 41 | 47 | case 'BPCHAR': |
| 42 | - if ($len <= $this->blobSize) return 'C'; |
|
| 48 | + if ($len <= $this->blobSize) |
|
| 49 | + { |
|
| 50 | + return 'C'; |
|
| 51 | + } |
|
| 43 | 52 | |
| 44 | 53 | case 'TEXT': |
| 45 | 54 | return 'X'; |
@@ -87,8 +96,9 @@ discard block |
||
| 87 | 96 | } |
| 88 | 97 | |
| 89 | 98 | function ActualType($meta) |
| 90 | - { |
|
| 91 | - switch($meta) { |
|
| 99 | + { |
|
| 100 | + switch($meta) |
|
| 101 | + { |
|
| 92 | 102 | case 'C': return 'VARCHAR'; |
| 93 | 103 | case 'XL': |
| 94 | 104 | case 'X': return 'TEXT'; |
@@ -130,19 +140,25 @@ discard block |
||
| 130 | 140 | $sql = array(); |
| 131 | 141 | list($lines,$pkey) = $this->_GenFields($flds); |
| 132 | 142 | $alter = 'ALTER TABLE ' . $tabname . $this->addCol . ' '; |
| 133 | - foreach($lines as $v) { |
|
| 134 | - if (($not_null = preg_match('/NOT NULL/i',$v))) { |
|
| 143 | + foreach($lines as $v) |
|
| 144 | + { |
|
| 145 | + if (($not_null = preg_match('/NOT NULL/i',$v))) |
|
| 146 | + { |
|
| 135 | 147 | $v = preg_replace('/NOT NULL/i','',$v); |
| 136 | 148 | } |
| 137 | - if (preg_match('/^([^ ]+) .*DEFAULT ([^ ]+)/',$v,$matches)) { |
|
| 149 | + if (preg_match('/^([^ ]+) .*DEFAULT ([^ ]+)/',$v,$matches)) |
|
| 150 | + { |
|
| 138 | 151 | list(,$colname,$default) = $matches; |
| 139 | 152 | $sql[] = $alter . str_replace('DEFAULT '.$default,'',$v); |
| 140 | 153 | $sql[] = 'UPDATE '.$tabname.' SET '.$colname.'='.$default; |
| 141 | 154 | $sql[] = 'ALTER TABLE '.$tabname.' ALTER COLUMN '.$colname.' SET DEFAULT ' . $default; |
| 142 | - } else { |
|
| 155 | + } |
|
| 156 | + else |
|
| 157 | + { |
|
| 143 | 158 | $sql[] = $alter . $v; |
| 144 | 159 | } |
| 145 | - if ($not_null) { |
|
| 160 | + if ($not_null) |
|
| 161 | + { |
|
| 146 | 162 | list($colname) = explode(' ',$v); |
| 147 | 163 | $sql[] = 'ALTER TABLE '.$tabname.' ALTER COLUMN '.$colname.' SET NOT NULL'; |
| 148 | 164 | } |
@@ -163,8 +179,12 @@ discard block |
||
| 163 | 179 | */ |
| 164 | 180 | function AlterColumnSQL($tabname, $flds, $tableflds='',$tableoptions='') |
| 165 | 181 | { |
| 166 | - if (!$tableflds) { |
|
| 167 | - if ($this->debug) ADOConnection::outp("AlterColumnSQL needs a complete table-definiton for PostgreSQL"); |
|
| 182 | + if (!$tableflds) |
|
| 183 | + { |
|
| 184 | + if ($this->debug) |
|
| 185 | + { |
|
| 186 | + ADOConnection::outp("AlterColumnSQL needs a complete table-definiton for PostgreSQL"); |
|
| 187 | + } |
|
| 168 | 188 | return array(); |
| 169 | 189 | } |
| 170 | 190 | return $this->_recreate_copy_table($tabname,False,$tableflds,$tableoptions); |
@@ -184,11 +204,16 @@ discard block |
||
| 184 | 204 | function DropColumnSQL($tabname, $flds, $tableflds='',$tableoptions='') |
| 185 | 205 | { |
| 186 | 206 | $has_drop_column = 7.3 <= (float) @$this->serverInfo['version']; |
| 187 | - if (!$has_drop_column && !$tableflds) { |
|
| 188 | - if ($this->debug) ADOConnection::outp("DropColumnSQL needs complete table-definiton for PostgreSQL < 7.3"); |
|
| 207 | + if (!$has_drop_column && !$tableflds) |
|
| 208 | + { |
|
| 209 | + if ($this->debug) |
|
| 210 | + { |
|
| 211 | + ADOConnection::outp("DropColumnSQL needs complete table-definiton for PostgreSQL < 7.3"); |
|
| 212 | + } |
|
| 189 | 213 | return array(); |
| 190 | 214 | } |
| 191 | - if ($has_drop_column) { |
|
| 215 | + if ($has_drop_column) |
|
| 216 | + { |
|
| 192 | 217 | return ADODB_DataDict::DropColumnSQL($tabname, $flds); |
| 193 | 218 | } |
| 194 | 219 | return $this->_recreate_copy_table($tabname,$flds,$tableflds,$tableoptions); |
@@ -208,29 +233,45 @@ discard block |
||
| 208 | 233 | */ |
| 209 | 234 | function _recreate_copy_table($tabname,$dropflds,$tableflds,$tableoptions='') |
| 210 | 235 | { |
| 211 | - if ($dropflds && !is_array($dropflds)) $dropflds = explode(',',$dropflds); |
|
| 236 | + if ($dropflds && !is_array($dropflds)) |
|
| 237 | + { |
|
| 238 | + $dropflds = explode(',',$dropflds); |
|
| 239 | + } |
|
| 212 | 240 | $copyflds = array(); |
| 213 | - foreach(($meta=$this->MetaColumns($tabname)) as $fld) { |
|
| 214 | - if (!$dropflds || !in_array($fld->name,$dropflds)) { |
|
| 241 | + foreach(($meta=$this->MetaColumns($tabname)) as $fld) |
|
| 242 | + { |
|
| 243 | + if (!$dropflds || !in_array($fld->name,$dropflds)) |
|
| 244 | + { |
|
| 215 | 245 | // we need to explicit convert varchar to a number to be able to do an AlterColumn of a char column to a nummeric one |
| 216 | 246 | if (preg_match('/'.$fld->name.' (I|I2|I4|I8|N|F)/i',$tableflds,$matches) && |
| 217 | - in_array($fld->type,array('varchar','char','text','bytea'))) { |
|
| 247 | + in_array($fld->type,array('varchar','char','text','bytea'))) |
|
| 248 | + { |
|
| 218 | 249 | $copyflds[] = "to_number($fld->name,'S9999999999999D99')"; |
| 219 | - } elseif (preg_match('/'.$fld->name.' ([\w]+)/i',$tableflds,$matches) && |
|
| 220 | - strtoupper($fld->type) != ($type = $this->ActualType($matches[1]))) { |
|
| 221 | - if ($type == 'BYTEA' && $fld->type == 'text') { |
|
| 250 | + } |
|
| 251 | + elseif (preg_match('/'.$fld->name.' ([\w]+)/i',$tableflds,$matches) && |
|
| 252 | + strtoupper($fld->type) != ($type = $this->ActualType($matches[1]))) |
|
| 253 | + { |
|
| 254 | + if ($type == 'BYTEA' && $fld->type == 'text') |
|
| 255 | + { |
|
| 222 | 256 | $copyflds[] = "DECODE($fld->name, 'escape')"; |
| 223 | - } elseif ($fld->type == 'bytea' && $type == 'TEXT') { |
|
| 257 | + } |
|
| 258 | + elseif ($fld->type == 'bytea' && $type == 'TEXT') |
|
| 259 | + { |
|
| 224 | 260 | $copyflds[] = "ENCODE($fld->name, 'escape')"; |
| 225 | - } else { |
|
| 261 | + } |
|
| 262 | + else |
|
| 263 | + { |
|
| 226 | 264 | $copyflds[] = "CAST($fld->name AS $type)"; |
| 227 | 265 | } |
| 228 | - } else { |
|
| 266 | + } |
|
| 267 | + else |
|
| 268 | + { |
|
| 229 | 269 | $copyflds[] = $fld->name; |
| 230 | 270 | } |
| 231 | 271 | // identify the sequence name and the fld its on |
| 232 | 272 | if ($fld->primary_key && $fld->has_default && |
| 233 | - preg_match("/nextval\('([^']+)'::(text|regclass)\)/",$fld->default_value,$matches)) { |
|
| 273 | + preg_match("/nextval\('([^']+)'::(text|regclass)\)/",$fld->default_value,$matches)) |
|
| 274 | + { |
|
| 234 | 275 | $seq_name = $matches[1]; |
| 235 | 276 | $seq_fld = $fld->name; |
| 236 | 277 | } |
@@ -244,7 +285,9 @@ discard block |
||
| 244 | 285 | $aSql = array_merge($aSql,$this->DropTableSQL($tabname)); |
| 245 | 286 | $aSql = array_merge($aSql,$this->CreateTableSQL($tabname,$tableflds,$tableoptions)); |
| 246 | 287 | $aSql[] = "INSERT INTO $tabname SELECT $copyflds FROM $tempname"; |
| 247 | - if ($seq_name && $seq_fld) { // if we have a sequence we need to set it again |
|
| 288 | + if ($seq_name && $seq_fld) |
|
| 289 | + { |
|
| 290 | +// if we have a sequence we need to set it again |
|
| 248 | 291 | $seq_name = $tabname.'_'.$seq_fld.'_seq'; // has to be the name of the new implicit sequence |
| 249 | 292 | $aSql[] = "SELECT setval('$seq_name',MAX($seq_fld)) FROM $tabname"; |
| 250 | 293 | } |
@@ -252,7 +295,8 @@ discard block |
||
| 252 | 295 | // recreate the indexes, if they not contain one of the droped columns |
| 253 | 296 | foreach($this->MetaIndexes($tabname) as $idx_name => $idx_data) |
| 254 | 297 | { |
| 255 | - if (substr($idx_name,-5) != '_pkey' && (!$dropflds || !count(array_intersect($dropflds,$idx_data['columns'])))) { |
|
| 298 | + if (substr($idx_name,-5) != '_pkey' && (!$dropflds || !count(array_intersect($dropflds,$idx_data['columns'])))) |
|
| 299 | + { |
|
| 256 | 300 | $aSql = array_merge($aSql,$this->CreateIndexSQL($idx_name,$tabname,$idx_data['columns'], |
| 257 | 301 | $idx_data['unique'] ? array('UNIQUE') : False)); |
| 258 | 302 | } |
@@ -266,7 +310,10 @@ discard block |
||
| 266 | 310 | $sql = ADODB_DataDict::DropTableSQL($tabname); |
| 267 | 311 | |
| 268 | 312 | $drop_seq = $this->_DropAutoIncrement($tabname); |
| 269 | - if ($drop_seq) $sql[] = $drop_seq; |
|
| 313 | + if ($drop_seq) |
|
| 314 | + { |
|
| 315 | + $sql[] = $drop_seq; |
|
| 316 | + } |
|
| 270 | 317 | |
| 271 | 318 | return $sql; |
| 272 | 319 | } |
@@ -274,14 +321,24 @@ discard block |
||
| 274 | 321 | // return string must begin with space |
| 275 | 322 | function _CreateSuffix($fname, &$ftype, $fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned) |
| 276 | 323 | { |
| 277 | - if ($fautoinc) { |
|
| 324 | + if ($fautoinc) |
|
| 325 | + { |
|
| 278 | 326 | $ftype = 'SERIAL'; |
| 279 | 327 | return ''; |
| 280 | 328 | } |
| 281 | 329 | $suffix = ''; |
| 282 | - if (strlen($fdefault)) $suffix .= " DEFAULT $fdefault"; |
|
| 283 | - if ($fnotnull) $suffix .= ' NOT NULL'; |
|
| 284 | - if ($fconstraint) $suffix .= ' '.$fconstraint; |
|
| 330 | + if (strlen($fdefault)) |
|
| 331 | + { |
|
| 332 | + $suffix .= " DEFAULT $fdefault"; |
|
| 333 | + } |
|
| 334 | + if ($fnotnull) |
|
| 335 | + { |
|
| 336 | + $suffix .= ' NOT NULL'; |
|
| 337 | + } |
|
| 338 | + if ($fconstraint) |
|
| 339 | + { |
|
| 340 | + $suffix .= ' '.$fconstraint; |
|
| 341 | + } |
|
| 285 | 342 | return $suffix; |
| 286 | 343 | } |
| 287 | 344 | |
@@ -295,7 +352,8 @@ discard block |
||
| 295 | 352 | $seq = $this->connection->GetOne("SELECT relname FROM pg_class WHERE NOT relname ~ 'pg_.*' AND relname LIKE $tabname AND relkind='S'"); |
| 296 | 353 | |
| 297 | 354 | // check if a tables depends on the sequenz and it therefor cant and dont need to be droped separatly |
| 298 | - if (!$seq || $this->connection->GetOne("SELECT relname FROM pg_class JOIN pg_depend ON pg_class.oid=pg_depend.objid WHERE relname='$seq' AND relkind='S' AND refclassid = (SELECT oid FROM pg_class WHERE relname = 'pg_class')")) { |
|
| 355 | + if (!$seq || $this->connection->GetOne("SELECT relname FROM pg_class JOIN pg_depend ON pg_class.oid=pg_depend.objid WHERE relname='$seq' AND relkind='S' AND refclassid = (SELECT oid FROM pg_class WHERE relname = 'pg_class')")) |
|
| 356 | + { |
|
| 299 | 357 | return False; |
| 300 | 358 | } |
| 301 | 359 | return "DROP SEQUENCE ".$seq; |
@@ -338,13 +396,17 @@ discard block |
||
| 338 | 396 | { |
| 339 | 397 | $sql = array(); |
| 340 | 398 | |
| 341 | - if ( isset($idxoptions['REPLACE']) || isset($idxoptions['DROP']) ) { |
|
| 399 | + if ( isset($idxoptions['REPLACE']) || isset($idxoptions['DROP']) ) |
|
| 400 | + { |
|
| 342 | 401 | $sql[] = sprintf ($this->dropIndex, $idxname, $tabname); |
| 343 | 402 | if ( isset($idxoptions['DROP']) ) |
| 344 | - return $sql; |
|
| 403 | + { |
|
| 404 | + return $sql; |
|
| 405 | + } |
|
| 345 | 406 | } |
| 346 | 407 | |
| 347 | - if ( empty ($flds) ) { |
|
| 408 | + if ( empty ($flds) ) |
|
| 409 | + { |
|
| 348 | 410 | return $sql; |
| 349 | 411 | } |
| 350 | 412 | |
@@ -353,13 +415,19 @@ discard block |
||
| 353 | 415 | $s = 'CREATE' . $unique . ' INDEX ' . $idxname . ' ON ' . $tabname . ' '; |
| 354 | 416 | |
| 355 | 417 | if (isset($idxoptions['HASH'])) |
| 356 | - $s .= 'USING HASH '; |
|
| 418 | + { |
|
| 419 | + $s .= 'USING HASH '; |
|
| 420 | + } |
|
| 357 | 421 | |
| 358 | 422 | if ( isset($idxoptions[$this->upperName]) ) |
| 359 | - $s .= $idxoptions[$this->upperName]; |
|
| 423 | + { |
|
| 424 | + $s .= $idxoptions[$this->upperName]; |
|
| 425 | + } |
|
| 360 | 426 | |
| 361 | 427 | if ( is_array($flds) ) |
| 362 | - $flds = implode(', ',$flds); |
|
| 428 | + { |
|
| 429 | + $flds = implode(', ',$flds); |
|
| 430 | + } |
|
| 363 | 431 | $s .= '(' . $flds . ')'; |
| 364 | 432 | $sql[] = $s; |
| 365 | 433 | |
@@ -379,6 +379,11 @@ |
||
| 379 | 379 | } |
| 380 | 380 | |
| 381 | 381 | //OPN STUFF start |
| 382 | + |
|
| 383 | + /** |
|
| 384 | + * @param ADOFieldObject $fld |
|
| 385 | + * @param boolean $dialect3 |
|
| 386 | + */ |
|
| 382 | 387 | function _ConvertFieldType(&$fld, $ftype, $flen, $fscale, $fsubtype, $fprecision, $dialect3) |
| 383 | 388 | { |
| 384 | 389 | $fscale = abs($fscale); |
@@ -189,55 +189,55 @@ discard block |
||
| 189 | 189 | |
| 190 | 190 | function &MetaIndexes ($table, $primary = FALSE, $owner=false) |
| 191 | 191 | { |
| 192 | - // save old fetch mode |
|
| 193 | - global $ADODB_FETCH_MODE; |
|
| 194 | - $false = false; |
|
| 195 | - $save = $ADODB_FETCH_MODE; |
|
| 196 | - $ADODB_FETCH_MODE = ADODB_FETCH_NUM; |
|
| 197 | - if ($this->fetchMode !== FALSE) { |
|
| 198 | - $savem = $this->SetFetchMode(FALSE); |
|
| 199 | - } |
|
| 200 | - $table = strtoupper($table); |
|
| 201 | - $sql = "SELECT * FROM RDB\$INDICES WHERE RDB\$RELATION_NAME = '".$table."'"; |
|
| 202 | - if (!$primary) { |
|
| 203 | - $sql .= " AND RDB\$INDEX_NAME NOT LIKE 'RDB\$%'"; |
|
| 204 | - } else { |
|
| 205 | - $sql .= " AND RDB\$INDEX_NAME NOT LIKE 'RDB\$FOREIGN%'"; |
|
| 206 | - } |
|
| 207 | - // get index details |
|
| 208 | - $rs = $this->Execute($sql); |
|
| 209 | - if (!is_object($rs)) { |
|
| 210 | - // restore fetchmode |
|
| 211 | - if (isset($savem)) { |
|
| 212 | - $this->SetFetchMode($savem); |
|
| 213 | - } |
|
| 214 | - $ADODB_FETCH_MODE = $save; |
|
| 215 | - return $false; |
|
| 216 | - } |
|
| 192 | + // save old fetch mode |
|
| 193 | + global $ADODB_FETCH_MODE; |
|
| 194 | + $false = false; |
|
| 195 | + $save = $ADODB_FETCH_MODE; |
|
| 196 | + $ADODB_FETCH_MODE = ADODB_FETCH_NUM; |
|
| 197 | + if ($this->fetchMode !== FALSE) { |
|
| 198 | + $savem = $this->SetFetchMode(FALSE); |
|
| 199 | + } |
|
| 200 | + $table = strtoupper($table); |
|
| 201 | + $sql = "SELECT * FROM RDB\$INDICES WHERE RDB\$RELATION_NAME = '".$table."'"; |
|
| 202 | + if (!$primary) { |
|
| 203 | + $sql .= " AND RDB\$INDEX_NAME NOT LIKE 'RDB\$%'"; |
|
| 204 | + } else { |
|
| 205 | + $sql .= " AND RDB\$INDEX_NAME NOT LIKE 'RDB\$FOREIGN%'"; |
|
| 206 | + } |
|
| 207 | + // get index details |
|
| 208 | + $rs = $this->Execute($sql); |
|
| 209 | + if (!is_object($rs)) { |
|
| 210 | + // restore fetchmode |
|
| 211 | + if (isset($savem)) { |
|
| 212 | + $this->SetFetchMode($savem); |
|
| 213 | + } |
|
| 214 | + $ADODB_FETCH_MODE = $save; |
|
| 215 | + return $false; |
|
| 216 | + } |
|
| 217 | 217 | |
| 218 | - $indexes = array (); |
|
| 218 | + $indexes = array (); |
|
| 219 | 219 | while ($row = $rs->FetchRow()) { |
| 220 | 220 | $index = $row[0]; |
| 221 | - if (!isset($indexes[$index])) { |
|
| 222 | - if (is_null($row[3])) {$row[3] = 0;} |
|
| 223 | - $indexes[$index] = array( |
|
| 224 | - 'unique' => ($row[3] == 1), |
|
| 225 | - 'columns' => array() |
|
| 226 | - ); |
|
| 227 | - } |
|
| 221 | + if (!isset($indexes[$index])) { |
|
| 222 | + if (is_null($row[3])) {$row[3] = 0;} |
|
| 223 | + $indexes[$index] = array( |
|
| 224 | + 'unique' => ($row[3] == 1), |
|
| 225 | + 'columns' => array() |
|
| 226 | + ); |
|
| 227 | + } |
|
| 228 | 228 | $sql = "SELECT * FROM RDB\$INDEX_SEGMENTS WHERE RDB\$INDEX_NAME = '".$name."' ORDER BY RDB\$FIELD_POSITION ASC"; |
| 229 | 229 | $rs1 = $this->Execute($sql); |
| 230 | - while ($row1 = $rs1->FetchRow()) { |
|
| 231 | - $indexes[$index]['columns'][$row1[2]] = $row1[1]; |
|
| 232 | - } |
|
| 230 | + while ($row1 = $rs1->FetchRow()) { |
|
| 231 | + $indexes[$index]['columns'][$row1[2]] = $row1[1]; |
|
| 232 | + } |
|
| 233 | + } |
|
| 234 | + // restore fetchmode |
|
| 235 | + if (isset($savem)) { |
|
| 236 | + $this->SetFetchMode($savem); |
|
| 233 | 237 | } |
| 234 | - // restore fetchmode |
|
| 235 | - if (isset($savem)) { |
|
| 236 | - $this->SetFetchMode($savem); |
|
| 237 | - } |
|
| 238 | - $ADODB_FETCH_MODE = $save; |
|
| 238 | + $ADODB_FETCH_MODE = $save; |
|
| 239 | 239 | |
| 240 | - return $indexes; |
|
| 240 | + return $indexes; |
|
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | |
@@ -388,24 +388,24 @@ discard block |
||
| 388 | 388 | case 7: |
| 389 | 389 | case 8: |
| 390 | 390 | if ($dialect3) { |
| 391 | - switch($fsubtype){ |
|
| 392 | - case 0: |
|
| 393 | - $fld->type = ($ftype == 7 ? 'smallint' : 'integer'); |
|
| 394 | - break; |
|
| 395 | - case 1: |
|
| 396 | - $fld->type = 'numeric'; |
|
| 391 | + switch($fsubtype){ |
|
| 392 | + case 0: |
|
| 393 | + $fld->type = ($ftype == 7 ? 'smallint' : 'integer'); |
|
| 394 | + break; |
|
| 395 | + case 1: |
|
| 396 | + $fld->type = 'numeric'; |
|
| 397 | 397 | $fld->max_length = $fprecision; |
| 398 | 398 | $fld->scale = $fscale; |
| 399 | - break; |
|
| 400 | - case 2: |
|
| 401 | - $fld->type = 'decimal'; |
|
| 399 | + break; |
|
| 400 | + case 2: |
|
| 401 | + $fld->type = 'decimal'; |
|
| 402 | 402 | $fld->max_length = $fprecision; |
| 403 | 403 | $fld->scale = $fscale; |
| 404 | - break; |
|
| 405 | - } // switch |
|
| 404 | + break; |
|
| 405 | + } // switch |
|
| 406 | 406 | } else { |
| 407 | 407 | if ($fscale !=0) { |
| 408 | - $fld->type = 'decimal'; |
|
| 408 | + $fld->type = 'decimal'; |
|
| 409 | 409 | $fld->scale = $fscale; |
| 410 | 410 | $fld->max_length = ($ftype == 7 ? 4 : 9); |
| 411 | 411 | } else { |
@@ -415,23 +415,23 @@ discard block |
||
| 415 | 415 | break; |
| 416 | 416 | case 16: |
| 417 | 417 | if ($dialect3) { |
| 418 | - switch($fsubtype){ |
|
| 419 | - case 0: |
|
| 420 | - $fld->type = 'decimal'; |
|
| 418 | + switch($fsubtype){ |
|
| 419 | + case 0: |
|
| 420 | + $fld->type = 'decimal'; |
|
| 421 | 421 | $fld->max_length = 18; |
| 422 | 422 | $fld->scale = 0; |
| 423 | - break; |
|
| 424 | - case 1: |
|
| 425 | - $fld->type = 'numeric'; |
|
| 423 | + break; |
|
| 424 | + case 1: |
|
| 425 | + $fld->type = 'numeric'; |
|
| 426 | 426 | $fld->max_length = $fprecision; |
| 427 | 427 | $fld->scale = $fscale; |
| 428 | - break; |
|
| 429 | - case 2: |
|
| 430 | - $fld->type = 'decimal'; |
|
| 428 | + break; |
|
| 429 | + case 2: |
|
| 430 | + $fld->type = 'decimal'; |
|
| 431 | 431 | $fld->max_length = $fprecision; |
| 432 | 432 | $fld->scale = $fscale; |
| 433 | - break; |
|
| 434 | - } // switch |
|
| 433 | + break; |
|
| 434 | + } // switch |
|
| 435 | 435 | } |
| 436 | 436 | break; |
| 437 | 437 | case 10: |
@@ -442,7 +442,7 @@ discard block |
||
| 442 | 442 | break; |
| 443 | 443 | case 27: |
| 444 | 444 | if ($fscale !=0) { |
| 445 | - $fld->type = 'decimal'; |
|
| 445 | + $fld->type = 'decimal'; |
|
| 446 | 446 | $fld->max_length = 15; |
| 447 | 447 | $fld->scale = 5; |
| 448 | 448 | } else { |
@@ -451,7 +451,7 @@ discard block |
||
| 451 | 451 | break; |
| 452 | 452 | case 35: |
| 453 | 453 | if ($dialect3) { |
| 454 | - $fld->type = 'timestamp'; |
|
| 454 | + $fld->type = 'timestamp'; |
|
| 455 | 455 | } else { |
| 456 | 456 | $fld->type = 'date'; |
| 457 | 457 | } |
@@ -122,11 +122,11 @@ discard block |
||
| 122 | 122 | { |
| 123 | 123 | $arr['dialect'] = $this->dialect; |
| 124 | 124 | switch($arr['dialect']) { |
| 125 | - case '': |
|
| 126 | - case '1': $s = 'Interbase 5.5 or earlier'; break; |
|
| 127 | - case '2': $s = 'Interbase 5.6'; break; |
|
| 128 | - default: |
|
| 129 | - case '3': $s = 'Interbase 6.0'; break; |
|
| 125 | + case '': |
|
| 126 | + case '1': $s = 'Interbase 5.5 or earlier'; break; |
|
| 127 | + case '2': $s = 'Interbase 5.6'; break; |
|
| 128 | + default: |
|
| 129 | + case '3': $s = 'Interbase 6.0'; break; |
|
| 130 | 130 | } |
| 131 | 131 | $arr['version'] = ADOConnection::_findvers($s); |
| 132 | 132 | $arr['description'] = $s; |
@@ -330,15 +330,15 @@ discard block |
||
| 330 | 330 | $ret = call_user_func_array($fn,$fnarr); |
| 331 | 331 | } else { |
| 332 | 332 | switch(sizeof($iarr)) { |
| 333 | - case 1: $ret = $fn($sql,$iarr[0]); break; |
|
| 334 | - case 2: $ret = $fn($sql,$iarr[0],$iarr[1]); break; |
|
| 335 | - case 3: $ret = $fn($sql,$iarr[0],$iarr[1],$iarr[2]); break; |
|
| 336 | - case 4: $ret = $fn($sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3]); break; |
|
| 337 | - case 5: $ret = $fn($sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4]); break; |
|
| 338 | - case 6: $ret = $fn($sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4],$iarr[5]); break; |
|
| 339 | - case 7: $ret = $fn($sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4],$iarr[5],$iarr[6]); break; |
|
| 340 | - default: ADOConnection::outp( "Too many parameters to ibase query $sql"); |
|
| 341 | - case 8: $ret = $fn($sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4],$iarr[5],$iarr[6],$iarr[7]); break; |
|
| 333 | + case 1: $ret = $fn($sql,$iarr[0]); break; |
|
| 334 | + case 2: $ret = $fn($sql,$iarr[0],$iarr[1]); break; |
|
| 335 | + case 3: $ret = $fn($sql,$iarr[0],$iarr[1],$iarr[2]); break; |
|
| 336 | + case 4: $ret = $fn($sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3]); break; |
|
| 337 | + case 5: $ret = $fn($sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4]); break; |
|
| 338 | + case 6: $ret = $fn($sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4],$iarr[5]); break; |
|
| 339 | + case 7: $ret = $fn($sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4],$iarr[5],$iarr[6]); break; |
|
| 340 | + default: ADOConnection::outp( "Too many parameters to ibase query $sql"); |
|
| 341 | + case 8: $ret = $fn($sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4],$iarr[5],$iarr[6],$iarr[7]); break; |
|
| 342 | 342 | } |
| 343 | 343 | } |
| 344 | 344 | } else $ret = $fn($sql); |
@@ -352,15 +352,15 @@ discard block |
||
| 352 | 352 | $ret = call_user_func_array($fn,$fnarr); |
| 353 | 353 | } else { |
| 354 | 354 | switch(sizeof($iarr)) { |
| 355 | - case 1: $ret = $fn($conn,$sql,$iarr[0]); break; |
|
| 356 | - case 2: $ret = $fn($conn,$sql,$iarr[0],$iarr[1]); break; |
|
| 357 | - case 3: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2]); break; |
|
| 358 | - case 4: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3]); break; |
|
| 359 | - case 5: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4]); break; |
|
| 360 | - case 6: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4],$iarr[5]); break; |
|
| 361 | - case 7: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4],$iarr[5],$iarr[6]); break; |
|
| 362 | - default: ADOConnection::outp( "Too many parameters to ibase query $sql"); |
|
| 363 | - case 8: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4],$iarr[5],$iarr[6],$iarr[7]); break; |
|
| 355 | + case 1: $ret = $fn($conn,$sql,$iarr[0]); break; |
|
| 356 | + case 2: $ret = $fn($conn,$sql,$iarr[0],$iarr[1]); break; |
|
| 357 | + case 3: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2]); break; |
|
| 358 | + case 4: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3]); break; |
|
| 359 | + case 5: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4]); break; |
|
| 360 | + case 6: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4],$iarr[5]); break; |
|
| 361 | + case 7: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4],$iarr[5],$iarr[6]); break; |
|
| 362 | + default: ADOConnection::outp( "Too many parameters to ibase query $sql"); |
|
| 363 | + case 8: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4],$iarr[5],$iarr[6],$iarr[7]); break; |
|
| 364 | 364 | } |
| 365 | 365 | } |
| 366 | 366 | } else $ret = $fn($conn,$sql); |
@@ -509,15 +509,15 @@ discard block |
||
| 509 | 509 | $d = substr($rs->fields[2],strlen('default ')); |
| 510 | 510 | switch ($fld->type) |
| 511 | 511 | { |
| 512 | - case 'smallint': |
|
| 513 | - case 'integer': $fld->default_value = (int) $d; break; |
|
| 514 | - case 'char': |
|
| 515 | - case 'blob': |
|
| 516 | - case 'text': |
|
| 517 | - case 'varchar': $fld->default_value = (string) substr($d,1,strlen($d)-2); break; |
|
| 518 | - case 'double': |
|
| 519 | - case 'float': $fld->default_value = (float) $d; break; |
|
| 520 | - default: $fld->default_value = $d; break; |
|
| 512 | + case 'smallint': |
|
| 513 | + case 'integer': $fld->default_value = (int) $d; break; |
|
| 514 | + case 'char': |
|
| 515 | + case 'blob': |
|
| 516 | + case 'text': |
|
| 517 | + case 'varchar': $fld->default_value = (string) substr($d,1,strlen($d)-2); break; |
|
| 518 | + case 'double': |
|
| 519 | + case 'float': $fld->default_value = (float) $d; break; |
|
| 520 | + default: $fld->default_value = $d; break; |
|
| 521 | 521 | } |
| 522 | 522 | // case 35:$tt = 'TIMESTAMP'; break; |
| 523 | 523 | } |
@@ -651,42 +651,42 @@ discard block |
||
| 651 | 651 | if ($s) $s .= '||'; |
| 652 | 652 | $ch = $fmt[$i]; |
| 653 | 653 | switch($ch) { |
| 654 | - case 'Y': |
|
| 655 | - case 'y': |
|
| 656 | - $s .= "extract(year from $col)"; |
|
| 657 | - break; |
|
| 658 | - case 'M': |
|
| 659 | - case 'm': |
|
| 660 | - $s .= "extract(month from $col)"; |
|
| 661 | - break; |
|
| 662 | - case 'Q': |
|
| 663 | - case 'q': |
|
| 664 | - $s .= "cast(((extract(month from $col)+2) / 3) as integer)"; |
|
| 665 | - break; |
|
| 666 | - case 'D': |
|
| 667 | - case 'd': |
|
| 668 | - $s .= "(extract(day from $col))"; |
|
| 669 | - break; |
|
| 670 | - case 'H': |
|
| 671 | - case 'h': |
|
| 672 | - $s .= "(extract(hour from $col))"; |
|
| 673 | - break; |
|
| 674 | - case 'I': |
|
| 675 | - case 'i': |
|
| 676 | - $s .= "(extract(minute from $col))"; |
|
| 677 | - break; |
|
| 678 | - case 'S': |
|
| 679 | - case 's': |
|
| 680 | - $s .= "CAST((extract(second from $col)) AS INTEGER)"; |
|
| 681 | - break; |
|
| 654 | + case 'Y': |
|
| 655 | + case 'y': |
|
| 656 | + $s .= "extract(year from $col)"; |
|
| 657 | + break; |
|
| 658 | + case 'M': |
|
| 659 | + case 'm': |
|
| 660 | + $s .= "extract(month from $col)"; |
|
| 661 | + break; |
|
| 662 | + case 'Q': |
|
| 663 | + case 'q': |
|
| 664 | + $s .= "cast(((extract(month from $col)+2) / 3) as integer)"; |
|
| 665 | + break; |
|
| 666 | + case 'D': |
|
| 667 | + case 'd': |
|
| 668 | + $s .= "(extract(day from $col))"; |
|
| 669 | + break; |
|
| 670 | + case 'H': |
|
| 671 | + case 'h': |
|
| 672 | + $s .= "(extract(hour from $col))"; |
|
| 673 | + break; |
|
| 674 | + case 'I': |
|
| 675 | + case 'i': |
|
| 676 | + $s .= "(extract(minute from $col))"; |
|
| 677 | + break; |
|
| 678 | + case 'S': |
|
| 679 | + case 's': |
|
| 680 | + $s .= "CAST((extract(second from $col)) AS INTEGER)"; |
|
| 681 | + break; |
|
| 682 | 682 | |
| 683 | - default: |
|
| 684 | - if ($ch == '\\') { |
|
| 685 | - $i++; |
|
| 686 | - $ch = substr($fmt,$i,1); |
|
| 687 | - } |
|
| 688 | - $s .= $this->qstr($ch); |
|
| 689 | - break; |
|
| 683 | + default: |
|
| 684 | + if ($ch == '\\') { |
|
| 685 | + $i++; |
|
| 686 | + $ch = substr($fmt,$i,1); |
|
| 687 | + } |
|
| 688 | + $s .= $this->qstr($ch); |
|
| 689 | + break; |
|
| 690 | 690 | } |
| 691 | 691 | } |
| 692 | 692 | return $s; |
@@ -722,18 +722,18 @@ discard block |
||
| 722 | 722 | $fld = new ADOFieldObject; |
| 723 | 723 | $ibf = ibase_field_info($this->_queryID,$fieldOffset); |
| 724 | 724 | switch (ADODB_ASSOC_CASE) { |
| 725 | - case 2: // the default |
|
| 726 | - $fld->name = ($ibf['alias']); |
|
| 727 | - if (empty($fld->name)) $fld->name = ($ibf['name']); |
|
| 728 | - break; |
|
| 729 | - case 0: |
|
| 730 | - $fld->name = strtoupper($ibf['alias']); |
|
| 731 | - if (empty($fld->name)) $fld->name = strtoupper($ibf['name']); |
|
| 732 | - break; |
|
| 733 | - case 1: |
|
| 734 | - $fld->name = strtolower($ibf['alias']); |
|
| 735 | - if (empty($fld->name)) $fld->name = strtolower($ibf['name']); |
|
| 736 | - break; |
|
| 725 | + case 2: // the default |
|
| 726 | + $fld->name = ($ibf['alias']); |
|
| 727 | + if (empty($fld->name)) $fld->name = ($ibf['name']); |
|
| 728 | + break; |
|
| 729 | + case 0: |
|
| 730 | + $fld->name = strtoupper($ibf['alias']); |
|
| 731 | + if (empty($fld->name)) $fld->name = strtoupper($ibf['name']); |
|
| 732 | + break; |
|
| 733 | + case 1: |
|
| 734 | + $fld->name = strtolower($ibf['alias']); |
|
| 735 | + if (empty($fld->name)) $fld->name = strtolower($ibf['name']); |
|
| 736 | + break; |
|
| 737 | 737 | } |
| 738 | 738 | |
| 739 | 739 | $fld->type = $ibf['type']; |
@@ -833,27 +833,27 @@ discard block |
||
| 833 | 833 | $len = $fieldobj->max_length; |
| 834 | 834 | } |
| 835 | 835 | switch (strtoupper($t)) { |
| 836 | - case 'CHAR': |
|
| 837 | - return 'C'; |
|
| 836 | + case 'CHAR': |
|
| 837 | + return 'C'; |
|
| 838 | 838 | |
| 839 | - case 'TEXT': |
|
| 840 | - case 'VARCHAR': |
|
| 841 | - case 'VARYING': |
|
| 842 | - if ($len <= $this->blobSize) return 'C'; |
|
| 843 | - return 'X'; |
|
| 844 | - case 'BLOB': |
|
| 845 | - return 'B'; |
|
| 839 | + case 'TEXT': |
|
| 840 | + case 'VARCHAR': |
|
| 841 | + case 'VARYING': |
|
| 842 | + if ($len <= $this->blobSize) return 'C'; |
|
| 843 | + return 'X'; |
|
| 844 | + case 'BLOB': |
|
| 845 | + return 'B'; |
|
| 846 | 846 | |
| 847 | - case 'TIMESTAMP': |
|
| 848 | - case 'DATE': return 'D'; |
|
| 849 | - case 'TIME': return 'T'; |
|
| 850 | - //case 'T': return 'T'; |
|
| 847 | + case 'TIMESTAMP': |
|
| 848 | + case 'DATE': return 'D'; |
|
| 849 | + case 'TIME': return 'T'; |
|
| 850 | + //case 'T': return 'T'; |
|
| 851 | 851 | |
| 852 | - //case 'L': return 'L'; |
|
| 853 | - case 'INT': |
|
| 854 | - case 'SHORT': |
|
| 855 | - case 'INTEGER': return 'I'; |
|
| 856 | - default: return 'N'; |
|
| 852 | + //case 'L': return 'L'; |
|
| 853 | + case 'INT': |
|
| 854 | + case 'SHORT': |
|
| 855 | + case 'INTEGER': return 'I'; |
|
| 856 | + default: return 'N'; |
|
| 857 | 857 | } |
| 858 | 858 | } |
| 859 | 859 | |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | var $ibase_timestampfmt = "%Y-%m-%d %H:%M:%S"; |
| 36 | 36 | var $ibase_timefmt = "%H:%M:%S"; |
| 37 | 37 | var $fmtTimeStamp = "'Y-m-d, H:i:s'"; |
| 38 | - var $concat_operator='||'; |
|
| 38 | + var $concat_operator = '||'; |
|
| 39 | 39 | var $_transactionID; |
| 40 | 40 | var $metaTablesSQL = "select rdb\$relation_name from rdb\$relations where rdb\$relation_name not like 'RDB\$%'"; |
| 41 | 41 | //OPN STUFF start |
@@ -61,17 +61,17 @@ discard block |
||
| 61 | 61 | |
| 62 | 62 | |
| 63 | 63 | // returns true or false |
| 64 | - function _connect($argHostname, $argUsername, $argPassword, $argDatabasename,$persist=false) |
|
| 64 | + function _connect($argHostname, $argUsername, $argPassword, $argDatabasename, $persist = false) |
|
| 65 | 65 | { |
| 66 | 66 | if (!function_exists('ibase_pconnect')) return null; |
| 67 | 67 | if ($argDatabasename) $argHostname .= ':'.$argDatabasename; |
| 68 | - $fn = ($persist) ? 'ibase_pconnect':'ibase_connect'; |
|
| 68 | + $fn = ($persist) ? 'ibase_pconnect' : 'ibase_connect'; |
|
| 69 | 69 | if ($this->role) |
| 70 | - $this->_connectionID = $fn($argHostname,$argUsername,$argPassword, |
|
| 71 | - $this->charSet,$this->buffers,$this->dialect,$this->role); |
|
| 70 | + $this->_connectionID = $fn($argHostname, $argUsername, $argPassword, |
|
| 71 | + $this->charSet, $this->buffers, $this->dialect, $this->role); |
|
| 72 | 72 | else |
| 73 | - $this->_connectionID = $fn($argHostname,$argUsername,$argPassword, |
|
| 74 | - $this->charSet,$this->buffers,$this->dialect); |
|
| 73 | + $this->_connectionID = $fn($argHostname, $argUsername, $argPassword, |
|
| 74 | + $this->charSet, $this->buffers, $this->dialect); |
|
| 75 | 75 | |
| 76 | 76 | if ($this->dialect != 1) { // http://www.ibphoenix.com/ibp_60_del_id_ds.html |
| 77 | 77 | $this->replaceQuote = "''"; |
@@ -83,10 +83,10 @@ discard block |
||
| 83 | 83 | |
| 84 | 84 | // PHP5 change. |
| 85 | 85 | if (function_exists('ibase_timefmt')) { |
| 86 | - ibase_timefmt($this->ibase_datefmt,IBASE_DATE ); |
|
| 87 | - if ($this->dialect == 1) ibase_timefmt($this->ibase_datefmt,IBASE_TIMESTAMP ); |
|
| 88 | - else ibase_timefmt($this->ibase_timestampfmt,IBASE_TIMESTAMP ); |
|
| 89 | - ibase_timefmt($this->ibase_timefmt,IBASE_TIME ); |
|
| 86 | + ibase_timefmt($this->ibase_datefmt, IBASE_DATE); |
|
| 87 | + if ($this->dialect == 1) ibase_timefmt($this->ibase_datefmt, IBASE_TIMESTAMP); |
|
| 88 | + else ibase_timefmt($this->ibase_timestampfmt, IBASE_TIMESTAMP); |
|
| 89 | + ibase_timefmt($this->ibase_timefmt, IBASE_TIME); |
|
| 90 | 90 | |
| 91 | 91 | } else { |
| 92 | 92 | ini_set("ibase.timestampformat", $this->ibase_timestampfmt); |
@@ -98,11 +98,11 @@ discard block |
||
| 98 | 98 | // returns true or false |
| 99 | 99 | function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename) |
| 100 | 100 | { |
| 101 | - return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename,true); |
|
| 101 | + return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename, true); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | |
| 105 | - function MetaPrimaryKeys($table,$owner_notused=false,$internalKey=false) |
|
| 105 | + function MetaPrimaryKeys($table, $owner_notused = false, $internalKey = false) |
|
| 106 | 106 | { |
| 107 | 107 | if ($internalKey) return array('RDB$DB_KEY'); |
| 108 | 108 | |
@@ -113,15 +113,15 @@ discard block |
||
| 113 | 113 | WHERE I.RDB$RELATION_NAME=\''.$table.'\' and I.RDB$INDEX_NAME like \'RDB$PRIMARY%\' |
| 114 | 114 | ORDER BY I.RDB$INDEX_NAME,S.RDB$FIELD_POSITION'; |
| 115 | 115 | |
| 116 | - $a = $this->GetCol($sql,false,true); |
|
| 117 | - if ($a && sizeof($a)>0) return $a; |
|
| 116 | + $a = $this->GetCol($sql, false, true); |
|
| 117 | + if ($a && sizeof($a) > 0) return $a; |
|
| 118 | 118 | return false; |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | function ServerInfo() |
| 122 | 122 | { |
| 123 | 123 | $arr['dialect'] = $this->dialect; |
| 124 | - switch($arr['dialect']) { |
|
| 124 | + switch ($arr['dialect']) { |
|
| 125 | 125 | case '': |
| 126 | 126 | case '1': $s = 'Interbase 5.5 or earlier'; break; |
| 127 | 127 | case '2': $s = 'Interbase 5.6'; break; |
@@ -138,11 +138,11 @@ discard block |
||
| 138 | 138 | if ($this->transOff) return true; |
| 139 | 139 | $this->transCnt += 1; |
| 140 | 140 | $this->autoCommit = false; |
| 141 | - $this->_transactionID = $this->_connectionID;//ibase_trans($this->ibasetrans, $this->_connectionID); |
|
| 141 | + $this->_transactionID = $this->_connectionID; //ibase_trans($this->ibasetrans, $this->_connectionID); |
|
| 142 | 142 | return $this->_transactionID; |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - function CommitTrans($ok=true) |
|
| 145 | + function CommitTrans($ok = true) |
|
| 146 | 146 | { |
| 147 | 147 | if (!$ok) return $this->RollbackTrans(); |
| 148 | 148 | if ($this->transOff) return true; |
@@ -159,17 +159,17 @@ discard block |
||
| 159 | 159 | |
| 160 | 160 | // there are some compat problems with ADODB_COUNTRECS=false and $this->_logsql currently. |
| 161 | 161 | // it appears that ibase extension cannot support multiple concurrent queryid's |
| 162 | - function &_Execute($sql,$inputarr=false) |
|
| 162 | + function &_Execute($sql, $inputarr = false) |
|
| 163 | 163 | { |
| 164 | 164 | global $ADODB_COUNTRECS; |
| 165 | 165 | |
| 166 | 166 | if ($this->_logsql) { |
| 167 | 167 | $savecrecs = $ADODB_COUNTRECS; |
| 168 | 168 | $ADODB_COUNTRECS = true; // force countrecs |
| 169 | - $ret =& ADOConnection::_Execute($sql,$inputarr); |
|
| 169 | + $ret = & ADOConnection::_Execute($sql, $inputarr); |
|
| 170 | 170 | $ADODB_COUNTRECS = $savecrecs; |
| 171 | 171 | } else { |
| 172 | - $ret =& ADOConnection::_Execute($sql,$inputarr); |
|
| 172 | + $ret = & ADOConnection::_Execute($sql, $inputarr); |
|
| 173 | 173 | } |
| 174 | 174 | return $ret; |
| 175 | 175 | } |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | return $ret; |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | - function &MetaIndexes ($table, $primary = FALSE, $owner=false) |
|
| 190 | + function &MetaIndexes($table, $primary = FALSE, $owner = false) |
|
| 191 | 191 | { |
| 192 | 192 | // save old fetch mode |
| 193 | 193 | global $ADODB_FETCH_MODE; |
@@ -215,11 +215,11 @@ discard block |
||
| 215 | 215 | return $false; |
| 216 | 216 | } |
| 217 | 217 | |
| 218 | - $indexes = array (); |
|
| 218 | + $indexes = array(); |
|
| 219 | 219 | while ($row = $rs->FetchRow()) { |
| 220 | 220 | $index = $row[0]; |
| 221 | 221 | if (!isset($indexes[$index])) { |
| 222 | - if (is_null($row[3])) {$row[3] = 0;} |
|
| 222 | + if (is_null($row[3])) {$row[3] = 0; } |
|
| 223 | 223 | $indexes[$index] = array( |
| 224 | 224 | 'unique' => ($row[3] == 1), |
| 225 | 225 | 'columns' => array() |
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | |
| 243 | 243 | |
| 244 | 244 | // See http://community.borland.com/article/0,1410,25844,00.html |
| 245 | - function RowLock($tables,$where,$col) |
|
| 245 | + function RowLock($tables, $where, $col) |
|
| 246 | 246 | { |
| 247 | 247 | if ($this->autoCommit) $this->BeginTrans(); |
| 248 | 248 | $this->Execute("UPDATE $table SET $col=$col WHERE $where "); // is this correct - jlim? |
@@ -250,11 +250,11 @@ discard block |
||
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | |
| 253 | - function CreateSequence($seqname,$startID=1) |
|
| 253 | + function CreateSequence($seqname, $startID = 1) |
|
| 254 | 254 | { |
| 255 | - $ok = $this->Execute(("INSERT INTO RDB\$GENERATORS (RDB\$GENERATOR_NAME) VALUES (UPPER('$seqname'))" )); |
|
| 255 | + $ok = $this->Execute(("INSERT INTO RDB\$GENERATORS (RDB\$GENERATOR_NAME) VALUES (UPPER('$seqname'))")); |
|
| 256 | 256 | if (!$ok) return false; |
| 257 | - return $this->Execute("SET GENERATOR $seqname TO ".($startID-1).';'); |
|
| 257 | + return $this->Execute("SET GENERATOR $seqname TO ".($startID - 1).';'); |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | function DropSequence($seqname) |
@@ -263,16 +263,16 @@ discard block |
||
| 263 | 263 | $this->Execute("delete from RDB\$GENERATORS where RDB\$GENERATOR_NAME='$seqname'"); |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | - function GenID($seqname='adodbseq',$startID=1) |
|
| 266 | + function GenID($seqname = 'adodbseq', $startID = 1) |
|
| 267 | 267 | { |
| 268 | 268 | $getnext = ("SELECT Gen_ID($seqname,1) FROM RDB\$DATABASE"); |
| 269 | 269 | $rs = @$this->Execute($getnext); |
| 270 | 270 | if (!$rs) { |
| 271 | - $this->Execute(("INSERT INTO RDB\$GENERATORS (RDB\$GENERATOR_NAME) VALUES (UPPER('$seqname'))" )); |
|
| 272 | - $this->Execute("SET GENERATOR $seqname TO ".($startID-1).';'); |
|
| 271 | + $this->Execute(("INSERT INTO RDB\$GENERATORS (RDB\$GENERATOR_NAME) VALUES (UPPER('$seqname'))")); |
|
| 272 | + $this->Execute("SET GENERATOR $seqname TO ".($startID - 1).';'); |
|
| 273 | 273 | $rs = $this->Execute($getnext); |
| 274 | 274 | } |
| 275 | - if ($rs && !$rs->EOF) $this->genID = (integer) reset($rs->fields); |
|
| 275 | + if ($rs && !$rs->EOF) $this->genID = (integer)reset($rs->fields); |
|
| 276 | 276 | else $this->genID = 0; // false |
| 277 | 277 | |
| 278 | 278 | if ($rs) $rs->Close(); |
@@ -292,7 +292,7 @@ discard block |
||
| 292 | 292 | |
| 293 | 293 | function ErrorNo() |
| 294 | 294 | { |
| 295 | - if (preg_match('/error code = ([\-0-9]*)/i', $this->_errorMsg,$arr)) return (integer) $arr[1]; |
|
| 295 | + if (preg_match('/error code = ([\-0-9]*)/i', $this->_errorMsg, $arr)) return (integer)$arr[1]; |
|
| 296 | 296 | else return 0; |
| 297 | 297 | } |
| 298 | 298 | |
@@ -303,14 +303,14 @@ discard block |
||
| 303 | 303 | |
| 304 | 304 | function Prepare($sql) |
| 305 | 305 | { |
| 306 | - $stmt = ibase_prepare($this->_connectionID,$sql); |
|
| 306 | + $stmt = ibase_prepare($this->_connectionID, $sql); |
|
| 307 | 307 | if (!$stmt) return false; |
| 308 | - return array($sql,$stmt); |
|
| 308 | + return array($sql, $stmt); |
|
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | // returns query ID if successful, otherwise false |
| 312 | 312 | // there have been reports of problems with nested queries - the code is probably not re-entrant? |
| 313 | - function _query($sql,$iarr=false) |
|
| 313 | + function _query($sql, $iarr = false) |
|
| 314 | 314 | { |
| 315 | 315 | |
| 316 | 316 | if (!$this->autoCommit && $this->_transactionID) { |
@@ -324,21 +324,21 @@ discard block |
||
| 324 | 324 | $fn = 'ibase_execute'; |
| 325 | 325 | $sql = $sql[1]; |
| 326 | 326 | if (is_array($iarr)) { |
| 327 | - if (ADODB_PHPVER >= 0x4050) { // actually 4.0.4 |
|
| 328 | - if ( !isset($iarr[0]) ) $iarr[0] = ''; // PHP5 compat hack |
|
| 329 | - $fnarr =& array_merge( array($sql) , $iarr); |
|
| 330 | - $ret = call_user_func_array($fn,$fnarr); |
|
| 327 | + if (ADODB_PHPVER >= 0x4050) { // actually 4.0.4 |
|
| 328 | + if (!isset($iarr[0])) $iarr[0] = ''; // PHP5 compat hack |
|
| 329 | + $fnarr = & array_merge(array($sql), $iarr); |
|
| 330 | + $ret = call_user_func_array($fn, $fnarr); |
|
| 331 | 331 | } else { |
| 332 | - switch(sizeof($iarr)) { |
|
| 333 | - case 1: $ret = $fn($sql,$iarr[0]); break; |
|
| 334 | - case 2: $ret = $fn($sql,$iarr[0],$iarr[1]); break; |
|
| 335 | - case 3: $ret = $fn($sql,$iarr[0],$iarr[1],$iarr[2]); break; |
|
| 336 | - case 4: $ret = $fn($sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3]); break; |
|
| 337 | - case 5: $ret = $fn($sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4]); break; |
|
| 338 | - case 6: $ret = $fn($sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4],$iarr[5]); break; |
|
| 339 | - case 7: $ret = $fn($sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4],$iarr[5],$iarr[6]); break; |
|
| 340 | - default: ADOConnection::outp( "Too many parameters to ibase query $sql"); |
|
| 341 | - case 8: $ret = $fn($sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4],$iarr[5],$iarr[6],$iarr[7]); break; |
|
| 332 | + switch (sizeof($iarr)) { |
|
| 333 | + case 1: $ret = $fn($sql, $iarr[0]); break; |
|
| 334 | + case 2: $ret = $fn($sql, $iarr[0], $iarr[1]); break; |
|
| 335 | + case 3: $ret = $fn($sql, $iarr[0], $iarr[1], $iarr[2]); break; |
|
| 336 | + case 4: $ret = $fn($sql, $iarr[0], $iarr[1], $iarr[2], $iarr[3]); break; |
|
| 337 | + case 5: $ret = $fn($sql, $iarr[0], $iarr[1], $iarr[2], $iarr[3], $iarr[4]); break; |
|
| 338 | + case 6: $ret = $fn($sql, $iarr[0], $iarr[1], $iarr[2], $iarr[3], $iarr[4], $iarr[5]); break; |
|
| 339 | + case 7: $ret = $fn($sql, $iarr[0], $iarr[1], $iarr[2], $iarr[3], $iarr[4], $iarr[5], $iarr[6]); break; |
|
| 340 | + default: ADOConnection::outp("Too many parameters to ibase query $sql"); |
|
| 341 | + case 8: $ret = $fn($sql, $iarr[0], $iarr[1], $iarr[2], $iarr[3], $iarr[4], $iarr[5], $iarr[6], $iarr[7]); break; |
|
| 342 | 342 | } |
| 343 | 343 | } |
| 344 | 344 | } else $ret = $fn($sql); |
@@ -348,22 +348,22 @@ discard block |
||
| 348 | 348 | if (is_array($iarr)) { |
| 349 | 349 | if (ADODB_PHPVER >= 0x4050) { // actually 4.0.4 |
| 350 | 350 | if (sizeof($iarr) == 0) $iarr[0] = ''; // PHP5 compat hack |
| 351 | - $fnarr =& array_merge( array($conn,$sql) , $iarr); |
|
| 352 | - $ret = call_user_func_array($fn,$fnarr); |
|
| 351 | + $fnarr = & array_merge(array($conn, $sql), $iarr); |
|
| 352 | + $ret = call_user_func_array($fn, $fnarr); |
|
| 353 | 353 | } else { |
| 354 | - switch(sizeof($iarr)) { |
|
| 355 | - case 1: $ret = $fn($conn,$sql,$iarr[0]); break; |
|
| 356 | - case 2: $ret = $fn($conn,$sql,$iarr[0],$iarr[1]); break; |
|
| 357 | - case 3: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2]); break; |
|
| 358 | - case 4: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3]); break; |
|
| 359 | - case 5: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4]); break; |
|
| 360 | - case 6: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4],$iarr[5]); break; |
|
| 361 | - case 7: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4],$iarr[5],$iarr[6]); break; |
|
| 362 | - default: ADOConnection::outp( "Too many parameters to ibase query $sql"); |
|
| 363 | - case 8: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4],$iarr[5],$iarr[6],$iarr[7]); break; |
|
| 354 | + switch (sizeof($iarr)) { |
|
| 355 | + case 1: $ret = $fn($conn, $sql, $iarr[0]); break; |
|
| 356 | + case 2: $ret = $fn($conn, $sql, $iarr[0], $iarr[1]); break; |
|
| 357 | + case 3: $ret = $fn($conn, $sql, $iarr[0], $iarr[1], $iarr[2]); break; |
|
| 358 | + case 4: $ret = $fn($conn, $sql, $iarr[0], $iarr[1], $iarr[2], $iarr[3]); break; |
|
| 359 | + case 5: $ret = $fn($conn, $sql, $iarr[0], $iarr[1], $iarr[2], $iarr[3], $iarr[4]); break; |
|
| 360 | + case 6: $ret = $fn($conn, $sql, $iarr[0], $iarr[1], $iarr[2], $iarr[3], $iarr[4], $iarr[5]); break; |
|
| 361 | + case 7: $ret = $fn($conn, $sql, $iarr[0], $iarr[1], $iarr[2], $iarr[3], $iarr[4], $iarr[5], $iarr[6]); break; |
|
| 362 | + default: ADOConnection::outp("Too many parameters to ibase query $sql"); |
|
| 363 | + case 8: $ret = $fn($conn, $sql, $iarr[0], $iarr[1], $iarr[2], $iarr[3], $iarr[4], $iarr[5], $iarr[6], $iarr[7]); break; |
|
| 364 | 364 | } |
| 365 | 365 | } |
| 366 | - } else $ret = $fn($conn,$sql); |
|
| 366 | + } else $ret = $fn($conn, $sql); |
|
| 367 | 367 | } |
| 368 | 368 | if ($docommit && $ret === true) ibase_commit($this->_connectionID); |
| 369 | 369 | |
@@ -384,11 +384,11 @@ discard block |
||
| 384 | 384 | $fscale = abs($fscale); |
| 385 | 385 | $fld->max_length = $flen; |
| 386 | 386 | $fld->scale = null; |
| 387 | - switch($ftype){ |
|
| 387 | + switch ($ftype) { |
|
| 388 | 388 | case 7: |
| 389 | 389 | case 8: |
| 390 | 390 | if ($dialect3) { |
| 391 | - switch($fsubtype){ |
|
| 391 | + switch ($fsubtype) { |
|
| 392 | 392 | case 0: |
| 393 | 393 | $fld->type = ($ftype == 7 ? 'smallint' : 'integer'); |
| 394 | 394 | break; |
@@ -404,7 +404,7 @@ discard block |
||
| 404 | 404 | break; |
| 405 | 405 | } // switch |
| 406 | 406 | } else { |
| 407 | - if ($fscale !=0) { |
|
| 407 | + if ($fscale != 0) { |
|
| 408 | 408 | $fld->type = 'decimal'; |
| 409 | 409 | $fld->scale = $fscale; |
| 410 | 410 | $fld->max_length = ($ftype == 7 ? 4 : 9); |
@@ -415,7 +415,7 @@ discard block |
||
| 415 | 415 | break; |
| 416 | 416 | case 16: |
| 417 | 417 | if ($dialect3) { |
| 418 | - switch($fsubtype){ |
|
| 418 | + switch ($fsubtype) { |
|
| 419 | 419 | case 0: |
| 420 | 420 | $fld->type = 'decimal'; |
| 421 | 421 | $fld->max_length = 18; |
@@ -441,7 +441,7 @@ discard block |
||
| 441 | 441 | $fld->type = 'char'; |
| 442 | 442 | break; |
| 443 | 443 | case 27: |
| 444 | - if ($fscale !=0) { |
|
| 444 | + if ($fscale != 0) { |
|
| 445 | 445 | $fld->type = 'decimal'; |
| 446 | 446 | $fld->max_length = 15; |
| 447 | 447 | $fld->scale = 5; |
@@ -483,7 +483,7 @@ discard block |
||
| 483 | 483 | $save = $ADODB_FETCH_MODE; |
| 484 | 484 | $ADODB_FETCH_MODE = ADODB_FETCH_NUM; |
| 485 | 485 | |
| 486 | - $rs = $this->Execute(sprintf($this->metaColumnsSQL,strtoupper($table))); |
|
| 486 | + $rs = $this->Execute(sprintf($this->metaColumnsSQL, strtoupper($table))); |
|
| 487 | 487 | |
| 488 | 488 | $ADODB_FETCH_MODE = $save; |
| 489 | 489 | $false = false; |
@@ -493,7 +493,7 @@ discard block |
||
| 493 | 493 | |
| 494 | 494 | $retarr = array(); |
| 495 | 495 | //OPN STUFF start |
| 496 | - $dialect3 = ($this->dialect==3 ? true : false); |
|
| 496 | + $dialect3 = ($this->dialect == 3 ? true : false); |
|
| 497 | 497 | //OPN STUFF end |
| 498 | 498 | while (!$rs->EOF) { //print_r($rs->fields); |
| 499 | 499 | $fld = new ADOFieldObject(); |
@@ -506,17 +506,17 @@ discard block |
||
| 506 | 506 | if (isset($rs->fields[2])) { |
| 507 | 507 | |
| 508 | 508 | $fld->has_default = true; |
| 509 | - $d = substr($rs->fields[2],strlen('default ')); |
|
| 509 | + $d = substr($rs->fields[2], strlen('default ')); |
|
| 510 | 510 | switch ($fld->type) |
| 511 | 511 | { |
| 512 | 512 | case 'smallint': |
| 513 | - case 'integer': $fld->default_value = (int) $d; break; |
|
| 513 | + case 'integer': $fld->default_value = (int)$d; break; |
|
| 514 | 514 | case 'char': |
| 515 | 515 | case 'blob': |
| 516 | 516 | case 'text': |
| 517 | - case 'varchar': $fld->default_value = (string) substr($d,1,strlen($d)-2); break; |
|
| 517 | + case 'varchar': $fld->default_value = (string)substr($d, 1, strlen($d) - 2); break; |
|
| 518 | 518 | case 'double': |
| 519 | - case 'float': $fld->default_value = (float) $d; break; |
|
| 519 | + case 'float': $fld->default_value = (float)$d; break; |
|
| 520 | 520 | default: $fld->default_value = $d; break; |
| 521 | 521 | } |
| 522 | 522 | // case 35:$tt = 'TIMESTAMP'; break; |
@@ -533,15 +533,15 @@ discard block |
||
| 533 | 533 | $rs->MoveNext(); |
| 534 | 534 | } |
| 535 | 535 | $rs->Close(); |
| 536 | - if ( empty($retarr)) return $false; |
|
| 536 | + if (empty($retarr)) return $false; |
|
| 537 | 537 | else return $retarr; |
| 538 | 538 | } |
| 539 | 539 | |
| 540 | - function BlobEncode( $blob ) |
|
| 540 | + function BlobEncode($blob) |
|
| 541 | 541 | { |
| 542 | - $blobid = ibase_blob_create( $this->_connectionID); |
|
| 543 | - ibase_blob_add( $blobid, $blob ); |
|
| 544 | - return ibase_blob_close( $blobid ); |
|
| 542 | + $blobid = ibase_blob_create($this->_connectionID); |
|
| 543 | + ibase_blob_add($blobid, $blob); |
|
| 544 | + return ibase_blob_close($blobid); |
|
| 545 | 545 | } |
| 546 | 546 | |
| 547 | 547 | // since we auto-decode all blob's since 2.42, |
@@ -556,27 +556,27 @@ discard block |
||
| 556 | 556 | |
| 557 | 557 | // old blobdecode function |
| 558 | 558 | // still used to auto-decode all blob's |
| 559 | - function _BlobDecode( $blob ) |
|
| 559 | + function _BlobDecode($blob) |
|
| 560 | 560 | { |
| 561 | - $blobid = ibase_blob_open( $blob ); |
|
| 562 | - $realblob = ibase_blob_get( $blobid,$this->maxblobsize); // 2nd param is max size of blob -- Kevin Boillet <[email protected]> |
|
| 563 | - while($string = ibase_blob_get($blobid, 8192)){ |
|
| 561 | + $blobid = ibase_blob_open($blob); |
|
| 562 | + $realblob = ibase_blob_get($blobid, $this->maxblobsize); // 2nd param is max size of blob -- Kevin Boillet <[email protected]> |
|
| 563 | + while ($string = ibase_blob_get($blobid, 8192)) { |
|
| 564 | 564 | $realblob .= $string; |
| 565 | 565 | } |
| 566 | - ibase_blob_close( $blobid ); |
|
| 566 | + ibase_blob_close($blobid); |
|
| 567 | 567 | |
| 568 | - return( $realblob ); |
|
| 568 | + return($realblob); |
|
| 569 | 569 | } |
| 570 | 570 | |
| 571 | - function UpdateBlobFile($table,$column,$path,$where,$blobtype='BLOB') |
|
| 571 | + function UpdateBlobFile($table, $column, $path, $where, $blobtype = 'BLOB') |
|
| 572 | 572 | { |
| 573 | - $fd = fopen($path,'rb'); |
|
| 573 | + $fd = fopen($path, 'rb'); |
|
| 574 | 574 | if ($fd === false) return false; |
| 575 | 575 | $blob_id = ibase_blob_create($this->_connectionID); |
| 576 | 576 | |
| 577 | 577 | /* fill with data */ |
| 578 | 578 | |
| 579 | - while ($val = fread($fd,32768)){ |
|
| 579 | + while ($val = fread($fd, 32768)) { |
|
| 580 | 580 | ibase_blob_add($blob_id, $val); |
| 581 | 581 | } |
| 582 | 582 | |
@@ -584,7 +584,7 @@ discard block |
||
| 584 | 584 | $blob_id_str = ibase_blob_close($blob_id); |
| 585 | 585 | |
| 586 | 586 | fclose($fd); |
| 587 | - return $this->Execute("UPDATE $table SET $column=(?) WHERE $where",array($blob_id_str)) != false; |
|
| 587 | + return $this->Execute("UPDATE $table SET $column=(?) WHERE $where", array($blob_id_str)) != false; |
|
| 588 | 588 | } |
| 589 | 589 | |
| 590 | 590 | /* |
@@ -596,7 +596,7 @@ discard block |
||
| 596 | 596 | $conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, null)'); |
| 597 | 597 | $conn->UpdateBlob('blobtable','blobcol',$blob,'id=1'); |
| 598 | 598 | */ |
| 599 | - function UpdateBlob($table,$column,$val,$where,$blobtype='BLOB') |
|
| 599 | + function UpdateBlob($table, $column, $val, $where, $blobtype = 'BLOB') |
|
| 600 | 600 | { |
| 601 | 601 | $blob_id = ibase_blob_create($this->_connectionID); |
| 602 | 602 | |
@@ -625,32 +625,32 @@ discard block |
||
| 625 | 625 | |
| 626 | 626 | $blob_id_str = ibase_blob_close($blob_id); |
| 627 | 627 | |
| 628 | - return $this->Execute("UPDATE $table SET $column=(?) WHERE $where",array($blob_id_str)) != false; |
|
| 628 | + return $this->Execute("UPDATE $table SET $column=(?) WHERE $where", array($blob_id_str)) != false; |
|
| 629 | 629 | |
| 630 | 630 | } |
| 631 | 631 | |
| 632 | 632 | |
| 633 | - function OldUpdateBlob($table,$column,$val,$where,$blobtype='BLOB') |
|
| 633 | + function OldUpdateBlob($table, $column, $val, $where, $blobtype = 'BLOB') |
|
| 634 | 634 | { |
| 635 | 635 | $blob_id = ibase_blob_create($this->_connectionID); |
| 636 | 636 | ibase_blob_add($blob_id, $val); |
| 637 | 637 | $blob_id_str = ibase_blob_close($blob_id); |
| 638 | - return $this->Execute("UPDATE $table SET $column=(?) WHERE $where",array($blob_id_str)) != false; |
|
| 638 | + return $this->Execute("UPDATE $table SET $column=(?) WHERE $where", array($blob_id_str)) != false; |
|
| 639 | 639 | } |
| 640 | 640 | |
| 641 | 641 | // Format date column in sql string given an input format that understands Y M D |
| 642 | 642 | // Only since Interbase 6.0 - uses EXTRACT |
| 643 | 643 | // problem - does not zero-fill the day and month yet |
| 644 | - function SQLDate($fmt, $col=false) |
|
| 644 | + function SQLDate($fmt, $col = false) |
|
| 645 | 645 | { |
| 646 | 646 | if (!$col) $col = $this->sysDate; |
| 647 | 647 | $s = ''; |
| 648 | 648 | |
| 649 | 649 | $len = strlen($fmt); |
| 650 | - for ($i=0; $i < $len; $i++) { |
|
| 650 | + for ($i = 0; $i < $len; $i++) { |
|
| 651 | 651 | if ($s) $s .= '||'; |
| 652 | 652 | $ch = $fmt[$i]; |
| 653 | - switch($ch) { |
|
| 653 | + switch ($ch) { |
|
| 654 | 654 | case 'Y': |
| 655 | 655 | case 'y': |
| 656 | 656 | $s .= "extract(year from $col)"; |
@@ -683,7 +683,7 @@ discard block |
||
| 683 | 683 | default: |
| 684 | 684 | if ($ch == '\\') { |
| 685 | 685 | $i++; |
| 686 | - $ch = substr($fmt,$i,1); |
|
| 686 | + $ch = substr($fmt, $i, 1); |
|
| 687 | 687 | } |
| 688 | 688 | $s .= $this->qstr($ch); |
| 689 | 689 | break; |
@@ -701,10 +701,10 @@ discard block |
||
| 701 | 701 | { |
| 702 | 702 | |
| 703 | 703 | var $databaseType = "ibase"; |
| 704 | - var $bind=false; |
|
| 704 | + var $bind = false; |
|
| 705 | 705 | var $_cacheType; |
| 706 | 706 | |
| 707 | - function ADORecordset_ibase($id,$mode=false) |
|
| 707 | + function ADORecordset_ibase($id, $mode = false) |
|
| 708 | 708 | { |
| 709 | 709 | global $ADODB_FETCH_MODE; |
| 710 | 710 | |
@@ -720,7 +720,7 @@ discard block |
||
| 720 | 720 | function &FetchField($fieldOffset = -1) |
| 721 | 721 | { |
| 722 | 722 | $fld = new ADOFieldObject; |
| 723 | - $ibf = ibase_field_info($this->_queryID,$fieldOffset); |
|
| 723 | + $ibf = ibase_field_info($this->_queryID, $fieldOffset); |
|
| 724 | 724 | switch (ADODB_ASSOC_CASE) { |
| 725 | 725 | case 2: // the default |
| 726 | 726 | $fld->name = ($ibf['alias']); |
@@ -752,7 +752,7 @@ discard block |
||
| 752 | 752 | $this->_numOfFields = @ibase_num_fields($this->_queryID); |
| 753 | 753 | |
| 754 | 754 | // cache types for blob decode check |
| 755 | - for ($i=0, $max = $this->_numOfFields; $i < $max; $i++) { |
|
| 755 | + for ($i = 0, $max = $this->_numOfFields; $i < $max; $i++) { |
|
| 756 | 756 | $f1 = $this->FetchField($i); |
| 757 | 757 | $this->_cacheType[] = $f1->type; |
| 758 | 758 | } |
@@ -777,8 +777,8 @@ discard block |
||
| 777 | 777 | //$ADODB_ANSI_PADDING_OFF=1; |
| 778 | 778 | $rtrim = !empty($ADODB_ANSI_PADDING_OFF); |
| 779 | 779 | |
| 780 | - for ($i=0, $max = $this->_numOfFields; $i < $max; $i++) { |
|
| 781 | - if ($this->_cacheType[$i]=="BLOB") { |
|
| 780 | + for ($i = 0, $max = $this->_numOfFields; $i < $max; $i++) { |
|
| 781 | + if ($this->_cacheType[$i] == "BLOB") { |
|
| 782 | 782 | if (isset($f[$i])) { |
| 783 | 783 | $f[$i] = $this->connection->_BlobDecode($f[$i]); |
| 784 | 784 | } else { |
@@ -798,7 +798,7 @@ discard block |
||
| 798 | 798 | if ($this->fetchMode == ADODB_FETCH_ASSOC) { |
| 799 | 799 | $this->fields = &$this->GetRowAssoc(ADODB_ASSOC_CASE); |
| 800 | 800 | } else if ($this->fetchMode == ADODB_FETCH_BOTH) { |
| 801 | - $this->fields =& array_merge($this->fields,$this->GetRowAssoc(ADODB_ASSOC_CASE)); |
|
| 801 | + $this->fields = & array_merge($this->fields, $this->GetRowAssoc(ADODB_ASSOC_CASE)); |
|
| 802 | 802 | } |
| 803 | 803 | return true; |
| 804 | 804 | } |
@@ -806,10 +806,10 @@ discard block |
||
| 806 | 806 | /* Use associative array to get fields array */ |
| 807 | 807 | function Fields($colname) |
| 808 | 808 | { |
| 809 | - if ($this->fetchMode & ADODB_FETCH_ASSOC) return $this->fields[$colname]; |
|
| 809 | + if ($this->fetchMode&ADODB_FETCH_ASSOC) return $this->fields[$colname]; |
|
| 810 | 810 | if (!$this->bind) { |
| 811 | 811 | $this->bind = array(); |
| 812 | - for ($i=0; $i < $this->_numOfFields; $i++) { |
|
| 812 | + for ($i = 0; $i < $this->_numOfFields; $i++) { |
|
| 813 | 813 | $o = $this->FetchField($i); |
| 814 | 814 | $this->bind[strtoupper($o->name)] = $i; |
| 815 | 815 | } |
@@ -825,7 +825,7 @@ discard block |
||
| 825 | 825 | return @ibase_free_result($this->_queryID); |
| 826 | 826 | } |
| 827 | 827 | |
| 828 | - function MetaType($t,$len=-1,$fieldobj=false) |
|
| 828 | + function MetaType($t, $len = -1, $fieldobj = false) |
|
| 829 | 829 | { |
| 830 | 830 | if (is_object($t)) { |
| 831 | 831 | $fieldobj = $t; |
@@ -24,9 +24,13 @@ discard block |
||
| 24 | 24 | */ |
| 25 | 25 | |
| 26 | 26 | // security - hide paths |
| 27 | -if (!defined('ADODB_DIR')) die(); |
|
| 27 | +if (!defined('ADODB_DIR')) |
|
| 28 | +{ |
|
| 29 | + die(); |
|
| 30 | +} |
|
| 28 | 31 | |
| 29 | -class ADODB_ibase extends ADOConnection { |
|
| 32 | +class ADODB_ibase extends ADOConnection |
|
| 33 | +{ |
|
| 30 | 34 | var $databaseType = "ibase"; |
| 31 | 35 | var $dataProvider = "ibase"; |
| 32 | 36 | var $replaceQuote = "''"; // string to use to replace quotes |
@@ -54,41 +58,64 @@ discard block |
||
| 54 | 58 | var $blobEncodeType = 'C'; |
| 55 | 59 | var $role = false; |
| 56 | 60 | |
| 57 | - function ADODB_ibase() |
|
| 61 | + function ADODB_ibase() |
|
| 58 | 62 | { |
| 59 | - if (defined('IBASE_DEFAULT')) $this->ibasetrans = IBASE_DEFAULT; |
|
| 63 | + if (defined('IBASE_DEFAULT')) |
|
| 64 | + { |
|
| 65 | + $this->ibasetrans = IBASE_DEFAULT; |
|
| 66 | + } |
|
| 60 | 67 | } |
| 61 | 68 | |
| 62 | 69 | |
| 63 | 70 | // returns true or false |
| 64 | 71 | function _connect($argHostname, $argUsername, $argPassword, $argDatabasename,$persist=false) |
| 65 | - { |
|
| 66 | - if (!function_exists('ibase_pconnect')) return null; |
|
| 67 | - if ($argDatabasename) $argHostname .= ':'.$argDatabasename; |
|
| 72 | + { |
|
| 73 | + if (!function_exists('ibase_pconnect')) |
|
| 74 | + { |
|
| 75 | + return null; |
|
| 76 | + } |
|
| 77 | + if ($argDatabasename) |
|
| 78 | + { |
|
| 79 | + $argHostname .= ':'.$argDatabasename; |
|
| 80 | + } |
|
| 68 | 81 | $fn = ($persist) ? 'ibase_pconnect':'ibase_connect'; |
| 69 | 82 | if ($this->role) |
| 70 | - $this->_connectionID = $fn($argHostname,$argUsername,$argPassword, |
|
| 83 | + { |
|
| 84 | + $this->_connectionID = $fn($argHostname,$argUsername,$argPassword, |
|
| 71 | 85 | $this->charSet,$this->buffers,$this->dialect,$this->role); |
| 72 | - else |
|
| 73 | - $this->_connectionID = $fn($argHostname,$argUsername,$argPassword, |
|
| 86 | + } |
|
| 87 | + else { |
|
| 88 | + $this->_connectionID = $fn($argHostname,$argUsername,$argPassword, |
|
| 74 | 89 | $this->charSet,$this->buffers,$this->dialect); |
| 90 | + } |
|
| 75 | 91 | |
| 76 | - if ($this->dialect != 1) { // http://www.ibphoenix.com/ibp_60_del_id_ds.html |
|
| 92 | + if ($this->dialect != 1) |
|
| 93 | + { |
|
| 94 | +// http://www.ibphoenix.com/ibp_60_del_id_ds.html |
|
| 77 | 95 | $this->replaceQuote = "''"; |
| 78 | 96 | } |
| 79 | - if ($this->_connectionID === false) { |
|
| 97 | + if ($this->_connectionID === false) |
|
| 98 | + { |
|
| 80 | 99 | $this->_handleerror(); |
| 81 | 100 | return false; |
| 82 | 101 | } |
| 83 | 102 | |
| 84 | 103 | // PHP5 change. |
| 85 | - if (function_exists('ibase_timefmt')) { |
|
| 104 | + if (function_exists('ibase_timefmt')) |
|
| 105 | + { |
|
| 86 | 106 | ibase_timefmt($this->ibase_datefmt,IBASE_DATE ); |
| 87 | - if ($this->dialect == 1) ibase_timefmt($this->ibase_datefmt,IBASE_TIMESTAMP ); |
|
| 88 | - else ibase_timefmt($this->ibase_timestampfmt,IBASE_TIMESTAMP ); |
|
| 107 | + if ($this->dialect == 1) |
|
| 108 | + { |
|
| 109 | + ibase_timefmt($this->ibase_datefmt,IBASE_TIMESTAMP ); |
|
| 110 | + } |
|
| 111 | + else { |
|
| 112 | + ibase_timefmt($this->ibase_timestampfmt,IBASE_TIMESTAMP ); |
|
| 113 | + } |
|
| 89 | 114 | ibase_timefmt($this->ibase_timefmt,IBASE_TIME ); |
| 90 | 115 | |
| 91 | - } else { |
|
| 116 | + } |
|
| 117 | + else |
|
| 118 | + { |
|
| 92 | 119 | ini_set("ibase.timestampformat", $this->ibase_timestampfmt); |
| 93 | 120 | ini_set("ibase.dateformat", $this->ibase_datefmt); |
| 94 | 121 | ini_set("ibase.timeformat", $this->ibase_timefmt); |
@@ -103,8 +130,11 @@ discard block |
||
| 103 | 130 | |
| 104 | 131 | |
| 105 | 132 | function MetaPrimaryKeys($table,$owner_notused=false,$internalKey=false) |
| 106 | - { |
|
| 107 | - if ($internalKey) return array('RDB$DB_KEY'); |
|
| 133 | + { |
|
| 134 | + if ($internalKey) |
|
| 135 | + { |
|
| 136 | + return array('RDB$DB_KEY'); |
|
| 137 | + } |
|
| 108 | 138 | |
| 109 | 139 | $table = strtoupper($table); |
| 110 | 140 | |
@@ -114,14 +144,18 @@ discard block |
||
| 114 | 144 | ORDER BY I.RDB$INDEX_NAME,S.RDB$FIELD_POSITION'; |
| 115 | 145 | |
| 116 | 146 | $a = $this->GetCol($sql,false,true); |
| 117 | - if ($a && sizeof($a)>0) return $a; |
|
| 147 | + if ($a && sizeof($a)>0) |
|
| 148 | + { |
|
| 149 | + return $a; |
|
| 150 | + } |
|
| 118 | 151 | return false; |
| 119 | 152 | } |
| 120 | 153 | |
| 121 | 154 | function ServerInfo() |
| 122 | 155 | { |
| 123 | 156 | $arr['dialect'] = $this->dialect; |
| 124 | - switch($arr['dialect']) { |
|
| 157 | + switch($arr['dialect']) |
|
| 158 | + { |
|
| 125 | 159 | case '': |
| 126 | 160 | case '1': $s = 'Interbase 5.5 or earlier'; break; |
| 127 | 161 | case '2': $s = 'Interbase 5.6'; break; |
@@ -134,22 +168,35 @@ discard block |
||
| 134 | 168 | } |
| 135 | 169 | |
| 136 | 170 | function BeginTrans() |
| 137 | - { |
|
| 138 | - if ($this->transOff) return true; |
|
| 171 | + { |
|
| 172 | + if ($this->transOff) |
|
| 173 | + { |
|
| 174 | + return true; |
|
| 175 | + } |
|
| 139 | 176 | $this->transCnt += 1; |
| 140 | 177 | $this->autoCommit = false; |
| 141 | 178 | $this->_transactionID = $this->_connectionID;//ibase_trans($this->ibasetrans, $this->_connectionID); |
| 142 | 179 | return $this->_transactionID; |
| 143 | 180 | } |
| 144 | 181 | |
| 145 | - function CommitTrans($ok=true) |
|
| 146 | - { |
|
| 147 | - if (!$ok) return $this->RollbackTrans(); |
|
| 148 | - if ($this->transOff) return true; |
|
| 149 | - if ($this->transCnt) $this->transCnt -= 1; |
|
| 182 | + function CommitTrans($ok=true) |
|
| 183 | + { |
|
| 184 | + if (!$ok) |
|
| 185 | + { |
|
| 186 | + return $this->RollbackTrans(); |
|
| 187 | + } |
|
| 188 | + if ($this->transOff) |
|
| 189 | + { |
|
| 190 | + return true; |
|
| 191 | + } |
|
| 192 | + if ($this->transCnt) |
|
| 193 | + { |
|
| 194 | + $this->transCnt -= 1; |
|
| 195 | + } |
|
| 150 | 196 | $ret = false; |
| 151 | 197 | $this->autoCommit = true; |
| 152 | - if ($this->_transactionID) { |
|
| 198 | + if ($this->_transactionID) |
|
| 199 | + { |
|
| 153 | 200 | //print ' commit '; |
| 154 | 201 | $ret = ibase_commit($this->_transactionID); |
| 155 | 202 | } |
@@ -163,12 +210,15 @@ discard block |
||
| 163 | 210 | { |
| 164 | 211 | global $ADODB_COUNTRECS; |
| 165 | 212 | |
| 166 | - if ($this->_logsql) { |
|
| 213 | + if ($this->_logsql) |
|
| 214 | + { |
|
| 167 | 215 | $savecrecs = $ADODB_COUNTRECS; |
| 168 | 216 | $ADODB_COUNTRECS = true; // force countrecs |
| 169 | 217 | $ret =& ADOConnection::_Execute($sql,$inputarr); |
| 170 | 218 | $ADODB_COUNTRECS = $savecrecs; |
| 171 | - } else { |
|
| 219 | + } |
|
| 220 | + else |
|
| 221 | + { |
|
| 172 | 222 | $ret =& ADOConnection::_Execute($sql,$inputarr); |
| 173 | 223 | } |
| 174 | 224 | return $ret; |
@@ -176,12 +226,20 @@ discard block |
||
| 176 | 226 | |
| 177 | 227 | function RollbackTrans() |
| 178 | 228 | { |
| 179 | - if ($this->transOff) return true; |
|
| 180 | - if ($this->transCnt) $this->transCnt -= 1; |
|
| 229 | + if ($this->transOff) |
|
| 230 | + { |
|
| 231 | + return true; |
|
| 232 | + } |
|
| 233 | + if ($this->transCnt) |
|
| 234 | + { |
|
| 235 | + $this->transCnt -= 1; |
|
| 236 | + } |
|
| 181 | 237 | $ret = false; |
| 182 | 238 | $this->autoCommit = true; |
| 183 | - if ($this->_transactionID) |
|
| 184 | - $ret = ibase_rollback($this->_transactionID); |
|
| 239 | + if ($this->_transactionID) |
|
| 240 | + { |
|
| 241 | + $ret = ibase_rollback($this->_transactionID); |
|
| 242 | + } |
|
| 185 | 243 | $this->_transactionID = false; |
| 186 | 244 | |
| 187 | 245 | return $ret; |
@@ -194,21 +252,27 @@ discard block |
||
| 194 | 252 | $false = false; |
| 195 | 253 | $save = $ADODB_FETCH_MODE; |
| 196 | 254 | $ADODB_FETCH_MODE = ADODB_FETCH_NUM; |
| 197 | - if ($this->fetchMode !== FALSE) { |
|
| 255 | + if ($this->fetchMode !== FALSE) |
|
| 256 | + { |
|
| 198 | 257 | $savem = $this->SetFetchMode(FALSE); |
| 199 | 258 | } |
| 200 | 259 | $table = strtoupper($table); |
| 201 | 260 | $sql = "SELECT * FROM RDB\$INDICES WHERE RDB\$RELATION_NAME = '".$table."'"; |
| 202 | - if (!$primary) { |
|
| 261 | + if (!$primary) |
|
| 262 | + { |
|
| 203 | 263 | $sql .= " AND RDB\$INDEX_NAME NOT LIKE 'RDB\$%'"; |
| 204 | - } else { |
|
| 264 | + } |
|
| 265 | + else |
|
| 266 | + { |
|
| 205 | 267 | $sql .= " AND RDB\$INDEX_NAME NOT LIKE 'RDB\$FOREIGN%'"; |
| 206 | 268 | } |
| 207 | 269 | // get index details |
| 208 | 270 | $rs = $this->Execute($sql); |
| 209 | - if (!is_object($rs)) { |
|
| 271 | + if (!is_object($rs)) |
|
| 272 | + { |
|
| 210 | 273 | // restore fetchmode |
| 211 | - if (isset($savem)) { |
|
| 274 | + if (isset($savem)) |
|
| 275 | + { |
|
| 212 | 276 | $this->SetFetchMode($savem); |
| 213 | 277 | } |
| 214 | 278 | $ADODB_FETCH_MODE = $save; |
@@ -216,10 +280,14 @@ discard block |
||
| 216 | 280 | } |
| 217 | 281 | |
| 218 | 282 | $indexes = array (); |
| 219 | - while ($row = $rs->FetchRow()) { |
|
| 283 | + while ($row = $rs->FetchRow()) |
|
| 284 | + { |
|
| 220 | 285 | $index = $row[0]; |
| 221 | - if (!isset($indexes[$index])) { |
|
| 222 | - if (is_null($row[3])) {$row[3] = 0;} |
|
| 286 | + if (!isset($indexes[$index])) |
|
| 287 | + { |
|
| 288 | + if (is_null($row[3])) |
|
| 289 | + { |
|
| 290 | +$row[3] = 0;} |
|
| 223 | 291 | $indexes[$index] = array( |
| 224 | 292 | 'unique' => ($row[3] == 1), |
| 225 | 293 | 'columns' => array() |
@@ -227,12 +295,14 @@ discard block |
||
| 227 | 295 | } |
| 228 | 296 | $sql = "SELECT * FROM RDB\$INDEX_SEGMENTS WHERE RDB\$INDEX_NAME = '".$name."' ORDER BY RDB\$FIELD_POSITION ASC"; |
| 229 | 297 | $rs1 = $this->Execute($sql); |
| 230 | - while ($row1 = $rs1->FetchRow()) { |
|
| 298 | + while ($row1 = $rs1->FetchRow()) |
|
| 299 | + { |
|
| 231 | 300 | $indexes[$index]['columns'][$row1[2]] = $row1[1]; |
| 232 | 301 | } |
| 233 | 302 | } |
| 234 | 303 | // restore fetchmode |
| 235 | - if (isset($savem)) { |
|
| 304 | + if (isset($savem)) |
|
| 305 | + { |
|
| 236 | 306 | $this->SetFetchMode($savem); |
| 237 | 307 | } |
| 238 | 308 | $ADODB_FETCH_MODE = $save; |
@@ -244,7 +314,10 @@ discard block |
||
| 244 | 314 | // See http://community.borland.com/article/0,1410,25844,00.html |
| 245 | 315 | function RowLock($tables,$where,$col) |
| 246 | 316 | { |
| 247 | - if ($this->autoCommit) $this->BeginTrans(); |
|
| 317 | + if ($this->autoCommit) |
|
| 318 | + { |
|
| 319 | + $this->BeginTrans(); |
|
| 320 | + } |
|
| 248 | 321 | $this->Execute("UPDATE $table SET $col=$col WHERE $where "); // is this correct - jlim? |
| 249 | 322 | return 1; |
| 250 | 323 | } |
@@ -253,7 +326,10 @@ discard block |
||
| 253 | 326 | function CreateSequence($seqname,$startID=1) |
| 254 | 327 | { |
| 255 | 328 | $ok = $this->Execute(("INSERT INTO RDB\$GENERATORS (RDB\$GENERATOR_NAME) VALUES (UPPER('$seqname'))" )); |
| 256 | - if (!$ok) return false; |
|
| 329 | + if (!$ok) |
|
| 330 | + { |
|
| 331 | + return false; |
|
| 332 | + } |
|
| 257 | 333 | return $this->Execute("SET GENERATOR $seqname TO ".($startID-1).';'); |
| 258 | 334 | } |
| 259 | 335 | |
@@ -267,20 +343,30 @@ discard block |
||
| 267 | 343 | { |
| 268 | 344 | $getnext = ("SELECT Gen_ID($seqname,1) FROM RDB\$DATABASE"); |
| 269 | 345 | $rs = @$this->Execute($getnext); |
| 270 | - if (!$rs) { |
|
| 346 | + if (!$rs) |
|
| 347 | + { |
|
| 271 | 348 | $this->Execute(("INSERT INTO RDB\$GENERATORS (RDB\$GENERATOR_NAME) VALUES (UPPER('$seqname'))" )); |
| 272 | 349 | $this->Execute("SET GENERATOR $seqname TO ".($startID-1).';'); |
| 273 | 350 | $rs = $this->Execute($getnext); |
| 274 | 351 | } |
| 275 | - if ($rs && !$rs->EOF) $this->genID = (integer) reset($rs->fields); |
|
| 276 | - else $this->genID = 0; // false |
|
| 352 | + if ($rs && !$rs->EOF) |
|
| 353 | + { |
|
| 354 | + $this->genID = (integer) reset($rs->fields); |
|
| 355 | + } |
|
| 356 | + else { |
|
| 357 | + $this->genID = 0; |
|
| 358 | + } |
|
| 359 | + // false |
|
| 277 | 360 | |
| 278 | - if ($rs) $rs->Close(); |
|
| 361 | + if ($rs) |
|
| 362 | + { |
|
| 363 | + $rs->Close(); |
|
| 364 | + } |
|
| 279 | 365 | |
| 280 | 366 | return $this->genID; |
| 281 | 367 | } |
| 282 | 368 | |
| 283 | - function SelectDB($dbName) |
|
| 369 | + function SelectDB($dbName) |
|
| 284 | 370 | { |
| 285 | 371 | return false; |
| 286 | 372 | } |
@@ -290,13 +376,18 @@ discard block |
||
| 290 | 376 | $this->_errorMsg = ibase_errmsg(); |
| 291 | 377 | } |
| 292 | 378 | |
| 293 | - function ErrorNo() |
|
| 379 | + function ErrorNo() |
|
| 294 | 380 | { |
| 295 | - if (preg_match('/error code = ([\-0-9]*)/i', $this->_errorMsg,$arr)) return (integer) $arr[1]; |
|
| 296 | - else return 0; |
|
| 381 | + if (preg_match('/error code = ([\-0-9]*)/i', $this->_errorMsg,$arr)) |
|
| 382 | + { |
|
| 383 | + return (integer) $arr[1]; |
|
| 384 | + } |
|
| 385 | + else { |
|
| 386 | + return 0; |
|
| 387 | + } |
|
| 297 | 388 | } |
| 298 | 389 | |
| 299 | - function ErrorMsg() |
|
| 390 | + function ErrorMsg() |
|
| 300 | 391 | { |
| 301 | 392 | return $this->_errorMsg; |
| 302 | 393 | } |
@@ -304,32 +395,49 @@ discard block |
||
| 304 | 395 | function Prepare($sql) |
| 305 | 396 | { |
| 306 | 397 | $stmt = ibase_prepare($this->_connectionID,$sql); |
| 307 | - if (!$stmt) return false; |
|
| 398 | + if (!$stmt) |
|
| 399 | + { |
|
| 400 | + return false; |
|
| 401 | + } |
|
| 308 | 402 | return array($sql,$stmt); |
| 309 | 403 | } |
| 310 | 404 | |
| 311 | 405 | // returns query ID if successful, otherwise false |
| 312 | 406 | // there have been reports of problems with nested queries - the code is probably not re-entrant? |
| 313 | 407 | function _query($sql,$iarr=false) |
| 314 | - { |
|
| 408 | + { |
|
| 315 | 409 | |
| 316 | - if (!$this->autoCommit && $this->_transactionID) { |
|
| 410 | + if (!$this->autoCommit && $this->_transactionID) |
|
| 411 | + { |
|
| 317 | 412 | $conn = $this->_transactionID; |
| 318 | 413 | $docommit = false; |
| 319 | - } else { |
|
| 414 | + } |
|
| 415 | + else |
|
| 416 | + { |
|
| 320 | 417 | $conn = $this->_connectionID; |
| 321 | 418 | $docommit = true; |
| 322 | 419 | } |
| 323 | - if (is_array($sql)) { |
|
| 420 | + if (is_array($sql)) |
|
| 421 | + { |
|
| 324 | 422 | $fn = 'ibase_execute'; |
| 325 | 423 | $sql = $sql[1]; |
| 326 | - if (is_array($iarr)) { |
|
| 327 | - if (ADODB_PHPVER >= 0x4050) { // actually 4.0.4 |
|
| 328 | - if ( !isset($iarr[0]) ) $iarr[0] = ''; // PHP5 compat hack |
|
| 424 | + if (is_array($iarr)) |
|
| 425 | + { |
|
| 426 | + if (ADODB_PHPVER >= 0x4050) |
|
| 427 | + { |
|
| 428 | +// actually 4.0.4 |
|
| 429 | + if ( !isset($iarr[0]) ) |
|
| 430 | + { |
|
| 431 | + $iarr[0] = ''; |
|
| 432 | + } |
|
| 433 | + // PHP5 compat hack |
|
| 329 | 434 | $fnarr =& array_merge( array($sql) , $iarr); |
| 330 | 435 | $ret = call_user_func_array($fn,$fnarr); |
| 331 | - } else { |
|
| 332 | - switch(sizeof($iarr)) { |
|
| 436 | + } |
|
| 437 | + else |
|
| 438 | + { |
|
| 439 | + switch(sizeof($iarr)) |
|
| 440 | + { |
|
| 333 | 441 | case 1: $ret = $fn($sql,$iarr[0]); break; |
| 334 | 442 | case 2: $ret = $fn($sql,$iarr[0],$iarr[1]); break; |
| 335 | 443 | case 3: $ret = $fn($sql,$iarr[0],$iarr[1],$iarr[2]); break; |
@@ -341,17 +449,32 @@ discard block |
||
| 341 | 449 | case 8: $ret = $fn($sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4],$iarr[5],$iarr[6],$iarr[7]); break; |
| 342 | 450 | } |
| 343 | 451 | } |
| 344 | - } else $ret = $fn($sql); |
|
| 345 | - } else { |
|
| 452 | + } |
|
| 453 | + else { |
|
| 454 | + $ret = $fn($sql); |
|
| 455 | + } |
|
| 456 | + } |
|
| 457 | + else |
|
| 458 | + { |
|
| 346 | 459 | $fn = 'ibase_query'; |
| 347 | 460 | |
| 348 | - if (is_array($iarr)) { |
|
| 349 | - if (ADODB_PHPVER >= 0x4050) { // actually 4.0.4 |
|
| 350 | - if (sizeof($iarr) == 0) $iarr[0] = ''; // PHP5 compat hack |
|
| 461 | + if (is_array($iarr)) |
|
| 462 | + { |
|
| 463 | + if (ADODB_PHPVER >= 0x4050) |
|
| 464 | + { |
|
| 465 | +// actually 4.0.4 |
|
| 466 | + if (sizeof($iarr) == 0) |
|
| 467 | + { |
|
| 468 | + $iarr[0] = ''; |
|
| 469 | + } |
|
| 470 | + // PHP5 compat hack |
|
| 351 | 471 | $fnarr =& array_merge( array($conn,$sql) , $iarr); |
| 352 | 472 | $ret = call_user_func_array($fn,$fnarr); |
| 353 | - } else { |
|
| 354 | - switch(sizeof($iarr)) { |
|
| 473 | + } |
|
| 474 | + else |
|
| 475 | + { |
|
| 476 | + switch(sizeof($iarr)) |
|
| 477 | + { |
|
| 355 | 478 | case 1: $ret = $fn($conn,$sql,$iarr[0]); break; |
| 356 | 479 | case 2: $ret = $fn($conn,$sql,$iarr[0],$iarr[1]); break; |
| 357 | 480 | case 3: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2]); break; |
@@ -363,9 +486,15 @@ discard block |
||
| 363 | 486 | case 8: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4],$iarr[5],$iarr[6],$iarr[7]); break; |
| 364 | 487 | } |
| 365 | 488 | } |
| 366 | - } else $ret = $fn($conn,$sql); |
|
| 489 | + } |
|
| 490 | + else { |
|
| 491 | + $ret = $fn($conn,$sql); |
|
| 492 | + } |
|
| 493 | + } |
|
| 494 | + if ($docommit && $ret === true) |
|
| 495 | + { |
|
| 496 | + ibase_commit($this->_connectionID); |
|
| 367 | 497 | } |
| 368 | - if ($docommit && $ret === true) ibase_commit($this->_connectionID); |
|
| 369 | 498 | |
| 370 | 499 | $this->_handleerror(); |
| 371 | 500 | return $ret; |
@@ -373,8 +502,11 @@ discard block |
||
| 373 | 502 | |
| 374 | 503 | // returns true or false |
| 375 | 504 | function _close() |
| 376 | - { |
|
| 377 | - if (!$this->autoCommit) @ibase_rollback($this->_connectionID); |
|
| 505 | + { |
|
| 506 | + if (!$this->autoCommit) |
|
| 507 | + { |
|
| 508 | + @ibase_rollback($this->_connectionID); |
|
| 509 | + } |
|
| 378 | 510 | return @ibase_close($this->_connectionID); |
| 379 | 511 | } |
| 380 | 512 | |
@@ -384,11 +516,14 @@ discard block |
||
| 384 | 516 | $fscale = abs($fscale); |
| 385 | 517 | $fld->max_length = $flen; |
| 386 | 518 | $fld->scale = null; |
| 387 | - switch($ftype){ |
|
| 519 | + switch($ftype) |
|
| 520 | + { |
|
| 388 | 521 | case 7: |
| 389 | 522 | case 8: |
| 390 | - if ($dialect3) { |
|
| 391 | - switch($fsubtype){ |
|
| 523 | + if ($dialect3) |
|
| 524 | + { |
|
| 525 | + switch($fsubtype) |
|
| 526 | + { |
|
| 392 | 527 | case 0: |
| 393 | 528 | $fld->type = ($ftype == 7 ? 'smallint' : 'integer'); |
| 394 | 529 | break; |
@@ -403,19 +538,26 @@ discard block |
||
| 403 | 538 | $fld->scale = $fscale; |
| 404 | 539 | break; |
| 405 | 540 | } // switch |
| 406 | - } else { |
|
| 407 | - if ($fscale !=0) { |
|
| 541 | + } |
|
| 542 | + else |
|
| 543 | + { |
|
| 544 | + if ($fscale !=0) |
|
| 545 | + { |
|
| 408 | 546 | $fld->type = 'decimal'; |
| 409 | 547 | $fld->scale = $fscale; |
| 410 | 548 | $fld->max_length = ($ftype == 7 ? 4 : 9); |
| 411 | - } else { |
|
| 549 | + } |
|
| 550 | + else |
|
| 551 | + { |
|
| 412 | 552 | $fld->type = ($ftype == 7 ? 'smallint' : 'integer'); |
| 413 | 553 | } |
| 414 | 554 | } |
| 415 | 555 | break; |
| 416 | 556 | case 16: |
| 417 | - if ($dialect3) { |
|
| 418 | - switch($fsubtype){ |
|
| 557 | + if ($dialect3) |
|
| 558 | + { |
|
| 559 | + switch($fsubtype) |
|
| 560 | + { |
|
| 419 | 561 | case 0: |
| 420 | 562 | $fld->type = 'decimal'; |
| 421 | 563 | $fld->max_length = 18; |
@@ -441,18 +583,24 @@ discard block |
||
| 441 | 583 | $fld->type = 'char'; |
| 442 | 584 | break; |
| 443 | 585 | case 27: |
| 444 | - if ($fscale !=0) { |
|
| 586 | + if ($fscale !=0) |
|
| 587 | + { |
|
| 445 | 588 | $fld->type = 'decimal'; |
| 446 | 589 | $fld->max_length = 15; |
| 447 | 590 | $fld->scale = 5; |
| 448 | - } else { |
|
| 591 | + } |
|
| 592 | + else |
|
| 593 | + { |
|
| 449 | 594 | $fld->type = 'double'; |
| 450 | 595 | } |
| 451 | 596 | break; |
| 452 | 597 | case 35: |
| 453 | - if ($dialect3) { |
|
| 598 | + if ($dialect3) |
|
| 599 | + { |
|
| 454 | 600 | $fld->type = 'timestamp'; |
| 455 | - } else { |
|
| 601 | + } |
|
| 602 | + else |
|
| 603 | + { |
|
| 456 | 604 | $fld->type = 'date'; |
| 457 | 605 | } |
| 458 | 606 | break; |
@@ -487,7 +635,8 @@ discard block |
||
| 487 | 635 | |
| 488 | 636 | $ADODB_FETCH_MODE = $save; |
| 489 | 637 | $false = false; |
| 490 | - if ($rs === false) { |
|
| 638 | + if ($rs === false) |
|
| 639 | + { |
|
| 491 | 640 | return $false; |
| 492 | 641 | } |
| 493 | 642 | |
@@ -495,15 +644,19 @@ discard block |
||
| 495 | 644 | //OPN STUFF start |
| 496 | 645 | $dialect3 = ($this->dialect==3 ? true : false); |
| 497 | 646 | //OPN STUFF end |
| 498 | - while (!$rs->EOF) { //print_r($rs->fields); |
|
| 647 | + while (!$rs->EOF) |
|
| 648 | + { |
|
| 649 | +//print_r($rs->fields); |
|
| 499 | 650 | $fld = new ADOFieldObject(); |
| 500 | 651 | $fld->name = trim($rs->fields[0]); |
| 501 | 652 | //OPN STUFF start |
| 502 | 653 | $this->_ConvertFieldType($fld, $rs->fields[7], $rs->fields[3], $rs->fields[4], $rs->fields[5], $rs->fields[6], $dialect3); |
| 503 | - if (isset($rs->fields[1]) && $rs->fields[1]) { |
|
| 654 | + if (isset($rs->fields[1]) && $rs->fields[1]) |
|
| 655 | + { |
|
| 504 | 656 | $fld->not_null = true; |
| 505 | 657 | } |
| 506 | - if (isset($rs->fields[2])) { |
|
| 658 | + if (isset($rs->fields[2])) |
|
| 659 | + { |
|
| 507 | 660 | |
| 508 | 661 | $fld->has_default = true; |
| 509 | 662 | $d = substr($rs->fields[2],strlen('default ')); |
@@ -521,23 +674,36 @@ discard block |
||
| 521 | 674 | } |
| 522 | 675 | // case 35:$tt = 'TIMESTAMP'; break; |
| 523 | 676 | } |
| 524 | - if ((isset($rs->fields[5])) && ($fld->type == 'blob')) { |
|
| 677 | + if ((isset($rs->fields[5])) && ($fld->type == 'blob')) |
|
| 678 | + { |
|
| 525 | 679 | $fld->sub_type = $rs->fields[5]; |
| 526 | - } else { |
|
| 680 | + } |
|
| 681 | + else |
|
| 682 | + { |
|
| 527 | 683 | $fld->sub_type = null; |
| 528 | 684 | } |
| 529 | 685 | //OPN STUFF end |
| 530 | - if ($ADODB_FETCH_MODE == ADODB_FETCH_NUM) $retarr[] = $fld; |
|
| 531 | - else $retarr[strtoupper($fld->name)] = $fld; |
|
| 686 | + if ($ADODB_FETCH_MODE == ADODB_FETCH_NUM) |
|
| 687 | + { |
|
| 688 | + $retarr[] = $fld; |
|
| 689 | + } |
|
| 690 | + else { |
|
| 691 | + $retarr[strtoupper($fld->name)] = $fld; |
|
| 692 | + } |
|
| 532 | 693 | |
| 533 | 694 | $rs->MoveNext(); |
| 534 | 695 | } |
| 535 | 696 | $rs->Close(); |
| 536 | - if ( empty($retarr)) return $false; |
|
| 537 | - else return $retarr; |
|
| 697 | + if ( empty($retarr)) |
|
| 698 | + { |
|
| 699 | + return $false; |
|
| 700 | + } |
|
| 701 | + else { |
|
| 702 | + return $retarr; |
|
| 703 | + } |
|
| 538 | 704 | } |
| 539 | 705 | |
| 540 | - function BlobEncode( $blob ) |
|
| 706 | + function BlobEncode( $blob ) |
|
| 541 | 707 | { |
| 542 | 708 | $blobid = ibase_blob_create( $this->_connectionID); |
| 543 | 709 | ibase_blob_add( $blobid, $blob ); |
@@ -556,11 +722,12 @@ discard block |
||
| 556 | 722 | |
| 557 | 723 | // old blobdecode function |
| 558 | 724 | // still used to auto-decode all blob's |
| 559 | - function _BlobDecode( $blob ) |
|
| 725 | + function _BlobDecode( $blob ) |
|
| 560 | 726 | { |
| 561 | 727 | $blobid = ibase_blob_open( $blob ); |
| 562 | 728 | $realblob = ibase_blob_get( $blobid,$this->maxblobsize); // 2nd param is max size of blob -- Kevin Boillet <[email protected]> |
| 563 | - while($string = ibase_blob_get($blobid, 8192)){ |
|
| 729 | + while($string = ibase_blob_get($blobid, 8192)) |
|
| 730 | + { |
|
| 564 | 731 | $realblob .= $string; |
| 565 | 732 | } |
| 566 | 733 | ibase_blob_close( $blobid ); |
@@ -568,15 +735,19 @@ discard block |
||
| 568 | 735 | return( $realblob ); |
| 569 | 736 | } |
| 570 | 737 | |
| 571 | - function UpdateBlobFile($table,$column,$path,$where,$blobtype='BLOB') |
|
| 572 | - { |
|
| 738 | + function UpdateBlobFile($table,$column,$path,$where,$blobtype='BLOB') |
|
| 739 | + { |
|
| 573 | 740 | $fd = fopen($path,'rb'); |
| 574 | - if ($fd === false) return false; |
|
| 741 | + if ($fd === false) |
|
| 742 | + { |
|
| 743 | + return false; |
|
| 744 | + } |
|
| 575 | 745 | $blob_id = ibase_blob_create($this->_connectionID); |
| 576 | 746 | |
| 577 | 747 | /* fill with data */ |
| 578 | 748 | |
| 579 | - while ($val = fread($fd,32768)){ |
|
| 749 | + while ($val = fread($fd,32768)) |
|
| 750 | + { |
|
| 580 | 751 | ibase_blob_add($blob_id, $val); |
| 581 | 752 | } |
| 582 | 753 | |
@@ -596,8 +767,8 @@ discard block |
||
| 596 | 767 | $conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, null)'); |
| 597 | 768 | $conn->UpdateBlob('blobtable','blobcol',$blob,'id=1'); |
| 598 | 769 | */ |
| 599 | - function UpdateBlob($table,$column,$val,$where,$blobtype='BLOB') |
|
| 600 | - { |
|
| 770 | + function UpdateBlob($table,$column,$val,$where,$blobtype='BLOB') |
|
| 771 | + { |
|
| 601 | 772 | $blob_id = ibase_blob_create($this->_connectionID); |
| 602 | 773 | |
| 603 | 774 | // ibase_blob_add($blob_id, $val); |
@@ -610,13 +781,15 @@ discard block |
||
| 610 | 781 | $tail_size = $len % $chunk_size; |
| 611 | 782 | $n_chunks = ($len - $tail_size) / $chunk_size; |
| 612 | 783 | |
| 613 | - for ($n = 0; $n < $n_chunks; $n++) { |
|
| 784 | + for ($n = 0; $n < $n_chunks; $n++) |
|
| 785 | + { |
|
| 614 | 786 | $start = $n * $chunk_size; |
| 615 | 787 | $data = substr($val, $start, $chunk_size); |
| 616 | 788 | ibase_blob_add($blob_id, $data); |
| 617 | 789 | } |
| 618 | 790 | |
| 619 | - if ($tail_size) { |
|
| 791 | + if ($tail_size) |
|
| 792 | + { |
|
| 620 | 793 | $start = $n_chunks * $chunk_size; |
| 621 | 794 | $data = substr($val, $start, $tail_size); |
| 622 | 795 | ibase_blob_add($blob_id, $data); |
@@ -642,15 +815,23 @@ discard block |
||
| 642 | 815 | // Only since Interbase 6.0 - uses EXTRACT |
| 643 | 816 | // problem - does not zero-fill the day and month yet |
| 644 | 817 | function SQLDate($fmt, $col=false) |
| 645 | - { |
|
| 646 | - if (!$col) $col = $this->sysDate; |
|
| 818 | + { |
|
| 819 | + if (!$col) |
|
| 820 | + { |
|
| 821 | + $col = $this->sysDate; |
|
| 822 | + } |
|
| 647 | 823 | $s = ''; |
| 648 | 824 | |
| 649 | 825 | $len = strlen($fmt); |
| 650 | - for ($i=0; $i < $len; $i++) { |
|
| 651 | - if ($s) $s .= '||'; |
|
| 826 | + for ($i=0; $i < $len; $i++) |
|
| 827 | + { |
|
| 828 | + if ($s) |
|
| 829 | + { |
|
| 830 | + $s .= '||'; |
|
| 831 | + } |
|
| 652 | 832 | $ch = $fmt[$i]; |
| 653 | - switch($ch) { |
|
| 833 | + switch($ch) |
|
| 834 | + { |
|
| 654 | 835 | case 'Y': |
| 655 | 836 | case 'y': |
| 656 | 837 | $s .= "extract(year from $col)"; |
@@ -681,7 +862,8 @@ discard block |
||
| 681 | 862 | break; |
| 682 | 863 | |
| 683 | 864 | default: |
| 684 | - if ($ch == '\\') { |
|
| 865 | + if ($ch == '\\') |
|
| 866 | + { |
|
| 685 | 867 | $i++; |
| 686 | 868 | $ch = substr($fmt,$i,1); |
| 687 | 869 | } |
@@ -721,18 +903,28 @@ discard block |
||
| 721 | 903 | { |
| 722 | 904 | $fld = new ADOFieldObject; |
| 723 | 905 | $ibf = ibase_field_info($this->_queryID,$fieldOffset); |
| 724 | - switch (ADODB_ASSOC_CASE) { |
|
| 906 | + switch (ADODB_ASSOC_CASE) |
|
| 907 | + { |
|
| 725 | 908 | case 2: // the default |
| 726 | 909 | $fld->name = ($ibf['alias']); |
| 727 | - if (empty($fld->name)) $fld->name = ($ibf['name']); |
|
| 910 | + if (empty($fld->name)) |
|
| 911 | + { |
|
| 912 | + $fld->name = ($ibf['name']); |
|
| 913 | + } |
|
| 728 | 914 | break; |
| 729 | 915 | case 0: |
| 730 | 916 | $fld->name = strtoupper($ibf['alias']); |
| 731 | - if (empty($fld->name)) $fld->name = strtoupper($ibf['name']); |
|
| 917 | + if (empty($fld->name)) |
|
| 918 | + { |
|
| 919 | + $fld->name = strtoupper($ibf['name']); |
|
| 920 | + } |
|
| 732 | 921 | break; |
| 733 | 922 | case 1: |
| 734 | 923 | $fld->name = strtolower($ibf['alias']); |
| 735 | - if (empty($fld->name)) $fld->name = strtolower($ibf['name']); |
|
| 924 | + if (empty($fld->name)) |
|
| 925 | + { |
|
| 926 | + $fld->name = strtolower($ibf['name']); |
|
| 927 | + } |
|
| 736 | 928 | break; |
| 737 | 929 | } |
| 738 | 930 | |
@@ -752,7 +944,8 @@ discard block |
||
| 752 | 944 | $this->_numOfFields = @ibase_num_fields($this->_queryID); |
| 753 | 945 | |
| 754 | 946 | // cache types for blob decode check |
| 755 | - for ($i=0, $max = $this->_numOfFields; $i < $max; $i++) { |
|
| 947 | + for ($i=0, $max = $this->_numOfFields; $i < $max; $i++) |
|
| 948 | + { |
|
| 756 | 949 | $f1 = $this->FetchField($i); |
| 757 | 950 | $this->_cacheType[] = $f1->type; |
| 758 | 951 | } |
@@ -763,10 +956,11 @@ discard block |
||
| 763 | 956 | return false; |
| 764 | 957 | } |
| 765 | 958 | |
| 766 | - function _fetch() |
|
| 959 | + function _fetch() |
|
| 767 | 960 | { |
| 768 | 961 | $f = @ibase_fetch_row($this->_queryID); |
| 769 | - if ($f === false) { |
|
| 962 | + if ($f === false) |
|
| 963 | + { |
|
| 770 | 964 | $this->fields = false; |
| 771 | 965 | return false; |
| 772 | 966 | } |
@@ -777,17 +971,27 @@ discard block |
||
| 777 | 971 | //$ADODB_ANSI_PADDING_OFF=1; |
| 778 | 972 | $rtrim = !empty($ADODB_ANSI_PADDING_OFF); |
| 779 | 973 | |
| 780 | - for ($i=0, $max = $this->_numOfFields; $i < $max; $i++) { |
|
| 781 | - if ($this->_cacheType[$i]=="BLOB") { |
|
| 782 | - if (isset($f[$i])) { |
|
| 974 | + for ($i=0, $max = $this->_numOfFields; $i < $max; $i++) |
|
| 975 | + { |
|
| 976 | + if ($this->_cacheType[$i]=="BLOB") |
|
| 977 | + { |
|
| 978 | + if (isset($f[$i])) |
|
| 979 | + { |
|
| 783 | 980 | $f[$i] = $this->connection->_BlobDecode($f[$i]); |
| 784 | - } else { |
|
| 981 | + } |
|
| 982 | + else |
|
| 983 | + { |
|
| 785 | 984 | $f[$i] = null; |
| 786 | 985 | } |
| 787 | - } else { |
|
| 788 | - if (!isset($f[$i])) { |
|
| 986 | + } |
|
| 987 | + else |
|
| 988 | + { |
|
| 989 | + if (!isset($f[$i])) |
|
| 990 | + { |
|
| 789 | 991 | $f[$i] = null; |
| 790 | - } else if ($rtrim && is_string($f[$i])) { |
|
| 992 | + } |
|
| 993 | + else if ($rtrim && is_string($f[$i])) |
|
| 994 | + { |
|
| 791 | 995 | $f[$i] = rtrim($f[$i]); |
| 792 | 996 | } |
| 793 | 997 | } |
@@ -795,9 +999,12 @@ discard block |
||
| 795 | 999 | // OPN stuff end |
| 796 | 1000 | |
| 797 | 1001 | $this->fields = $f; |
| 798 | - if ($this->fetchMode == ADODB_FETCH_ASSOC) { |
|
| 1002 | + if ($this->fetchMode == ADODB_FETCH_ASSOC) |
|
| 1003 | + { |
|
| 799 | 1004 | $this->fields = &$this->GetRowAssoc(ADODB_ASSOC_CASE); |
| 800 | - } else if ($this->fetchMode == ADODB_FETCH_BOTH) { |
|
| 1005 | + } |
|
| 1006 | + else if ($this->fetchMode == ADODB_FETCH_BOTH) |
|
| 1007 | + { |
|
| 801 | 1008 | $this->fields =& array_merge($this->fields,$this->GetRowAssoc(ADODB_ASSOC_CASE)); |
| 802 | 1009 | } |
| 803 | 1010 | return true; |
@@ -806,10 +1013,15 @@ discard block |
||
| 806 | 1013 | /* Use associative array to get fields array */ |
| 807 | 1014 | function Fields($colname) |
| 808 | 1015 | { |
| 809 | - if ($this->fetchMode & ADODB_FETCH_ASSOC) return $this->fields[$colname]; |
|
| 810 | - if (!$this->bind) { |
|
| 1016 | + if ($this->fetchMode & ADODB_FETCH_ASSOC) |
|
| 1017 | + { |
|
| 1018 | + return $this->fields[$colname]; |
|
| 1019 | + } |
|
| 1020 | + if (!$this->bind) |
|
| 1021 | + { |
|
| 811 | 1022 | $this->bind = array(); |
| 812 | - for ($i=0; $i < $this->_numOfFields; $i++) { |
|
| 1023 | + for ($i=0; $i < $this->_numOfFields; $i++) |
|
| 1024 | + { |
|
| 813 | 1025 | $o = $this->FetchField($i); |
| 814 | 1026 | $this->bind[strtoupper($o->name)] = $i; |
| 815 | 1027 | } |
@@ -820,26 +1032,31 @@ discard block |
||
| 820 | 1032 | } |
| 821 | 1033 | |
| 822 | 1034 | |
| 823 | - function _close() |
|
| 1035 | + function _close() |
|
| 824 | 1036 | { |
| 825 | 1037 | return @ibase_free_result($this->_queryID); |
| 826 | 1038 | } |
| 827 | 1039 | |
| 828 | 1040 | function MetaType($t,$len=-1,$fieldobj=false) |
| 829 | 1041 | { |
| 830 | - if (is_object($t)) { |
|
| 1042 | + if (is_object($t)) |
|
| 1043 | + { |
|
| 831 | 1044 | $fieldobj = $t; |
| 832 | 1045 | $t = $fieldobj->type; |
| 833 | 1046 | $len = $fieldobj->max_length; |
| 834 | 1047 | } |
| 835 | - switch (strtoupper($t)) { |
|
| 1048 | + switch (strtoupper($t)) |
|
| 1049 | + { |
|
| 836 | 1050 | case 'CHAR': |
| 837 | 1051 | return 'C'; |
| 838 | 1052 | |
| 839 | 1053 | case 'TEXT': |
| 840 | 1054 | case 'VARCHAR': |
| 841 | 1055 | case 'VARYING': |
| 842 | - if ($len <= $this->blobSize) return 'C'; |
|
| 1056 | + if ($len <= $this->blobSize) |
|
| 1057 | + { |
|
| 1058 | + return 'C'; |
|
| 1059 | + } |
|
| 843 | 1060 | return 'X'; |
| 844 | 1061 | case 'BLOB': |
| 845 | 1062 | return 'B'; |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | function RowLock($tables,$where,$col) |
| 246 | 246 | { |
| 247 | 247 | if ($this->autoCommit) $this->BeginTrans(); |
| 248 | - $this->Execute("UPDATE $table SET $col=$col WHERE $where "); // is this correct - jlim? |
|
| 248 | + $this->Execute("update $table SET $col=$col WHERE $where "); // is this correct - jlim? |
|
| 249 | 249 | return 1; |
| 250 | 250 | } |
| 251 | 251 | |
@@ -584,7 +584,7 @@ discard block |
||
| 584 | 584 | $blob_id_str = ibase_blob_close($blob_id); |
| 585 | 585 | |
| 586 | 586 | fclose($fd); |
| 587 | - return $this->Execute("UPDATE $table SET $column=(?) WHERE $where",array($blob_id_str)) != false; |
|
| 587 | + return $this->Execute("update $table SET $column=(?) WHERE $where",array($blob_id_str)) != false; |
|
| 588 | 588 | } |
| 589 | 589 | |
| 590 | 590 | /* |
@@ -625,7 +625,7 @@ discard block |
||
| 625 | 625 | |
| 626 | 626 | $blob_id_str = ibase_blob_close($blob_id); |
| 627 | 627 | |
| 628 | - return $this->Execute("UPDATE $table SET $column=(?) WHERE $where",array($blob_id_str)) != false; |
|
| 628 | + return $this->Execute("update $table SET $column=(?) WHERE $where",array($blob_id_str)) != false; |
|
| 629 | 629 | |
| 630 | 630 | } |
| 631 | 631 | |
@@ -635,7 +635,7 @@ discard block |
||
| 635 | 635 | $blob_id = ibase_blob_create($this->_connectionID); |
| 636 | 636 | ibase_blob_add($blob_id, $val); |
| 637 | 637 | $blob_id_str = ibase_blob_close($blob_id); |
| 638 | - return $this->Execute("UPDATE $table SET $column=(?) WHERE $where",array($blob_id_str)) != false; |
|
| 638 | + return $this->Execute("update $table SET $column=(?) WHERE $where",array($blob_id_str)) != false; |
|
| 639 | 639 | } |
| 640 | 640 | |
| 641 | 641 | // Format date column in sql string given an input format that understands Y M D |
@@ -524,6 +524,9 @@ discard block |
||
| 524 | 524 | return array($sql,$this->qstr($sql2),$max); |
| 525 | 525 | } |
| 526 | 526 | |
| 527 | + /** |
|
| 528 | + * @param string $sql |
|
| 529 | + */ |
|
| 527 | 530 | function PrepareSP($sql) |
| 528 | 531 | { |
| 529 | 532 | if (!$this->_has_mssql_init) { |
@@ -577,6 +580,11 @@ discard block |
||
| 577 | 580 | |
| 578 | 581 | See mssql_bind documentation at php.net. |
| 579 | 582 | */ |
| 583 | + |
|
| 584 | + /** |
|
| 585 | + * @param integer $var |
|
| 586 | + * @param string $name |
|
| 587 | + */ |
|
| 580 | 588 | function Parameter(&$stmt, &$var, $name, $isOutput=false, $maxLen=4000, $type=false) |
| 581 | 589 | { |
| 582 | 590 | if (!$this->_has_mssql_init) { |
@@ -327,29 +327,29 @@ discard block |
||
| 327 | 327 | |
| 328 | 328 | global $ADODB_FETCH_MODE; |
| 329 | 329 | $save = $ADODB_FETCH_MODE; |
| 330 | - $ADODB_FETCH_MODE = ADODB_FETCH_NUM; |
|
| 331 | - if ($this->fetchMode !== FALSE) { |
|
| 332 | - $savem = $this->SetFetchMode(FALSE); |
|
| 333 | - } |
|
| 330 | + $ADODB_FETCH_MODE = ADODB_FETCH_NUM; |
|
| 331 | + if ($this->fetchMode !== FALSE) { |
|
| 332 | + $savem = $this->SetFetchMode(FALSE); |
|
| 333 | + } |
|
| 334 | 334 | |
| 335 | - $rs = $this->Execute($sql); |
|
| 336 | - if (isset($savem)) { |
|
| 337 | - $this->SetFetchMode($savem); |
|
| 338 | - } |
|
| 339 | - $ADODB_FETCH_MODE = $save; |
|
| 335 | + $rs = $this->Execute($sql); |
|
| 336 | + if (isset($savem)) { |
|
| 337 | + $this->SetFetchMode($savem); |
|
| 338 | + } |
|
| 339 | + $ADODB_FETCH_MODE = $save; |
|
| 340 | 340 | |
| 341 | - if (!is_object($rs)) { |
|
| 342 | - return FALSE; |
|
| 343 | - } |
|
| 341 | + if (!is_object($rs)) { |
|
| 342 | + return FALSE; |
|
| 343 | + } |
|
| 344 | 344 | |
| 345 | 345 | $indexes = array(); |
| 346 | 346 | while ($row = $rs->FetchRow()) { |
| 347 | 347 | if (!$primary && $row[5]) continue; |
| 348 | 348 | |
| 349 | - $indexes[$row[0]]['unique'] = $row[6]; |
|
| 350 | - $indexes[$row[0]]['columns'][] = $row[1]; |
|
| 351 | - } |
|
| 352 | - return $indexes; |
|
| 349 | + $indexes[$row[0]]['unique'] = $row[6]; |
|
| 350 | + $indexes[$row[0]]['columns'][] = $row[1]; |
|
| 351 | + } |
|
| 352 | + return $indexes; |
|
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | function MetaForeignKeys($table, $owner=false, $upper=false) |
@@ -536,28 +536,28 @@ discard block |
||
| 536 | 536 | } |
| 537 | 537 | |
| 538 | 538 | // returns concatenated string |
| 539 | - // MSSQL requires integers to be cast as strings |
|
| 540 | - // automatically cast every datatype to VARCHAR(255) |
|
| 541 | - // @author David Rogers (introspectshun) |
|
| 542 | - function Concat() |
|
| 543 | - { |
|
| 544 | - $s = ""; |
|
| 545 | - $arr = func_get_args(); |
|
| 546 | - |
|
| 547 | - // Split single record on commas, if possible |
|
| 548 | - if (sizeof($arr) == 1) { |
|
| 549 | - foreach ($arr as $arg) { |
|
| 550 | - $args = explode(',', $arg); |
|
| 551 | - } |
|
| 552 | - $arr = $args; |
|
| 553 | - } |
|
| 554 | - |
|
| 555 | - array_walk($arr, create_function('&$v', '$v = "CAST(" . $v . " AS VARCHAR(255))";')); |
|
| 556 | - $s = implode('+',$arr); |
|
| 557 | - if (sizeof($arr) > 0) return "$s"; |
|
| 539 | + // MSSQL requires integers to be cast as strings |
|
| 540 | + // automatically cast every datatype to VARCHAR(255) |
|
| 541 | + // @author David Rogers (introspectshun) |
|
| 542 | + function Concat() |
|
| 543 | + { |
|
| 544 | + $s = ""; |
|
| 545 | + $arr = func_get_args(); |
|
| 546 | + |
|
| 547 | + // Split single record on commas, if possible |
|
| 548 | + if (sizeof($arr) == 1) { |
|
| 549 | + foreach ($arr as $arg) { |
|
| 550 | + $args = explode(',', $arg); |
|
| 551 | + } |
|
| 552 | + $arr = $args; |
|
| 553 | + } |
|
| 554 | + |
|
| 555 | + array_walk($arr, create_function('&$v', '$v = "CAST(" . $v . " AS VARCHAR(255))";')); |
|
| 556 | + $s = implode('+',$arr); |
|
| 557 | + if (sizeof($arr) > 0) return "$s"; |
|
| 558 | 558 | |
| 559 | 559 | return ''; |
| 560 | - } |
|
| 560 | + } |
|
| 561 | 561 | |
| 562 | 562 | /* |
| 563 | 563 | Usage: |
@@ -219,50 +219,50 @@ discard block |
||
| 219 | 219 | if ($s) $s .= '+'; |
| 220 | 220 | $ch = $fmt[$i]; |
| 221 | 221 | switch($ch) { |
| 222 | - case 'Y': |
|
| 223 | - case 'y': |
|
| 224 | - $s .= "datename(yyyy,$col)"; |
|
| 225 | - break; |
|
| 226 | - case 'M': |
|
| 227 | - $s .= "convert(char(3),$col,0)"; |
|
| 228 | - break; |
|
| 229 | - case 'm': |
|
| 230 | - $s .= "replace(str(month($col),2),' ','0')"; |
|
| 231 | - break; |
|
| 232 | - case 'Q': |
|
| 233 | - case 'q': |
|
| 234 | - $s .= "datename(quarter,$col)"; |
|
| 235 | - break; |
|
| 236 | - case 'D': |
|
| 237 | - case 'd': |
|
| 238 | - $s .= "replace(str(day($col),2),' ','0')"; |
|
| 239 | - break; |
|
| 240 | - case 'h': |
|
| 241 | - $s .= "substring(convert(char(14),$col,0),13,2)"; |
|
| 242 | - break; |
|
| 222 | + case 'Y': |
|
| 223 | + case 'y': |
|
| 224 | + $s .= "datename(yyyy,$col)"; |
|
| 225 | + break; |
|
| 226 | + case 'M': |
|
| 227 | + $s .= "convert(char(3),$col,0)"; |
|
| 228 | + break; |
|
| 229 | + case 'm': |
|
| 230 | + $s .= "replace(str(month($col),2),' ','0')"; |
|
| 231 | + break; |
|
| 232 | + case 'Q': |
|
| 233 | + case 'q': |
|
| 234 | + $s .= "datename(quarter,$col)"; |
|
| 235 | + break; |
|
| 236 | + case 'D': |
|
| 237 | + case 'd': |
|
| 238 | + $s .= "replace(str(day($col),2),' ','0')"; |
|
| 239 | + break; |
|
| 240 | + case 'h': |
|
| 241 | + $s .= "substring(convert(char(14),$col,0),13,2)"; |
|
| 242 | + break; |
|
| 243 | 243 | |
| 244 | - case 'H': |
|
| 245 | - $s .= "replace(str(datepart(hh,$col),2),' ','0')"; |
|
| 246 | - break; |
|
| 244 | + case 'H': |
|
| 245 | + $s .= "replace(str(datepart(hh,$col),2),' ','0')"; |
|
| 246 | + break; |
|
| 247 | 247 | |
| 248 | - case 'i': |
|
| 249 | - $s .= "replace(str(datepart(mi,$col),2),' ','0')"; |
|
| 250 | - break; |
|
| 251 | - case 's': |
|
| 252 | - $s .= "replace(str(datepart(ss,$col),2),' ','0')"; |
|
| 253 | - break; |
|
| 254 | - case 'a': |
|
| 255 | - case 'A': |
|
| 256 | - $s .= "substring(convert(char(19),$col,0),18,2)"; |
|
| 257 | - break; |
|
| 248 | + case 'i': |
|
| 249 | + $s .= "replace(str(datepart(mi,$col),2),' ','0')"; |
|
| 250 | + break; |
|
| 251 | + case 's': |
|
| 252 | + $s .= "replace(str(datepart(ss,$col),2),' ','0')"; |
|
| 253 | + break; |
|
| 254 | + case 'a': |
|
| 255 | + case 'A': |
|
| 256 | + $s .= "substring(convert(char(19),$col,0),18,2)"; |
|
| 257 | + break; |
|
| 258 | 258 | |
| 259 | - default: |
|
| 260 | - if ($ch == '\\') { |
|
| 261 | - $i++; |
|
| 262 | - $ch = substr($fmt,$i,1); |
|
| 263 | - } |
|
| 264 | - $s .= $this->qstr($ch); |
|
| 265 | - break; |
|
| 259 | + default: |
|
| 260 | + if ($ch == '\\') { |
|
| 261 | + $i++; |
|
| 262 | + $ch = substr($fmt,$i,1); |
|
| 263 | + } |
|
| 264 | + $s .= $this->qstr($ch); |
|
| 265 | + break; |
|
| 266 | 266 | } |
| 267 | 267 | } |
| 268 | 268 | return $s; |
@@ -588,11 +588,11 @@ discard block |
||
| 588 | 588 | |
| 589 | 589 | if ($type === false) |
| 590 | 590 | switch(gettype($var)) { |
| 591 | - default: |
|
| 592 | - case 'string': $type = SQLCHAR; break; |
|
| 593 | - case 'double': $type = SQLFLT8; break; |
|
| 594 | - case 'integer': $type = SQLINT4; break; |
|
| 595 | - case 'boolean': $type = SQLINT1; break; # SQLBIT not supported in 4.1.0 |
|
| 591 | + default: |
|
| 592 | + case 'string': $type = SQLCHAR; break; |
|
| 593 | + case 'double': $type = SQLFLT8; break; |
|
| 594 | + case 'integer': $type = SQLINT4; break; |
|
| 595 | + case 'boolean': $type = SQLINT1; break; # SQLBIT not supported in 4.1.0 |
|
| 596 | 596 | } |
| 597 | 597 | |
| 598 | 598 | if ($this->debug) { |
@@ -978,14 +978,14 @@ discard block |
||
| 978 | 978 | if ($themth <= 0) return false; |
| 979 | 979 | |
| 980 | 980 | switch (strtoupper($rr[6])) { |
| 981 | - case 'P': |
|
| 982 | - if ($rr[4]<12) $rr[4] += 12; |
|
| 983 | - break; |
|
| 984 | - case 'A': |
|
| 985 | - if ($rr[4]==12) $rr[4] = 0; |
|
| 986 | - break; |
|
| 987 | - default: |
|
| 988 | - break; |
|
| 981 | + case 'P': |
|
| 982 | + if ($rr[4]<12) $rr[4] += 12; |
|
| 983 | + break; |
|
| 984 | + case 'A': |
|
| 985 | + if ($rr[4]==12) $rr[4] = 0; |
|
| 986 | + break; |
|
| 987 | + default: |
|
| 988 | + break; |
|
| 989 | 989 | } |
| 990 | 990 | // h-m-s-MM-DD-YY |
| 991 | 991 | return mktime($rr[4],$rr[5],0,$themth,$theday,$rr[3]); |
@@ -39,15 +39,15 @@ discard block |
||
| 39 | 39 | // has datetime converstion to YYYY-MM-DD format, and also mssql_fetch_assoc |
| 40 | 40 | if (ADODB_PHPVER >= 0x4300) { |
| 41 | 41 | // docs say 4.2.0, but testing shows only since 4.3.0 does it work! |
| 42 | - ini_set('mssql.datetimeconvert',0); |
|
| 42 | + ini_set('mssql.datetimeconvert', 0); |
|
| 43 | 43 | } else { |
| 44 | -global $ADODB_mssql_mths; // array, months must be upper-case |
|
| 44 | +global $ADODB_mssql_mths; // array, months must be upper-case |
|
| 45 | 45 | |
| 46 | 46 | |
| 47 | 47 | $ADODB_mssql_date_order = 'mdy'; |
| 48 | 48 | $ADODB_mssql_mths = array( |
| 49 | - 'JAN'=>1,'FEB'=>2,'MAR'=>3,'APR'=>4,'MAY'=>5,'JUN'=>6, |
|
| 50 | - 'JUL'=>7,'AUG'=>8,'SEP'=>9,'OCT'=>10,'NOV'=>11,'DEC'=>12); |
|
| 49 | + 'JAN'=>1, 'FEB'=>2, 'MAR'=>3, 'APR'=>4, 'MAY'=>5, 'JUN'=>6, |
|
| 50 | + 'JUL'=>7, 'AUG'=>8, 'SEP'=>9, 'OCT'=>10, 'NOV'=>11, 'DEC'=>12); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | //--------------------------------------------------------------------------- |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | global $ADODB_mssql_date_order; |
| 60 | 60 | $adate = $conn->GetOne('select getdate()'); |
| 61 | 61 | if ($adate) { |
| 62 | - $anum = (int) $adate; |
|
| 62 | + $anum = (int)$adate; |
|
| 63 | 63 | if ($anum > 0) { |
| 64 | 64 | if ($anum > 31) { |
| 65 | 65 | //ADOConnection::outp( "MSSQL: YYYY-MM-DD date format not supported currently"); |
@@ -81,13 +81,13 @@ discard block |
||
| 81 | 81 | var $length = 'len'; |
| 82 | 82 | var $hasAffectedRows = true; |
| 83 | 83 | var $metaDatabasesSQL = "select name from sysdatabases where name <> 'master'"; |
| 84 | - var $metaTablesSQL="select name,case when type='U' then 'T' else 'V' end from sysobjects where (type='U' or type='V') and (name not in ('sysallocations','syscolumns','syscomments','sysdepends','sysfilegroups','sysfiles','sysfiles1','sysforeignkeys','sysfulltextcatalogs','sysindexes','sysindexkeys','sysmembers','sysobjects','syspermissions','sysprotects','sysreferences','systypes','sysusers','sysalternates','sysconstraints','syssegments','REFERENTIAL_CONSTRAINTS','CHECK_CONSTRAINTS','CONSTRAINT_TABLE_USAGE','CONSTRAINT_COLUMN_USAGE','VIEWS','VIEW_TABLE_USAGE','VIEW_COLUMN_USAGE','SCHEMATA','TABLES','TABLE_CONSTRAINTS','TABLE_PRIVILEGES','COLUMNS','COLUMN_DOMAIN_USAGE','COLUMN_PRIVILEGES','DOMAINS','DOMAIN_CONSTRAINTS','KEY_COLUMN_USAGE','dtproperties'))"; |
|
| 84 | + var $metaTablesSQL = "select name,case when type='U' then 'T' else 'V' end from sysobjects where (type='U' or type='V') and (name not in ('sysallocations','syscolumns','syscomments','sysdepends','sysfilegroups','sysfiles','sysfiles1','sysforeignkeys','sysfulltextcatalogs','sysindexes','sysindexkeys','sysmembers','sysobjects','syspermissions','sysprotects','sysreferences','systypes','sysusers','sysalternates','sysconstraints','syssegments','REFERENTIAL_CONSTRAINTS','CHECK_CONSTRAINTS','CONSTRAINT_TABLE_USAGE','CONSTRAINT_COLUMN_USAGE','VIEWS','VIEW_TABLE_USAGE','VIEW_COLUMN_USAGE','SCHEMATA','TABLES','TABLE_CONSTRAINTS','TABLE_PRIVILEGES','COLUMNS','COLUMN_DOMAIN_USAGE','COLUMN_PRIVILEGES','DOMAINS','DOMAIN_CONSTRAINTS','KEY_COLUMN_USAGE','dtproperties'))"; |
|
| 85 | 85 | var $metaColumnsSQL = # xtype==61 is datetime |
| 86 | 86 | "select c.name,t.name,c.length, |
| 87 | 87 | (case when c.xusertype=61 then 0 else c.xprec end), |
| 88 | 88 | (case when c.xusertype=61 then 0 else c.xscale end) |
| 89 | 89 | from syscolumns c join systypes t on t.xusertype=c.xusertype join sysobjects o on o.id=c.id where o.name='%s'"; |
| 90 | - var $hasTop = 'top'; // support mssql SELECT TOP 10 * FROM TABLE |
|
| 90 | + var $hasTop = 'top'; // support mssql SELECT TOP 10 * FROM TABLE |
|
| 91 | 91 | var $hasGenID = true; |
| 92 | 92 | var $sysDate = 'convert(datetime,convert(char,GetDate(),102),102)'; |
| 93 | 93 | var $sysTimeStamp = 'GetDate()'; |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | |
| 106 | 106 | function ADODB_mssql() |
| 107 | 107 | { |
| 108 | - $this->_has_mssql_init = (strnatcmp(PHP_VERSION,'4.1.0')>=0); |
|
| 108 | + $this->_has_mssql_init = (strnatcmp(PHP_VERSION, '4.1.0') >= 0); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | function ServerInfo() |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | $savem = $this->SetFetchMode(ADODB_FETCH_NUM); |
| 122 | 122 | |
| 123 | 123 | |
| 124 | - $this->Parameter($stmt,$val,'attribute_id'); |
|
| 124 | + $this->Parameter($stmt, $val, 'attribute_id'); |
|
| 125 | 125 | $row = $this->GetRow($stmt); |
| 126 | 126 | |
| 127 | 127 | //$row = $this->GetRow("execute sp_server_info 2"); |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | return $arr; |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | - function IfNull( $field, $ifNull ) |
|
| 139 | + function IfNull($field, $ifNull) |
|
| 140 | 140 | { |
| 141 | 141 | return " ISNULL($field, $ifNull) "; // if MS SQL Server |
| 142 | 142 | } |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | |
| 159 | 159 | var $_dropSeqSQL = "drop table %s"; |
| 160 | 160 | |
| 161 | - function CreateSequence($seq='adodbseq',$start=1) |
|
| 161 | + function CreateSequence($seq = 'adodbseq', $start = 1) |
|
| 162 | 162 | { |
| 163 | 163 | $start -= 1; |
| 164 | 164 | $this->Execute("create table $seq (id float(53))"); |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | return true; |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | - function GenID($seq='adodbseq',$start=1) |
|
| 174 | + function GenID($seq = 'adodbseq', $start = 1) |
|
| 175 | 175 | { |
| 176 | 176 | //$this->debug=1; |
| 177 | 177 | $this->Execute('BEGIN TRANSACTION adodbseq'); |
@@ -195,30 +195,30 @@ discard block |
||
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | |
| 198 | - function &SelectLimit($sql,$nrows=-1,$offset=-1, $inputarr=false,$secs2cache=0) |
|
| 198 | + function &SelectLimit($sql, $nrows = -1, $offset = -1, $inputarr = false, $secs2cache = 0) |
|
| 199 | 199 | { |
| 200 | 200 | if ($nrows > 0 && $offset <= 0) { |
| 201 | 201 | $sql = preg_replace( |
| 202 | - '/(^\s*select\s+(distinctrow|distinct)?)/i','\\1 '.$this->hasTop." $nrows ",$sql); |
|
| 203 | - $rs =& $this->Execute($sql,$inputarr); |
|
| 202 | + '/(^\s*select\s+(distinctrow|distinct)?)/i', '\\1 '.$this->hasTop." $nrows ", $sql); |
|
| 203 | + $rs = & $this->Execute($sql, $inputarr); |
|
| 204 | 204 | } else |
| 205 | - $rs =& ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache); |
|
| 205 | + $rs = & ADOConnection::SelectLimit($sql, $nrows, $offset, $inputarr, $secs2cache); |
|
| 206 | 206 | |
| 207 | 207 | return $rs; |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | |
| 211 | 211 | // Format date column in sql string given an input format that understands Y M D |
| 212 | - function SQLDate($fmt, $col=false) |
|
| 212 | + function SQLDate($fmt, $col = false) |
|
| 213 | 213 | { |
| 214 | 214 | if (!$col) $col = $this->sysTimeStamp; |
| 215 | 215 | $s = ''; |
| 216 | 216 | |
| 217 | 217 | $len = strlen($fmt); |
| 218 | - for ($i=0; $i < $len; $i++) { |
|
| 218 | + for ($i = 0; $i < $len; $i++) { |
|
| 219 | 219 | if ($s) $s .= '+'; |
| 220 | 220 | $ch = $fmt[$i]; |
| 221 | - switch($ch) { |
|
| 221 | + switch ($ch) { |
|
| 222 | 222 | case 'Y': |
| 223 | 223 | case 'y': |
| 224 | 224 | $s .= "datename(yyyy,$col)"; |
@@ -259,7 +259,7 @@ discard block |
||
| 259 | 259 | default: |
| 260 | 260 | if ($ch == '\\') { |
| 261 | 261 | $i++; |
| 262 | - $ch = substr($fmt,$i,1); |
|
| 262 | + $ch = substr($fmt, $i, 1); |
|
| 263 | 263 | } |
| 264 | 264 | $s .= $this->qstr($ch); |
| 265 | 265 | break; |
@@ -277,7 +277,7 @@ discard block |
||
| 277 | 277 | return true; |
| 278 | 278 | } |
| 279 | 279 | |
| 280 | - function CommitTrans($ok=true) |
|
| 280 | + function CommitTrans($ok = true) |
|
| 281 | 281 | { |
| 282 | 282 | if ($this->transOff) return true; |
| 283 | 283 | if (!$ok) return $this->RollbackTrans(); |
@@ -305,14 +305,14 @@ discard block |
||
| 305 | 305 | |
| 306 | 306 | See http://www.swynk.com/friends/achigrik/SQL70Locks.asp |
| 307 | 307 | */ |
| 308 | - function RowLock($tables,$where,$flds='top 1 null as ignore') |
|
| 308 | + function RowLock($tables, $where, $flds = 'top 1 null as ignore') |
|
| 309 | 309 | { |
| 310 | 310 | if (!$this->transCnt) $this->BeginTrans(); |
| 311 | 311 | return $this->GetOne("select $flds from $tables with (ROWLOCK,HOLDLOCK) where $where"); |
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | |
| 315 | - function &MetaIndexes($table,$primary=false) |
|
| 315 | + function &MetaIndexes($table, $primary = false) |
|
| 316 | 316 | { |
| 317 | 317 | $table = $this->qstr($table); |
| 318 | 318 | |
@@ -352,7 +352,7 @@ discard block |
||
| 352 | 352 | return $indexes; |
| 353 | 353 | } |
| 354 | 354 | |
| 355 | - function MetaForeignKeys($table, $owner=false, $upper=false) |
|
| 355 | + function MetaForeignKeys($table, $owner = false, $upper = false) |
|
| 356 | 356 | { |
| 357 | 357 | global $ADODB_FETCH_MODE; |
| 358 | 358 | |
@@ -369,12 +369,12 @@ discard block |
||
| 369 | 369 | where upper(object_name(fkeyid)) = $table |
| 370 | 370 | order by constraint_name, referenced_table_name, keyno"; |
| 371 | 371 | |
| 372 | - $constraints =& $this->GetArray($sql); |
|
| 372 | + $constraints = & $this->GetArray($sql); |
|
| 373 | 373 | |
| 374 | 374 | $ADODB_FETCH_MODE = $save; |
| 375 | 375 | |
| 376 | 376 | $arr = false; |
| 377 | - foreach($constraints as $constr) { |
|
| 377 | + foreach ($constraints as $constr) { |
|
| 378 | 378 | //print_r($constr); |
| 379 | 379 | $arr[$constr[0]][$constr[2]][] = $constr[1].'='.$constr[3]; |
| 380 | 380 | } |
@@ -382,8 +382,8 @@ discard block |
||
| 382 | 382 | |
| 383 | 383 | $arr2 = false; |
| 384 | 384 | |
| 385 | - foreach($arr as $k => $v) { |
|
| 386 | - foreach($v as $a => $b) { |
|
| 385 | + foreach ($arr as $k => $v) { |
|
| 386 | + foreach ($v as $a => $b) { |
|
| 387 | 387 | if ($upper) $a = strtoupper($a); |
| 388 | 388 | $arr2[$a] = $b; |
| 389 | 389 | } |
@@ -394,14 +394,14 @@ discard block |
||
| 394 | 394 | //From: Fernando Moreira <[email protected]> |
| 395 | 395 | function MetaDatabases() |
| 396 | 396 | { |
| 397 | - if(@mssql_select_db("master")) { |
|
| 398 | - $qry=$this->metaDatabasesSQL; |
|
| 399 | - if($rs=@mssql_query($qry)){ |
|
| 400 | - $tmpAr=$ar=array(); |
|
| 401 | - while($tmpAr=@mssql_fetch_row($rs)) |
|
| 402 | - $ar[]=$tmpAr[0]; |
|
| 397 | + if (@mssql_select_db("master")) { |
|
| 398 | + $qry = $this->metaDatabasesSQL; |
|
| 399 | + if ($rs = @mssql_query($qry)) { |
|
| 400 | + $tmpAr = $ar = array(); |
|
| 401 | + while ($tmpAr = @mssql_fetch_row($rs)) |
|
| 402 | + $ar[] = $tmpAr[0]; |
|
| 403 | 403 | @mssql_select_db($this->databaseName); |
| 404 | - if(sizeof($ar)) |
|
| 404 | + if (sizeof($ar)) |
|
| 405 | 405 | return($ar); |
| 406 | 406 | else |
| 407 | 407 | return(false); |
@@ -420,7 +420,7 @@ discard block |
||
| 420 | 420 | global $ADODB_FETCH_MODE; |
| 421 | 421 | |
| 422 | 422 | $schema = ''; |
| 423 | - $this->_findschema($table,$schema); |
|
| 423 | + $this->_findschema($table, $schema); |
|
| 424 | 424 | if (!$schema) $schema = $this->database; |
| 425 | 425 | if ($schema) $schema = "and k.table_catalog like '$schema%'"; |
| 426 | 426 | |
@@ -434,20 +434,20 @@ discard block |
||
| 434 | 434 | $a = $this->GetCol($sql); |
| 435 | 435 | $ADODB_FETCH_MODE = $savem; |
| 436 | 436 | |
| 437 | - if ($a && sizeof($a)>0) return $a; |
|
| 437 | + if ($a && sizeof($a) > 0) return $a; |
|
| 438 | 438 | $false = false; |
| 439 | 439 | return $false; |
| 440 | 440 | } |
| 441 | 441 | |
| 442 | 442 | |
| 443 | - function &MetaTables($ttype=false,$showSchema=false,$mask=false) |
|
| 443 | + function &MetaTables($ttype = false, $showSchema = false, $mask = false) |
|
| 444 | 444 | { |
| 445 | 445 | if ($mask) { |
| 446 | 446 | $save = $this->metaTablesSQL; |
| 447 | 447 | $mask = $this->qstr(($mask)); |
| 448 | 448 | $this->metaTablesSQL .= " AND name like $mask"; |
| 449 | 449 | } |
| 450 | - $ret =& ADOConnection::MetaTables($ttype,$showSchema); |
|
| 450 | + $ret = & ADOConnection::MetaTables($ttype, $showSchema); |
|
| 451 | 451 | |
| 452 | 452 | if ($mask) { |
| 453 | 453 | $this->metaTablesSQL = $save; |
@@ -466,7 +466,7 @@ discard block |
||
| 466 | 466 | |
| 467 | 467 | function ErrorMsg() |
| 468 | 468 | { |
| 469 | - if (empty($this->_errorMsg)){ |
|
| 469 | + if (empty($this->_errorMsg)) { |
|
| 470 | 470 | $this->_errorMsg = mssql_get_last_message(); |
| 471 | 471 | } |
| 472 | 472 | return $this->_errorMsg; |
@@ -478,7 +478,7 @@ discard block |
||
| 478 | 478 | if (empty($this->_errorMsg)) { |
| 479 | 479 | $this->_errorMsg = mssql_get_last_message(); |
| 480 | 480 | } |
| 481 | - $id = @mssql_query("select @@ERROR",$this->_connectionID); |
|
| 481 | + $id = @mssql_query("select @@ERROR", $this->_connectionID); |
|
| 482 | 482 | if (!$id) return false; |
| 483 | 483 | $arr = mssql_fetch_array($id); |
| 484 | 484 | @mssql_free_result($id); |
@@ -490,7 +490,7 @@ discard block |
||
| 490 | 490 | function _connect($argHostname, $argUsername, $argPassword, $argDatabasename) |
| 491 | 491 | { |
| 492 | 492 | if (!function_exists('mssql_pconnect')) return null; |
| 493 | - $this->_connectionID = mssql_connect($argHostname,$argUsername,$argPassword); |
|
| 493 | + $this->_connectionID = mssql_connect($argHostname, $argUsername, $argPassword); |
|
| 494 | 494 | if ($this->_connectionID === false) return false; |
| 495 | 495 | if ($argDatabasename) return $this->SelectDB($argDatabasename); |
| 496 | 496 | return true; |
@@ -501,7 +501,7 @@ discard block |
||
| 501 | 501 | function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename) |
| 502 | 502 | { |
| 503 | 503 | if (!function_exists('mssql_pconnect')) return null; |
| 504 | - $this->_connectionID = mssql_pconnect($argHostname,$argUsername,$argPassword); |
|
| 504 | + $this->_connectionID = mssql_pconnect($argHostname, $argUsername, $argPassword); |
|
| 505 | 505 | if ($this->_connectionID === false) return false; |
| 506 | 506 | |
| 507 | 507 | // persistent connections can forget to rollback on crash, so we do it here. |
@@ -515,24 +515,24 @@ discard block |
||
| 515 | 515 | |
| 516 | 516 | function Prepare($sql) |
| 517 | 517 | { |
| 518 | - $sqlarr = explode('?',$sql); |
|
| 518 | + $sqlarr = explode('?', $sql); |
|
| 519 | 519 | if (sizeof($sqlarr) <= 1) return $sql; |
| 520 | 520 | $sql2 = $sqlarr[0]; |
| 521 | 521 | for ($i = 1, $max = sizeof($sqlarr); $i < $max; $i++) { |
| 522 | - $sql2 .= '@P'.($i-1) . $sqlarr[$i]; |
|
| 522 | + $sql2 .= '@P'.($i - 1).$sqlarr[$i]; |
|
| 523 | 523 | } |
| 524 | - return array($sql,$this->qstr($sql2),$max); |
|
| 524 | + return array($sql, $this->qstr($sql2), $max); |
|
| 525 | 525 | } |
| 526 | 526 | |
| 527 | 527 | function PrepareSP($sql) |
| 528 | 528 | { |
| 529 | 529 | if (!$this->_has_mssql_init) { |
| 530 | - ADOConnection::outp( "PrepareSP: mssql_init only available since PHP 4.1.0"); |
|
| 530 | + ADOConnection::outp("PrepareSP: mssql_init only available since PHP 4.1.0"); |
|
| 531 | 531 | return $sql; |
| 532 | 532 | } |
| 533 | - $stmt = mssql_init($sql,$this->_connectionID); |
|
| 533 | + $stmt = mssql_init($sql, $this->_connectionID); |
|
| 534 | 534 | if (!$stmt) return $sql; |
| 535 | - return array($sql,$stmt); |
|
| 535 | + return array($sql, $stmt); |
|
| 536 | 536 | } |
| 537 | 537 | |
| 538 | 538 | // returns concatenated string |
@@ -553,7 +553,7 @@ discard block |
||
| 553 | 553 | } |
| 554 | 554 | |
| 555 | 555 | array_walk($arr, create_function('&$v', '$v = "CAST(" . $v . " AS VARCHAR(255))";')); |
| 556 | - $s = implode('+',$arr); |
|
| 556 | + $s = implode('+', $arr); |
|
| 557 | 557 | if (sizeof($arr) > 0) return "$s"; |
| 558 | 558 | |
| 559 | 559 | return ''; |
@@ -577,17 +577,17 @@ discard block |
||
| 577 | 577 | |
| 578 | 578 | See mssql_bind documentation at php.net. |
| 579 | 579 | */ |
| 580 | - function Parameter(&$stmt, &$var, $name, $isOutput=false, $maxLen=4000, $type=false) |
|
| 580 | + function Parameter(&$stmt, &$var, $name, $isOutput = false, $maxLen = 4000, $type = false) |
|
| 581 | 581 | { |
| 582 | 582 | if (!$this->_has_mssql_init) { |
| 583 | - ADOConnection::outp( "Parameter: mssql_bind only available since PHP 4.1.0"); |
|
| 583 | + ADOConnection::outp("Parameter: mssql_bind only available since PHP 4.1.0"); |
|
| 584 | 584 | return $sql; |
| 585 | 585 | } |
| 586 | 586 | |
| 587 | 587 | $isNull = is_null($var); // php 4.0.4 and above... |
| 588 | 588 | |
| 589 | 589 | if ($type === false) |
| 590 | - switch(gettype($var)) { |
|
| 590 | + switch (gettype($var)) { |
|
| 591 | 591 | default: |
| 592 | 592 | case 'string': $type = SQLCHAR; break; |
| 593 | 593 | case 'double': $type = SQLFLT8; break; |
@@ -595,10 +595,10 @@ discard block |
||
| 595 | 595 | case 'boolean': $type = SQLINT1; break; # SQLBIT not supported in 4.1.0 |
| 596 | 596 | } |
| 597 | 597 | |
| 598 | - if ($this->debug) { |
|
| 598 | + if ($this->debug) { |
|
| 599 | 599 | $prefix = ($isOutput) ? 'Out' : 'In'; |
| 600 | 600 | $ztype = (empty($type)) ? 'false' : $type; |
| 601 | - ADOConnection::outp( "{$prefix}Parameter(\$stmt, \$php_var='$var', \$name='$name', \$maxLen=$maxLen, \$type=$ztype);"); |
|
| 601 | + ADOConnection::outp("{$prefix}Parameter(\$stmt, \$php_var='$var', \$name='$name', \$maxLen=$maxLen, \$type=$ztype);"); |
|
| 602 | 602 | } |
| 603 | 603 | /* |
| 604 | 604 | See http://phplens.com/lens/lensforum/msgs.php?id=7231 |
@@ -625,11 +625,11 @@ discard block |
||
| 625 | 625 | ; Valid range 0 - 2147483647. Default = 4096. |
| 626 | 626 | mssql.textsize = 0 ; zero to pass through |
| 627 | 627 | */ |
| 628 | - function UpdateBlob($table,$column,$val,$where,$blobtype='BLOB') |
|
| 628 | + function UpdateBlob($table, $column, $val, $where, $blobtype = 'BLOB') |
|
| 629 | 629 | { |
| 630 | 630 | |
| 631 | 631 | if (strtoupper($blobtype) == 'CLOB') { |
| 632 | - $sql = "UPDATE $table SET $column='" . $val . "' WHERE $where"; |
|
| 632 | + $sql = "UPDATE $table SET $column='".$val."' WHERE $where"; |
|
| 633 | 633 | return $this->Execute($sql) != false; |
| 634 | 634 | } |
| 635 | 635 | $sql = "UPDATE $table SET $column=0x".bin2hex($val)." WHERE $where"; |
@@ -637,7 +637,7 @@ discard block |
||
| 637 | 637 | } |
| 638 | 638 | |
| 639 | 639 | // returns query ID if successful, otherwise false |
| 640 | - function _query($sql,$inputarr) |
|
| 640 | + function _query($sql, $inputarr) |
|
| 641 | 641 | { |
| 642 | 642 | $this->_errorMsg = false; |
| 643 | 643 | if (is_array($inputarr)) { |
@@ -649,7 +649,7 @@ discard block |
||
| 649 | 649 | $params = ''; |
| 650 | 650 | $decl = ''; |
| 651 | 651 | $i = 0; |
| 652 | - foreach($inputarr as $v) { |
|
| 652 | + foreach ($inputarr as $v) { |
|
| 653 | 653 | if ($decl) { |
| 654 | 654 | $decl .= ', '; |
| 655 | 655 | $params .= ', '; |
@@ -658,14 +658,14 @@ discard block |
||
| 658 | 658 | $len = strlen($v); |
| 659 | 659 | if ($len == 0) $len = 1; |
| 660 | 660 | |
| 661 | - if ($len > 4000 ) { |
|
| 661 | + if ($len > 4000) { |
|
| 662 | 662 | // NVARCHAR is max 4000 chars. Let's use NTEXT |
| 663 | 663 | $decl .= "@P$i NTEXT"; |
| 664 | 664 | } else { |
| 665 | 665 | $decl .= "@P$i NVARCHAR($len)"; |
| 666 | 666 | } |
| 667 | 667 | |
| 668 | - $params .= "@P$i=N". (strncmp($v,"'",1)==0? $v : $this->qstr($v)); |
|
| 668 | + $params .= "@P$i=N".(strncmp($v, "'", 1) == 0 ? $v : $this->qstr($v)); |
|
| 669 | 669 | } else if (is_integer($v)) { |
| 670 | 670 | $decl .= "@P$i INT"; |
| 671 | 671 | $params .= "@P$i=".$v; |
@@ -674,7 +674,7 @@ discard block |
||
| 674 | 674 | $params .= "@P$i=".$v; |
| 675 | 675 | } else if (is_bool($v)) { |
| 676 | 676 | $decl .= "@P$i INT"; # Used INT just in case BIT in not supported on the user's MSSQL version. It will cast appropriately. |
| 677 | - $params .= "@P$i=".(($v)?'1':'0'); # True == 1 in MSSQL BIT fields and acceptable for storing logical true in an int field |
|
| 677 | + $params .= "@P$i=".(($v) ? '1' : '0'); # True == 1 in MSSQL BIT fields and acceptable for storing logical true in an int field |
|
| 678 | 678 | } else { |
| 679 | 679 | $decl .= "@P$i CHAR"; # Used char because a type is required even when the value is to be NULL. |
| 680 | 680 | $params .= "@P$i=NULL"; |
@@ -690,7 +690,7 @@ discard block |
||
| 690 | 690 | $rez = mssql_execute($sql[1]); |
| 691 | 691 | |
| 692 | 692 | } else { |
| 693 | - $rez = mssql_query($sql,$this->_connectionID); |
|
| 693 | + $rez = mssql_query($sql, $this->_connectionID); |
|
| 694 | 694 | } |
| 695 | 695 | return $rez; |
| 696 | 696 | } |
@@ -727,7 +727,7 @@ discard block |
||
| 727 | 727 | var $hasFetchAssoc; // see http://phplens.com/lens/lensforum/msgs.php?id=6083 |
| 728 | 728 | // _mths works only in non-localised system |
| 729 | 729 | |
| 730 | - function ADORecordset_mssql($id,$mode=false) |
|
| 730 | + function ADORecordset_mssql($id, $mode = false) |
|
| 731 | 731 | { |
| 732 | 732 | // freedts check... |
| 733 | 733 | $this->hasFetchAssoc = function_exists('mssql_fetch_assoc'); |
@@ -737,14 +737,14 @@ discard block |
||
| 737 | 737 | $mode = $ADODB_FETCH_MODE; |
| 738 | 738 | } |
| 739 | 739 | $this->fetchMode = $mode; |
| 740 | - return $this->ADORecordSet($id,$mode); |
|
| 740 | + return $this->ADORecordSet($id, $mode); |
|
| 741 | 741 | } |
| 742 | 742 | |
| 743 | 743 | |
| 744 | 744 | function _initrs() |
| 745 | 745 | { |
| 746 | 746 | GLOBAL $ADODB_COUNTRECS; |
| 747 | - $this->_numOfRows = ($ADODB_COUNTRECS)? @mssql_num_rows($this->_queryID):-1; |
|
| 747 | + $this->_numOfRows = ($ADODB_COUNTRECS) ? @mssql_num_rows($this->_queryID) : -1; |
|
| 748 | 748 | $this->_numOfFields = @mssql_num_fields($this->_queryID); |
| 749 | 749 | } |
| 750 | 750 | |
@@ -767,7 +767,7 @@ discard block |
||
| 767 | 767 | if ($this->fetchMode != ADODB_FETCH_NUM) return $this->fields[$colname]; |
| 768 | 768 | if (!$this->bind) { |
| 769 | 769 | $this->bind = array(); |
| 770 | - for ($i=0; $i < $this->_numOfFields; $i++) { |
|
| 770 | + for ($i = 0; $i < $this->_numOfFields; $i++) { |
|
| 771 | 771 | $o = $this->FetchField($i); |
| 772 | 772 | $this->bind[strtoupper($o->name)] = $i; |
| 773 | 773 | } |
@@ -806,8 +806,8 @@ discard block |
||
| 806 | 806 | |
| 807 | 807 | $this->_currentRow++; |
| 808 | 808 | |
| 809 | - if ($this->fetchMode & ADODB_FETCH_ASSOC) { |
|
| 810 | - if ($this->fetchMode & ADODB_FETCH_NUM) { |
|
| 809 | + if ($this->fetchMode&ADODB_FETCH_ASSOC) { |
|
| 810 | + if ($this->fetchMode&ADODB_FETCH_NUM) { |
|
| 811 | 811 | //ADODB_FETCH_BOTH mode |
| 812 | 812 | $this->fields = @mssql_fetch_array($this->_queryID); |
| 813 | 813 | } |
@@ -818,7 +818,7 @@ discard block |
||
| 818 | 818 | $flds = @mssql_fetch_array($this->_queryID); |
| 819 | 819 | if (is_array($flds)) { |
| 820 | 820 | $fassoc = array(); |
| 821 | - foreach($flds as $k => $v) { |
|
| 821 | + foreach ($flds as $k => $v) { |
|
| 822 | 822 | if (is_numeric($k)) continue; |
| 823 | 823 | $fassoc[$k] = $v; |
| 824 | 824 | } |
@@ -830,11 +830,11 @@ discard block |
||
| 830 | 830 | |
| 831 | 831 | if (is_array($this->fields)) { |
| 832 | 832 | if (ADODB_ASSOC_CASE == 0) { |
| 833 | - foreach($this->fields as $k=>$v) { |
|
| 833 | + foreach ($this->fields as $k=>$v) { |
|
| 834 | 834 | $this->fields[strtolower($k)] = $v; |
| 835 | 835 | } |
| 836 | 836 | } else if (ADODB_ASSOC_CASE == 1) { |
| 837 | - foreach($this->fields as $k=>$v) { |
|
| 837 | + foreach ($this->fields as $k=>$v) { |
|
| 838 | 838 | $this->fields[strtoupper($k)] = $v; |
| 839 | 839 | } |
| 840 | 840 | } |
@@ -851,10 +851,10 @@ discard block |
||
| 851 | 851 | |
| 852 | 852 | // INSERT UPDATE DELETE returns false even if no error occurs in 4.0.4 |
| 853 | 853 | // also the date format has been changed from YYYY-mm-dd to dd MMM YYYY in 4.0.4. Idiot! |
| 854 | - function _fetch($ignore_fields=false) |
|
| 854 | + function _fetch($ignore_fields = false) |
|
| 855 | 855 | { |
| 856 | - if ($this->fetchMode & ADODB_FETCH_ASSOC) { |
|
| 857 | - if ($this->fetchMode & ADODB_FETCH_NUM) { |
|
| 856 | + if ($this->fetchMode&ADODB_FETCH_ASSOC) { |
|
| 857 | + if ($this->fetchMode&ADODB_FETCH_NUM) { |
|
| 858 | 858 | //ADODB_FETCH_BOTH mode |
| 859 | 859 | $this->fields = @mssql_fetch_array($this->_queryID); |
| 860 | 860 | } else { |
@@ -864,7 +864,7 @@ discard block |
||
| 864 | 864 | $this->fields = @mssql_fetch_array($this->_queryID); |
| 865 | 865 | if (@is_array($$this->fields)) { |
| 866 | 866 | $fassoc = array(); |
| 867 | - foreach($$this->fields as $k => $v) { |
|
| 867 | + foreach ($$this->fields as $k => $v) { |
|
| 868 | 868 | if (is_integer($k)) continue; |
| 869 | 869 | $fassoc[$k] = $v; |
| 870 | 870 | } |
@@ -875,11 +875,11 @@ discard block |
||
| 875 | 875 | |
| 876 | 876 | if (!$this->fields) { |
| 877 | 877 | } else if (ADODB_ASSOC_CASE == 0) { |
| 878 | - foreach($this->fields as $k=>$v) { |
|
| 878 | + foreach ($this->fields as $k=>$v) { |
|
| 879 | 879 | $this->fields[strtolower($k)] = $v; |
| 880 | 880 | } |
| 881 | 881 | } else if (ADODB_ASSOC_CASE == 1) { |
| 882 | - foreach($this->fields as $k=>$v) { |
|
| 882 | + foreach ($this->fields as $k=>$v) { |
|
| 883 | 883 | $this->fields[strtoupper($k)] = $v; |
| 884 | 884 | } |
| 885 | 885 | } |
@@ -913,65 +913,65 @@ discard block |
||
| 913 | 913 | |
| 914 | 914 | |
| 915 | 915 | class ADORecordSet_array_mssql extends ADORecordSet_array { |
| 916 | - function ADORecordSet_array_mssql($id=-1,$mode=false) |
|
| 916 | + function ADORecordSet_array_mssql($id = -1, $mode = false) |
|
| 917 | 917 | { |
| 918 | - $this->ADORecordSet_array($id,$mode); |
|
| 918 | + $this->ADORecordSet_array($id, $mode); |
|
| 919 | 919 | } |
| 920 | 920 | |
| 921 | 921 | // mssql uses a default date like Dec 30 2000 12:00AM |
| 922 | 922 | function UnixDate($v) |
| 923 | 923 | { |
| 924 | 924 | |
| 925 | - if (is_numeric(substr($v,0,1)) && ADODB_PHPVER >= 0x4200) return parent::UnixDate($v); |
|
| 925 | + if (is_numeric(substr($v, 0, 1)) && ADODB_PHPVER >= 0x4200) return parent::UnixDate($v); |
|
| 926 | 926 | |
| 927 | - global $ADODB_mssql_mths,$ADODB_mssql_date_order; |
|
| 927 | + global $ADODB_mssql_mths, $ADODB_mssql_date_order; |
|
| 928 | 928 | |
| 929 | 929 | //Dec 30 2000 12:00AM |
| 930 | 930 | if ($ADODB_mssql_date_order == 'dmy') { |
| 931 | - if (!preg_match( "|^([0-9]{1,2})[-/\. ]+([A-Za-z]{3})[-/\. ]+([0-9]{4})|" ,$v, $rr)) { |
|
| 931 | + if (!preg_match("|^([0-9]{1,2})[-/\. ]+([A-Za-z]{3})[-/\. ]+([0-9]{4})|", $v, $rr)) { |
|
| 932 | 932 | return parent::UnixDate($v); |
| 933 | 933 | } |
| 934 | 934 | if ($rr[3] <= TIMESTAMP_FIRST_YEAR) return 0; |
| 935 | 935 | |
| 936 | 936 | $theday = $rr[1]; |
| 937 | - $themth = substr(strtoupper($rr[2]),0,3); |
|
| 937 | + $themth = substr(strtoupper($rr[2]), 0, 3); |
|
| 938 | 938 | } else { |
| 939 | - if (!preg_match( "|^([A-Za-z]{3})[-/\. ]+([0-9]{1,2})[-/\. ]+([0-9]{4})|" ,$v, $rr)) { |
|
| 939 | + if (!preg_match("|^([A-Za-z]{3})[-/\. ]+([0-9]{1,2})[-/\. ]+([0-9]{4})|", $v, $rr)) { |
|
| 940 | 940 | return parent::UnixDate($v); |
| 941 | 941 | } |
| 942 | 942 | if ($rr[3] <= TIMESTAMP_FIRST_YEAR) return 0; |
| 943 | 943 | |
| 944 | 944 | $theday = $rr[2]; |
| 945 | - $themth = substr(strtoupper($rr[1]),0,3); |
|
| 945 | + $themth = substr(strtoupper($rr[1]), 0, 3); |
|
| 946 | 946 | } |
| 947 | 947 | $themth = $ADODB_mssql_mths[$themth]; |
| 948 | 948 | if ($themth <= 0) return false; |
| 949 | 949 | // h-m-s-MM-DD-YY |
| 950 | - return mktime(0,0,0,$themth,$theday,$rr[3]); |
|
| 950 | + return mktime(0, 0, 0, $themth, $theday, $rr[3]); |
|
| 951 | 951 | } |
| 952 | 952 | |
| 953 | 953 | function UnixTimeStamp($v) |
| 954 | 954 | { |
| 955 | 955 | |
| 956 | - if (is_numeric(substr($v,0,1)) && ADODB_PHPVER >= 0x4200) return parent::UnixTimeStamp($v); |
|
| 956 | + if (is_numeric(substr($v, 0, 1)) && ADODB_PHPVER >= 0x4200) return parent::UnixTimeStamp($v); |
|
| 957 | 957 | |
| 958 | - global $ADODB_mssql_mths,$ADODB_mssql_date_order; |
|
| 958 | + global $ADODB_mssql_mths, $ADODB_mssql_date_order; |
|
| 959 | 959 | |
| 960 | 960 | //Dec 30 2000 12:00AM |
| 961 | 961 | if ($ADODB_mssql_date_order == 'dmy') { |
| 962 | - if (!preg_match( "|^([0-9]{1,2})[-/\. ]+([A-Za-z]{3})[-/\. ]+([0-9]{4}) +([0-9]{1,2}):([0-9]{1,2}) *([apAP]{0,1})|" |
|
| 962 | + if (!preg_match("|^([0-9]{1,2})[-/\. ]+([A-Za-z]{3})[-/\. ]+([0-9]{4}) +([0-9]{1,2}):([0-9]{1,2}) *([apAP]{0,1})|" |
|
| 963 | 963 | ,$v, $rr)) return parent::UnixTimeStamp($v); |
| 964 | 964 | if ($rr[3] <= TIMESTAMP_FIRST_YEAR) return 0; |
| 965 | 965 | |
| 966 | 966 | $theday = $rr[1]; |
| 967 | - $themth = substr(strtoupper($rr[2]),0,3); |
|
| 967 | + $themth = substr(strtoupper($rr[2]), 0, 3); |
|
| 968 | 968 | } else { |
| 969 | - if (!preg_match( "|^([A-Za-z]{3})[-/\. ]+([0-9]{1,2})[-/\. ]+([0-9]{4}) +([0-9]{1,2}):([0-9]{1,2}) *([apAP]{0,1})|" |
|
| 969 | + if (!preg_match("|^([A-Za-z]{3})[-/\. ]+([0-9]{1,2})[-/\. ]+([0-9]{4}) +([0-9]{1,2}):([0-9]{1,2}) *([apAP]{0,1})|" |
|
| 970 | 970 | ,$v, $rr)) return parent::UnixTimeStamp($v); |
| 971 | 971 | if ($rr[3] <= TIMESTAMP_FIRST_YEAR) return 0; |
| 972 | 972 | |
| 973 | 973 | $theday = $rr[2]; |
| 974 | - $themth = substr(strtoupper($rr[1]),0,3); |
|
| 974 | + $themth = substr(strtoupper($rr[1]), 0, 3); |
|
| 975 | 975 | } |
| 976 | 976 | |
| 977 | 977 | $themth = $ADODB_mssql_mths[$themth]; |
@@ -979,16 +979,16 @@ discard block |
||
| 979 | 979 | |
| 980 | 980 | switch (strtoupper($rr[6])) { |
| 981 | 981 | case 'P': |
| 982 | - if ($rr[4]<12) $rr[4] += 12; |
|
| 982 | + if ($rr[4] < 12) $rr[4] += 12; |
|
| 983 | 983 | break; |
| 984 | 984 | case 'A': |
| 985 | - if ($rr[4]==12) $rr[4] = 0; |
|
| 985 | + if ($rr[4] == 12) $rr[4] = 0; |
|
| 986 | 986 | break; |
| 987 | 987 | default: |
| 988 | 988 | break; |
| 989 | 989 | } |
| 990 | 990 | // h-m-s-MM-DD-YY |
| 991 | - return mktime($rr[4],$rr[5],0,$themth,$theday,$rr[3]); |
|
| 991 | + return mktime($rr[4], $rr[5], 0, $themth, $theday, $rr[3]); |
|
| 992 | 992 | } |
| 993 | 993 | } |
| 994 | 994 | |
@@ -15,7 +15,10 @@ discard block |
||
| 15 | 15 | */ |
| 16 | 16 | |
| 17 | 17 | // security - hide paths |
| 18 | -if (!defined('ADODB_DIR')) die(); |
|
| 18 | +if (!defined('ADODB_DIR')) |
|
| 19 | +{ |
|
| 20 | + die(); |
|
| 21 | +} |
|
| 19 | 22 | |
| 20 | 23 | //---------------------------------------------------------------- |
| 21 | 24 | // MSSQL returns dates with the format Oct 13 2002 or 13 Oct 2002 |
@@ -37,10 +40,13 @@ discard block |
||
| 37 | 40 | |
| 38 | 41 | |
| 39 | 42 | // has datetime converstion to YYYY-MM-DD format, and also mssql_fetch_assoc |
| 40 | -if (ADODB_PHPVER >= 0x4300) { |
|
| 43 | +if (ADODB_PHPVER >= 0x4300) |
|
| 44 | +{ |
|
| 41 | 45 | // docs say 4.2.0, but testing shows only since 4.3.0 does it work! |
| 42 | 46 | ini_set('mssql.datetimeconvert',0); |
| 43 | -} else { |
|
| 47 | +} |
|
| 48 | +else |
|
| 49 | +{ |
|
| 44 | 50 | global $ADODB_mssql_mths; // array, months must be upper-case |
| 45 | 51 | |
| 46 | 52 | |
@@ -58,19 +64,27 @@ discard block |
||
| 58 | 64 | { |
| 59 | 65 | global $ADODB_mssql_date_order; |
| 60 | 66 | $adate = $conn->GetOne('select getdate()'); |
| 61 | - if ($adate) { |
|
| 67 | + if ($adate) |
|
| 68 | + { |
|
| 62 | 69 | $anum = (int) $adate; |
| 63 | - if ($anum > 0) { |
|
| 64 | - if ($anum > 31) { |
|
| 70 | + if ($anum > 0) |
|
| 71 | + { |
|
| 72 | + if ($anum > 31) |
|
| 73 | + { |
|
| 65 | 74 | //ADOConnection::outp( "MSSQL: YYYY-MM-DD date format not supported currently"); |
| 66 | - } else |
|
| 67 | - $ADODB_mssql_date_order = 'dmy'; |
|
| 68 | - } else |
|
| 69 | - $ADODB_mssql_date_order = 'mdy'; |
|
| 75 | + } |
|
| 76 | + else { |
|
| 77 | + $ADODB_mssql_date_order = 'dmy'; |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | + else { |
|
| 81 | + $ADODB_mssql_date_order = 'mdy'; |
|
| 82 | + } |
|
| 70 | 83 | } |
| 71 | 84 | } |
| 72 | 85 | |
| 73 | -class ADODB_mssql extends ADOConnection { |
|
| 86 | +class ADODB_mssql extends ADOConnection |
|
| 87 | +{ |
|
| 74 | 88 | var $databaseType = "mssql"; |
| 75 | 89 | var $dataProvider = "mssql"; |
| 76 | 90 | var $replaceQuote = "''"; // string to use to replace quotes |
@@ -103,8 +117,8 @@ discard block |
||
| 103 | 117 | var $uniqueOrderBy = true; |
| 104 | 118 | var $_bindInputArray = true; |
| 105 | 119 | |
| 106 | - function ADODB_mssql() |
|
| 107 | - { |
|
| 120 | + function ADODB_mssql() |
|
| 121 | + { |
|
| 108 | 122 | $this->_has_mssql_init = (strnatcmp(PHP_VERSION,'4.1.0')>=0); |
| 109 | 123 | } |
| 110 | 124 | |
@@ -114,11 +128,14 @@ discard block |
||
| 114 | 128 | |
| 115 | 129 | $stmt = $this->PrepareSP('sp_server_info'); |
| 116 | 130 | $val = 2; |
| 117 | - if ($this->fetchMode === false) { |
|
| 131 | + if ($this->fetchMode === false) |
|
| 132 | + { |
|
| 118 | 133 | $savem = $ADODB_FETCH_MODE; |
| 119 | 134 | $ADODB_FETCH_MODE = ADODB_FETCH_NUM; |
| 120 | - } else |
|
| 121 | - $savem = $this->SetFetchMode(ADODB_FETCH_NUM); |
|
| 135 | + } |
|
| 136 | + else { |
|
| 137 | + $savem = $this->SetFetchMode(ADODB_FETCH_NUM); |
|
| 138 | + } |
|
| 122 | 139 | |
| 123 | 140 | |
| 124 | 141 | $this->Parameter($stmt,$val,'attribute_id'); |
@@ -126,17 +143,20 @@ discard block |
||
| 126 | 143 | |
| 127 | 144 | //$row = $this->GetRow("execute sp_server_info 2"); |
| 128 | 145 | |
| 129 | - if ($this->fetchMode === false) { |
|
| 146 | + if ($this->fetchMode === false) |
|
| 147 | + { |
|
| 130 | 148 | $ADODB_FETCH_MODE = $savem; |
| 131 | - } else |
|
| 132 | - $this->SetFetchMode($savem); |
|
| 149 | + } |
|
| 150 | + else { |
|
| 151 | + $this->SetFetchMode($savem); |
|
| 152 | + } |
|
| 133 | 153 | |
| 134 | 154 | $arr['description'] = $row[2]; |
| 135 | 155 | $arr['version'] = ADOConnection::_findvers($arr['description']); |
| 136 | 156 | return $arr; |
| 137 | 157 | } |
| 138 | 158 | |
| 139 | - function IfNull( $field, $ifNull ) |
|
| 159 | + function IfNull( $field, $ifNull ) |
|
| 140 | 160 | { |
| 141 | 161 | return " ISNULL($field, $ifNull) "; // if MS SQL Server |
| 142 | 162 | } |
@@ -163,7 +183,8 @@ discard block |
||
| 163 | 183 | $start -= 1; |
| 164 | 184 | $this->Execute("create table $seq (id float(53))"); |
| 165 | 185 | $ok = $this->Execute("insert into $seq with (tablock,holdlock) values($start)"); |
| 166 | - if (!$ok) { |
|
| 186 | + if (!$ok) |
|
| 187 | + { |
|
| 167 | 188 | $this->Execute('ROLLBACK TRANSACTION adodbseq'); |
| 168 | 189 | return false; |
| 169 | 190 | } |
@@ -176,10 +197,12 @@ discard block |
||
| 176 | 197 | //$this->debug=1; |
| 177 | 198 | $this->Execute('BEGIN TRANSACTION adodbseq'); |
| 178 | 199 | $ok = $this->Execute("update $seq with (tablock,holdlock) set id = id + 1"); |
| 179 | - if (!$ok) { |
|
| 200 | + if (!$ok) |
|
| 201 | + { |
|
| 180 | 202 | $this->Execute("create table $seq (id float(53))"); |
| 181 | 203 | $ok = $this->Execute("insert into $seq with (tablock,holdlock) values($start)"); |
| 182 | - if (!$ok) { |
|
| 204 | + if (!$ok) |
|
| 205 | + { |
|
| 183 | 206 | $this->Execute('ROLLBACK TRANSACTION adodbseq'); |
| 184 | 207 | return false; |
| 185 | 208 | } |
@@ -197,12 +220,15 @@ discard block |
||
| 197 | 220 | |
| 198 | 221 | function &SelectLimit($sql,$nrows=-1,$offset=-1, $inputarr=false,$secs2cache=0) |
| 199 | 222 | { |
| 200 | - if ($nrows > 0 && $offset <= 0) { |
|
| 223 | + if ($nrows > 0 && $offset <= 0) |
|
| 224 | + { |
|
| 201 | 225 | $sql = preg_replace( |
| 202 | 226 | '/(^\s*select\s+(distinctrow|distinct)?)/i','\\1 '.$this->hasTop." $nrows ",$sql); |
| 203 | 227 | $rs =& $this->Execute($sql,$inputarr); |
| 204 | - } else |
|
| 205 | - $rs =& ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache); |
|
| 228 | + } |
|
| 229 | + else { |
|
| 230 | + $rs =& ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache); |
|
| 231 | + } |
|
| 206 | 232 | |
| 207 | 233 | return $rs; |
| 208 | 234 | } |
@@ -210,15 +236,23 @@ discard block |
||
| 210 | 236 | |
| 211 | 237 | // Format date column in sql string given an input format that understands Y M D |
| 212 | 238 | function SQLDate($fmt, $col=false) |
| 213 | - { |
|
| 214 | - if (!$col) $col = $this->sysTimeStamp; |
|
| 239 | + { |
|
| 240 | + if (!$col) |
|
| 241 | + { |
|
| 242 | + $col = $this->sysTimeStamp; |
|
| 243 | + } |
|
| 215 | 244 | $s = ''; |
| 216 | 245 | |
| 217 | 246 | $len = strlen($fmt); |
| 218 | - for ($i=0; $i < $len; $i++) { |
|
| 219 | - if ($s) $s .= '+'; |
|
| 247 | + for ($i=0; $i < $len; $i++) |
|
| 248 | + { |
|
| 249 | + if ($s) |
|
| 250 | + { |
|
| 251 | + $s .= '+'; |
|
| 252 | + } |
|
| 220 | 253 | $ch = $fmt[$i]; |
| 221 | - switch($ch) { |
|
| 254 | + switch($ch) |
|
| 255 | + { |
|
| 222 | 256 | case 'Y': |
| 223 | 257 | case 'y': |
| 224 | 258 | $s .= "datename(yyyy,$col)"; |
@@ -257,7 +291,8 @@ discard block |
||
| 257 | 291 | break; |
| 258 | 292 | |
| 259 | 293 | default: |
| 260 | - if ($ch == '\\') { |
|
| 294 | + if ($ch == '\\') |
|
| 295 | + { |
|
| 261 | 296 | $i++; |
| 262 | 297 | $ch = substr($fmt,$i,1); |
| 263 | 298 | } |
@@ -271,24 +306,42 @@ discard block |
||
| 271 | 306 | |
| 272 | 307 | function BeginTrans() |
| 273 | 308 | { |
| 274 | - if ($this->transOff) return true; |
|
| 309 | + if ($this->transOff) |
|
| 310 | + { |
|
| 311 | + return true; |
|
| 312 | + } |
|
| 275 | 313 | $this->transCnt += 1; |
| 276 | 314 | $this->Execute('BEGIN TRAN'); |
| 277 | 315 | return true; |
| 278 | 316 | } |
| 279 | 317 | |
| 280 | - function CommitTrans($ok=true) |
|
| 281 | - { |
|
| 282 | - if ($this->transOff) return true; |
|
| 283 | - if (!$ok) return $this->RollbackTrans(); |
|
| 284 | - if ($this->transCnt) $this->transCnt -= 1; |
|
| 318 | + function CommitTrans($ok=true) |
|
| 319 | + { |
|
| 320 | + if ($this->transOff) |
|
| 321 | + { |
|
| 322 | + return true; |
|
| 323 | + } |
|
| 324 | + if (!$ok) |
|
| 325 | + { |
|
| 326 | + return $this->RollbackTrans(); |
|
| 327 | + } |
|
| 328 | + if ($this->transCnt) |
|
| 329 | + { |
|
| 330 | + $this->transCnt -= 1; |
|
| 331 | + } |
|
| 285 | 332 | $this->Execute('COMMIT TRAN'); |
| 286 | 333 | return true; |
| 287 | 334 | } |
| 288 | 335 | function RollbackTrans() |
| 289 | 336 | { |
| 290 | - if ($this->transOff) return true; |
|
| 291 | - if ($this->transCnt) $this->transCnt -= 1; |
|
| 337 | + if ($this->transOff) |
|
| 338 | + { |
|
| 339 | + return true; |
|
| 340 | + } |
|
| 341 | + if ($this->transCnt) |
|
| 342 | + { |
|
| 343 | + $this->transCnt -= 1; |
|
| 344 | + } |
|
| 292 | 345 | $this->Execute('ROLLBACK TRAN'); |
| 293 | 346 | return true; |
| 294 | 347 | } |
@@ -305,9 +358,12 @@ discard block |
||
| 305 | 358 | |
| 306 | 359 | See http://www.swynk.com/friends/achigrik/SQL70Locks.asp |
| 307 | 360 | */ |
| 308 | - function RowLock($tables,$where,$flds='top 1 null as ignore') |
|
| 361 | + function RowLock($tables,$where,$flds='top 1 null as ignore') |
|
| 309 | 362 | { |
| 310 | - if (!$this->transCnt) $this->BeginTrans(); |
|
| 363 | + if (!$this->transCnt) |
|
| 364 | + { |
|
| 365 | + $this->BeginTrans(); |
|
| 366 | + } |
|
| 311 | 367 | return $this->GetOne("select $flds from $tables with (ROWLOCK,HOLDLOCK) where $where"); |
| 312 | 368 | } |
| 313 | 369 | |
@@ -328,23 +384,30 @@ discard block |
||
| 328 | 384 | global $ADODB_FETCH_MODE; |
| 329 | 385 | $save = $ADODB_FETCH_MODE; |
| 330 | 386 | $ADODB_FETCH_MODE = ADODB_FETCH_NUM; |
| 331 | - if ($this->fetchMode !== FALSE) { |
|
| 387 | + if ($this->fetchMode !== FALSE) |
|
| 388 | + { |
|
| 332 | 389 | $savem = $this->SetFetchMode(FALSE); |
| 333 | 390 | } |
| 334 | 391 | |
| 335 | 392 | $rs = $this->Execute($sql); |
| 336 | - if (isset($savem)) { |
|
| 393 | + if (isset($savem)) |
|
| 394 | + { |
|
| 337 | 395 | $this->SetFetchMode($savem); |
| 338 | 396 | } |
| 339 | 397 | $ADODB_FETCH_MODE = $save; |
| 340 | 398 | |
| 341 | - if (!is_object($rs)) { |
|
| 399 | + if (!is_object($rs)) |
|
| 400 | + { |
|
| 342 | 401 | return FALSE; |
| 343 | 402 | } |
| 344 | 403 | |
| 345 | 404 | $indexes = array(); |
| 346 | - while ($row = $rs->FetchRow()) { |
|
| 347 | - if (!$primary && $row[5]) continue; |
|
| 405 | + while ($row = $rs->FetchRow()) |
|
| 406 | + { |
|
| 407 | + if (!$primary && $row[5]) |
|
| 408 | + { |
|
| 409 | + continue; |
|
| 410 | + } |
|
| 348 | 411 | |
| 349 | 412 | $indexes[$row[0]]['unique'] = $row[6]; |
| 350 | 413 | $indexes[$row[0]]['columns'][] = $row[1]; |
@@ -374,17 +437,26 @@ discard block |
||
| 374 | 437 | $ADODB_FETCH_MODE = $save; |
| 375 | 438 | |
| 376 | 439 | $arr = false; |
| 377 | - foreach($constraints as $constr) { |
|
| 440 | + foreach($constraints as $constr) |
|
| 441 | + { |
|
| 378 | 442 | //print_r($constr); |
| 379 | 443 | $arr[$constr[0]][$constr[2]][] = $constr[1].'='.$constr[3]; |
| 380 | 444 | } |
| 381 | - if (!$arr) return false; |
|
| 445 | + if (!$arr) |
|
| 446 | + { |
|
| 447 | + return false; |
|
| 448 | + } |
|
| 382 | 449 | |
| 383 | 450 | $arr2 = false; |
| 384 | 451 | |
| 385 | - foreach($arr as $k => $v) { |
|
| 386 | - foreach($v as $a => $b) { |
|
| 387 | - if ($upper) $a = strtoupper($a); |
|
| 452 | + foreach($arr as $k => $v) |
|
| 453 | + { |
|
| 454 | + foreach($v as $a => $b) |
|
| 455 | + { |
|
| 456 | + if ($upper) |
|
| 457 | + { |
|
| 458 | + $a = strtoupper($a); |
|
| 459 | + } |
|
| 388 | 460 | $arr2[$a] = $b; |
| 389 | 461 | } |
| 390 | 462 | } |
@@ -392,20 +464,29 @@ discard block |
||
| 392 | 464 | } |
| 393 | 465 | |
| 394 | 466 | //From: Fernando Moreira <[email protected]> |
| 395 | - function MetaDatabases() |
|
| 396 | - { |
|
| 397 | - if(@mssql_select_db("master")) { |
|
| 467 | + function MetaDatabases() |
|
| 468 | + { |
|
| 469 | + if(@mssql_select_db("master")) |
|
| 470 | + { |
|
| 398 | 471 | $qry=$this->metaDatabasesSQL; |
| 399 | - if($rs=@mssql_query($qry)){ |
|
| 472 | + if($rs=@mssql_query($qry)) |
|
| 473 | + { |
|
| 400 | 474 | $tmpAr=$ar=array(); |
| 401 | - while($tmpAr=@mssql_fetch_row($rs)) |
|
| 402 | - $ar[]=$tmpAr[0]; |
|
| 475 | + while($tmpAr=@mssql_fetch_row($rs)) |
|
| 476 | + { |
|
| 477 | + $ar[]=$tmpAr[0]; |
|
| 478 | + } |
|
| 403 | 479 | @mssql_select_db($this->databaseName); |
| 404 | - if(sizeof($ar)) |
|
| 405 | - return($ar); |
|
| 406 | - else |
|
| 407 | - return(false); |
|
| 408 | - } else { |
|
| 480 | + if(sizeof($ar)) |
|
| 481 | + { |
|
| 482 | + return($ar); |
|
| 483 | + } |
|
| 484 | + else { |
|
| 485 | + return(false); |
|
| 486 | + } |
|
| 487 | + } |
|
| 488 | + else |
|
| 489 | + { |
|
| 409 | 490 | @mssql_select_db($this->databaseName); |
| 410 | 491 | return(false); |
| 411 | 492 | } |
@@ -421,8 +502,14 @@ discard block |
||
| 421 | 502 | |
| 422 | 503 | $schema = ''; |
| 423 | 504 | $this->_findschema($table,$schema); |
| 424 | - if (!$schema) $schema = $this->database; |
|
| 425 | - if ($schema) $schema = "and k.table_catalog like '$schema%'"; |
|
| 505 | + if (!$schema) |
|
| 506 | + { |
|
| 507 | + $schema = $this->database; |
|
| 508 | + } |
|
| 509 | + if ($schema) |
|
| 510 | + { |
|
| 511 | + $schema = "and k.table_catalog like '$schema%'"; |
|
| 512 | + } |
|
| 426 | 513 | |
| 427 | 514 | $sql = "select distinct k.column_name,ordinal_position from information_schema.key_column_usage k, |
| 428 | 515 | information_schema.table_constraints tc |
@@ -434,7 +521,10 @@ discard block |
||
| 434 | 521 | $a = $this->GetCol($sql); |
| 435 | 522 | $ADODB_FETCH_MODE = $savem; |
| 436 | 523 | |
| 437 | - if ($a && sizeof($a)>0) return $a; |
|
| 524 | + if ($a && sizeof($a)>0) |
|
| 525 | + { |
|
| 526 | + return $a; |
|
| 527 | + } |
|
| 438 | 528 | $false = false; |
| 439 | 529 | return $false; |
| 440 | 530 | } |
@@ -442,57 +532,84 @@ discard block |
||
| 442 | 532 | |
| 443 | 533 | function &MetaTables($ttype=false,$showSchema=false,$mask=false) |
| 444 | 534 | { |
| 445 | - if ($mask) { |
|
| 535 | + if ($mask) |
|
| 536 | + { |
|
| 446 | 537 | $save = $this->metaTablesSQL; |
| 447 | 538 | $mask = $this->qstr(($mask)); |
| 448 | 539 | $this->metaTablesSQL .= " AND name like $mask"; |
| 449 | 540 | } |
| 450 | 541 | $ret =& ADOConnection::MetaTables($ttype,$showSchema); |
| 451 | 542 | |
| 452 | - if ($mask) { |
|
| 543 | + if ($mask) |
|
| 544 | + { |
|
| 453 | 545 | $this->metaTablesSQL = $save; |
| 454 | 546 | } |
| 455 | 547 | return $ret; |
| 456 | 548 | } |
| 457 | 549 | |
| 458 | - function SelectDB($dbName) |
|
| 550 | + function SelectDB($dbName) |
|
| 459 | 551 | { |
| 460 | 552 | $this->databaseName = $dbName; |
| 461 | - if ($this->_connectionID) { |
|
| 553 | + if ($this->_connectionID) |
|
| 554 | + { |
|
| 462 | 555 | return @mssql_select_db($dbName); |
| 463 | 556 | } |
| 464 | - else return false; |
|
| 557 | + else { |
|
| 558 | + return false; |
|
| 559 | + } |
|
| 465 | 560 | } |
| 466 | 561 | |
| 467 | - function ErrorMsg() |
|
| 562 | + function ErrorMsg() |
|
| 468 | 563 | { |
| 469 | - if (empty($this->_errorMsg)){ |
|
| 564 | + if (empty($this->_errorMsg)) |
|
| 565 | + { |
|
| 470 | 566 | $this->_errorMsg = mssql_get_last_message(); |
| 471 | 567 | } |
| 472 | 568 | return $this->_errorMsg; |
| 473 | 569 | } |
| 474 | 570 | |
| 475 | - function ErrorNo() |
|
| 571 | + function ErrorNo() |
|
| 476 | 572 | { |
| 477 | - if ($this->_logsql && $this->_errorCode !== false) return $this->_errorCode; |
|
| 478 | - if (empty($this->_errorMsg)) { |
|
| 573 | + if ($this->_logsql && $this->_errorCode !== false) |
|
| 574 | + { |
|
| 575 | + return $this->_errorCode; |
|
| 576 | + } |
|
| 577 | + if (empty($this->_errorMsg)) |
|
| 578 | + { |
|
| 479 | 579 | $this->_errorMsg = mssql_get_last_message(); |
| 480 | 580 | } |
| 481 | 581 | $id = @mssql_query("select @@ERROR",$this->_connectionID); |
| 482 | - if (!$id) return false; |
|
| 582 | + if (!$id) |
|
| 583 | + { |
|
| 584 | + return false; |
|
| 585 | + } |
|
| 483 | 586 | $arr = mssql_fetch_array($id); |
| 484 | 587 | @mssql_free_result($id); |
| 485 | - if (is_array($arr)) return $arr[0]; |
|
| 486 | - else return -1; |
|
| 588 | + if (is_array($arr)) |
|
| 589 | + { |
|
| 590 | + return $arr[0]; |
|
| 591 | + } |
|
| 592 | + else { |
|
| 593 | + return -1; |
|
| 594 | + } |
|
| 487 | 595 | } |
| 488 | 596 | |
| 489 | 597 | // returns true or false |
| 490 | 598 | function _connect($argHostname, $argUsername, $argPassword, $argDatabasename) |
| 491 | 599 | { |
| 492 | - if (!function_exists('mssql_pconnect')) return null; |
|
| 600 | + if (!function_exists('mssql_pconnect')) |
|
| 601 | + { |
|
| 602 | + return null; |
|
| 603 | + } |
|
| 493 | 604 | $this->_connectionID = mssql_connect($argHostname,$argUsername,$argPassword); |
| 494 | - if ($this->_connectionID === false) return false; |
|
| 495 | - if ($argDatabasename) return $this->SelectDB($argDatabasename); |
|
| 605 | + if ($this->_connectionID === false) |
|
| 606 | + { |
|
| 607 | + return false; |
|
| 608 | + } |
|
| 609 | + if ($argDatabasename) |
|
| 610 | + { |
|
| 611 | + return $this->SelectDB($argDatabasename); |
|
| 612 | + } |
|
| 496 | 613 | return true; |
| 497 | 614 | } |
| 498 | 615 | |
@@ -500,25 +617,42 @@ discard block |
||
| 500 | 617 | // returns true or false |
| 501 | 618 | function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename) |
| 502 | 619 | { |
| 503 | - if (!function_exists('mssql_pconnect')) return null; |
|
| 620 | + if (!function_exists('mssql_pconnect')) |
|
| 621 | + { |
|
| 622 | + return null; |
|
| 623 | + } |
|
| 504 | 624 | $this->_connectionID = mssql_pconnect($argHostname,$argUsername,$argPassword); |
| 505 | - if ($this->_connectionID === false) return false; |
|
| 625 | + if ($this->_connectionID === false) |
|
| 626 | + { |
|
| 627 | + return false; |
|
| 628 | + } |
|
| 506 | 629 | |
| 507 | 630 | // persistent connections can forget to rollback on crash, so we do it here. |
| 508 | - if ($this->autoRollback) { |
|
| 631 | + if ($this->autoRollback) |
|
| 632 | + { |
|
| 509 | 633 | $cnt = $this->GetOne('select @@TRANCOUNT'); |
| 510 | - while (--$cnt >= 0) $this->Execute('ROLLBACK TRAN'); |
|
| 634 | + while (--$cnt >= 0) |
|
| 635 | + { |
|
| 636 | + $this->Execute('ROLLBACK TRAN'); |
|
| 637 | + } |
|
| 638 | + } |
|
| 639 | + if ($argDatabasename) |
|
| 640 | + { |
|
| 641 | + return $this->SelectDB($argDatabasename); |
|
| 511 | 642 | } |
| 512 | - if ($argDatabasename) return $this->SelectDB($argDatabasename); |
|
| 513 | 643 | return true; |
| 514 | 644 | } |
| 515 | 645 | |
| 516 | 646 | function Prepare($sql) |
| 517 | 647 | { |
| 518 | 648 | $sqlarr = explode('?',$sql); |
| 519 | - if (sizeof($sqlarr) <= 1) return $sql; |
|
| 649 | + if (sizeof($sqlarr) <= 1) |
|
| 650 | + { |
|
| 651 | + return $sql; |
|
| 652 | + } |
|
| 520 | 653 | $sql2 = $sqlarr[0]; |
| 521 | - for ($i = 1, $max = sizeof($sqlarr); $i < $max; $i++) { |
|
| 654 | + for ($i = 1, $max = sizeof($sqlarr); $i < $max; $i++) |
|
| 655 | + { |
|
| 522 | 656 | $sql2 .= '@P'.($i-1) . $sqlarr[$i]; |
| 523 | 657 | } |
| 524 | 658 | return array($sql,$this->qstr($sql2),$max); |
@@ -526,12 +660,16 @@ discard block |
||
| 526 | 660 | |
| 527 | 661 | function PrepareSP($sql) |
| 528 | 662 | { |
| 529 | - if (!$this->_has_mssql_init) { |
|
| 663 | + if (!$this->_has_mssql_init) |
|
| 664 | + { |
|
| 530 | 665 | ADOConnection::outp( "PrepareSP: mssql_init only available since PHP 4.1.0"); |
| 531 | 666 | return $sql; |
| 532 | 667 | } |
| 533 | 668 | $stmt = mssql_init($sql,$this->_connectionID); |
| 534 | - if (!$stmt) return $sql; |
|
| 669 | + if (!$stmt) |
|
| 670 | + { |
|
| 671 | + return $sql; |
|
| 672 | + } |
|
| 535 | 673 | return array($sql,$stmt); |
| 536 | 674 | } |
| 537 | 675 | |
@@ -545,8 +683,10 @@ discard block |
||
| 545 | 683 | $arr = func_get_args(); |
| 546 | 684 | |
| 547 | 685 | // Split single record on commas, if possible |
| 548 | - if (sizeof($arr) == 1) { |
|
| 549 | - foreach ($arr as $arg) { |
|
| 686 | + if (sizeof($arr) == 1) |
|
| 687 | + { |
|
| 688 | + foreach ($arr as $arg) |
|
| 689 | + { |
|
| 550 | 690 | $args = explode(',', $arg); |
| 551 | 691 | } |
| 552 | 692 | $arr = $args; |
@@ -554,7 +694,10 @@ discard block |
||
| 554 | 694 | |
| 555 | 695 | array_walk($arr, create_function('&$v', '$v = "CAST(" . $v . " AS VARCHAR(255))";')); |
| 556 | 696 | $s = implode('+',$arr); |
| 557 | - if (sizeof($arr) > 0) return "$s"; |
|
| 697 | + if (sizeof($arr) > 0) |
|
| 698 | + { |
|
| 699 | + return "$s"; |
|
| 700 | + } |
|
| 558 | 701 | |
| 559 | 702 | return ''; |
| 560 | 703 | } |
@@ -579,23 +722,28 @@ discard block |
||
| 579 | 722 | */ |
| 580 | 723 | function Parameter(&$stmt, &$var, $name, $isOutput=false, $maxLen=4000, $type=false) |
| 581 | 724 | { |
| 582 | - if (!$this->_has_mssql_init) { |
|
| 725 | + if (!$this->_has_mssql_init) |
|
| 726 | + { |
|
| 583 | 727 | ADOConnection::outp( "Parameter: mssql_bind only available since PHP 4.1.0"); |
| 584 | 728 | return $sql; |
| 585 | 729 | } |
| 586 | 730 | |
| 587 | 731 | $isNull = is_null($var); // php 4.0.4 and above... |
| 588 | 732 | |
| 589 | - if ($type === false) |
|
| 590 | - switch(gettype($var)) { |
|
| 733 | + if ($type === false) |
|
| 734 | + { |
|
| 735 | + switch(gettype($var)) { |
|
| 591 | 736 | default: |
| 592 | - case 'string': $type = SQLCHAR; break; |
|
| 737 | + case 'string': $type = SQLCHAR; |
|
| 738 | + } |
|
| 739 | + break; |
|
| 593 | 740 | case 'double': $type = SQLFLT8; break; |
| 594 | 741 | case 'integer': $type = SQLINT4; break; |
| 595 | 742 | case 'boolean': $type = SQLINT1; break; # SQLBIT not supported in 4.1.0 |
| 596 | 743 | } |
| 597 | 744 | |
| 598 | - if ($this->debug) { |
|
| 745 | + if ($this->debug) |
|
| 746 | + { |
|
| 599 | 747 | $prefix = ($isOutput) ? 'Out' : 'In'; |
| 600 | 748 | $ztype = (empty($type)) ? 'false' : $type; |
| 601 | 749 | ADOConnection::outp( "{$prefix}Parameter(\$stmt, \$php_var='$var', \$name='$name', \$maxLen=$maxLen, \$type=$ztype);"); |
@@ -609,7 +757,10 @@ discard block |
||
| 609 | 757 | see how it works. - type: one of this new supported PHP constants. |
| 610 | 758 | SQLTEXT, SQLVARCHAR,SQLCHAR, SQLINT1,SQLINT2, SQLINT4, SQLBIT,SQLFLT8 |
| 611 | 759 | */ |
| 612 | - if ($name !== 'RETVAL') $name = '@'.$name; |
|
| 760 | + if ($name !== 'RETVAL') |
|
| 761 | + { |
|
| 762 | + $name = '@'.$name; |
|
| 763 | + } |
|
| 613 | 764 | return mssql_bind($stmt[1], $name, $var, $type, $isOutput, $isNull, $maxLen); |
| 614 | 765 | } |
| 615 | 766 | |
@@ -628,7 +779,8 @@ discard block |
||
| 628 | 779 | function UpdateBlob($table,$column,$val,$where,$blobtype='BLOB') |
| 629 | 780 | { |
| 630 | 781 | |
| 631 | - if (strtoupper($blobtype) == 'CLOB') { |
|
| 782 | + if (strtoupper($blobtype) == 'CLOB') |
|
| 783 | + { |
|
| 632 | 784 | $sql = "UPDATE $table SET $column='" . $val . "' WHERE $where"; |
| 633 | 785 | return $this->Execute($sql) != false; |
| 634 | 786 | } |
@@ -640,56 +792,84 @@ discard block |
||
| 640 | 792 | function _query($sql,$inputarr) |
| 641 | 793 | { |
| 642 | 794 | $this->_errorMsg = false; |
| 643 | - if (is_array($inputarr)) { |
|
| 795 | + if (is_array($inputarr)) |
|
| 796 | + { |
|
| 644 | 797 | |
| 645 | 798 | # bind input params with sp_executesql: |
| 646 | 799 | # see http://www.quest-pipelines.com/newsletter-v3/0402_F.htm |
| 647 | 800 | # works only with sql server 7 and newer |
| 648 | - if (!is_array($sql)) $sql = $this->Prepare($sql); |
|
| 801 | + if (!is_array($sql)) |
|
| 802 | + { |
|
| 803 | + $sql = $this->Prepare($sql); |
|
| 804 | + } |
|
| 649 | 805 | $params = ''; |
| 650 | 806 | $decl = ''; |
| 651 | 807 | $i = 0; |
| 652 | - foreach($inputarr as $v) { |
|
| 653 | - if ($decl) { |
|
| 808 | + foreach($inputarr as $v) |
|
| 809 | + { |
|
| 810 | + if ($decl) |
|
| 811 | + { |
|
| 654 | 812 | $decl .= ', '; |
| 655 | 813 | $params .= ', '; |
| 656 | 814 | } |
| 657 | - if (is_string($v)) { |
|
| 815 | + if (is_string($v)) |
|
| 816 | + { |
|
| 658 | 817 | $len = strlen($v); |
| 659 | - if ($len == 0) $len = 1; |
|
| 818 | + if ($len == 0) |
|
| 819 | + { |
|
| 820 | + $len = 1; |
|
| 821 | + } |
|
| 660 | 822 | |
| 661 | - if ($len > 4000 ) { |
|
| 823 | + if ($len > 4000 ) |
|
| 824 | + { |
|
| 662 | 825 | // NVARCHAR is max 4000 chars. Let's use NTEXT |
| 663 | 826 | $decl .= "@P$i NTEXT"; |
| 664 | - } else { |
|
| 827 | + } |
|
| 828 | + else |
|
| 829 | + { |
|
| 665 | 830 | $decl .= "@P$i NVARCHAR($len)"; |
| 666 | 831 | } |
| 667 | 832 | |
| 668 | 833 | $params .= "@P$i=N". (strncmp($v,"'",1)==0? $v : $this->qstr($v)); |
| 669 | - } else if (is_integer($v)) { |
|
| 834 | + } |
|
| 835 | + else if (is_integer($v)) |
|
| 836 | + { |
|
| 670 | 837 | $decl .= "@P$i INT"; |
| 671 | 838 | $params .= "@P$i=".$v; |
| 672 | - } else if (is_float($v)) { |
|
| 839 | + } |
|
| 840 | + else if (is_float($v)) |
|
| 841 | + { |
|
| 673 | 842 | $decl .= "@P$i FLOAT"; |
| 674 | 843 | $params .= "@P$i=".$v; |
| 675 | - } else if (is_bool($v)) { |
|
| 844 | + } |
|
| 845 | + else if (is_bool($v)) |
|
| 846 | + { |
|
| 676 | 847 | $decl .= "@P$i INT"; # Used INT just in case BIT in not supported on the user's MSSQL version. It will cast appropriately. |
| 677 | 848 | $params .= "@P$i=".(($v)?'1':'0'); # True == 1 in MSSQL BIT fields and acceptable for storing logical true in an int field |
| 678 | - } else { |
|
| 849 | + } |
|
| 850 | + else |
|
| 851 | + { |
|
| 679 | 852 | $decl .= "@P$i CHAR"; # Used char because a type is required even when the value is to be NULL. |
| 680 | 853 | $params .= "@P$i=NULL"; |
| 681 | 854 | } |
| 682 | 855 | $i += 1; |
| 683 | 856 | } |
| 684 | 857 | $decl = $this->qstr($decl); |
| 685 | - if ($this->debug) ADOConnection::outp("<font size=-1>sp_executesql N{$sql[1]},N$decl,$params</font>"); |
|
| 858 | + if ($this->debug) |
|
| 859 | + { |
|
| 860 | + ADOConnection::outp("<font size=-1>sp_executesql N{$sql[1]},N$decl,$params</font>"); |
|
| 861 | + } |
|
| 686 | 862 | $rez = mssql_query("sp_executesql N{$sql[1]},N$decl,$params"); |
| 687 | 863 | |
| 688 | - } else if (is_array($sql)) { |
|
| 864 | + } |
|
| 865 | + else if (is_array($sql)) |
|
| 866 | + { |
|
| 689 | 867 | # PrepareSP() |
| 690 | 868 | $rez = mssql_execute($sql[1]); |
| 691 | 869 | |
| 692 | - } else { |
|
| 870 | + } |
|
| 871 | + else |
|
| 872 | + { |
|
| 693 | 873 | $rez = mssql_query($sql,$this->_connectionID); |
| 694 | 874 | } |
| 695 | 875 | return $rez; |
@@ -697,8 +877,11 @@ discard block |
||
| 697 | 877 | |
| 698 | 878 | // returns true or false |
| 699 | 879 | function _close() |
| 700 | - { |
|
| 701 | - if ($this->transCnt) $this->RollbackTrans(); |
|
| 880 | + { |
|
| 881 | + if ($this->transCnt) |
|
| 882 | + { |
|
| 883 | + $this->RollbackTrans(); |
|
| 884 | + } |
|
| 702 | 885 | $rez = @mssql_close($this->_connectionID); |
| 703 | 886 | $this->_connectionID = false; |
| 704 | 887 | return $rez; |
@@ -720,7 +903,8 @@ discard block |
||
| 720 | 903 | Class Name: Recordset |
| 721 | 904 | --------------------------------------------------------------------------------------*/ |
| 722 | 905 | |
| 723 | -class ADORecordset_mssql extends ADORecordSet { |
|
| 906 | +class ADORecordset_mssql extends ADORecordSet |
|
| 907 | +{ |
|
| 724 | 908 | |
| 725 | 909 | var $databaseType = "mssql"; |
| 726 | 910 | var $canSeek = true; |
@@ -732,7 +916,8 @@ discard block |
||
| 732 | 916 | // freedts check... |
| 733 | 917 | $this->hasFetchAssoc = function_exists('mssql_fetch_assoc'); |
| 734 | 918 | |
| 735 | - if ($mode === false) { |
|
| 919 | + if ($mode === false) |
|
| 920 | + { |
|
| 736 | 921 | global $ADODB_FETCH_MODE; |
| 737 | 922 | $mode = $ADODB_FETCH_MODE; |
| 738 | 923 | } |
@@ -753,7 +938,10 @@ discard block |
||
| 753 | 938 | // get next resultset - requires PHP 4.0.5 or later |
| 754 | 939 | function NextRecordSet() |
| 755 | 940 | { |
| 756 | - if (!mssql_next_result($this->_queryID)) return false; |
|
| 941 | + if (!mssql_next_result($this->_queryID)) |
|
| 942 | + { |
|
| 943 | + return false; |
|
| 944 | + } |
|
| 757 | 945 | $this->_inited = false; |
| 758 | 946 | $this->bind = false; |
| 759 | 947 | $this->_currentRow = -1; |
@@ -764,10 +952,15 @@ discard block |
||
| 764 | 952 | /* Use associative array to get fields array */ |
| 765 | 953 | function Fields($colname) |
| 766 | 954 | { |
| 767 | - if ($this->fetchMode != ADODB_FETCH_NUM) return $this->fields[$colname]; |
|
| 768 | - if (!$this->bind) { |
|
| 955 | + if ($this->fetchMode != ADODB_FETCH_NUM) |
|
| 956 | + { |
|
| 957 | + return $this->fields[$colname]; |
|
| 958 | + } |
|
| 959 | + if (!$this->bind) |
|
| 960 | + { |
|
| 769 | 961 | $this->bind = array(); |
| 770 | - for ($i=0; $i < $this->_numOfFields; $i++) { |
|
| 962 | + for ($i=0; $i < $this->_numOfFields; $i++) |
|
| 963 | + { |
|
| 771 | 964 | $o = $this->FetchField($i); |
| 772 | 965 | $this->bind[strtoupper($o->name)] = $i; |
| 773 | 966 | } |
@@ -783,66 +976,100 @@ discard block |
||
| 783 | 976 | |
| 784 | 977 | function &FetchField($fieldOffset = -1) |
| 785 | 978 | { |
| 786 | - if ($fieldOffset != -1) { |
|
| 979 | + if ($fieldOffset != -1) |
|
| 980 | + { |
|
| 787 | 981 | $f = @mssql_fetch_field($this->_queryID, $fieldOffset); |
| 788 | 982 | } |
| 789 | - else if ($fieldOffset == -1) { /* The $fieldOffset argument is not provided thus its -1 */ |
|
| 983 | + else if ($fieldOffset == -1) |
|
| 984 | + { |
|
| 985 | +/* The $fieldOffset argument is not provided thus its -1 */ |
|
| 790 | 986 | $f = @mssql_fetch_field($this->_queryID); |
| 791 | 987 | } |
| 792 | 988 | $false = false; |
| 793 | - if (empty($f)) return $false; |
|
| 989 | + if (empty($f)) |
|
| 990 | + { |
|
| 991 | + return $false; |
|
| 992 | + } |
|
| 794 | 993 | return $f; |
| 795 | 994 | } |
| 796 | 995 | |
| 797 | - function _seek($row) |
|
| 996 | + function _seek($row) |
|
| 798 | 997 | { |
| 799 | 998 | return @mssql_data_seek($this->_queryID, $row); |
| 800 | 999 | } |
| 801 | 1000 | |
| 802 | 1001 | // speedup |
| 803 | - function MoveNext() |
|
| 1002 | + function MoveNext() |
|
| 804 | 1003 | { |
| 805 | - if ($this->EOF) return false; |
|
| 1004 | + if ($this->EOF) |
|
| 1005 | + { |
|
| 1006 | + return false; |
|
| 1007 | + } |
|
| 806 | 1008 | |
| 807 | 1009 | $this->_currentRow++; |
| 808 | 1010 | |
| 809 | - if ($this->fetchMode & ADODB_FETCH_ASSOC) { |
|
| 810 | - if ($this->fetchMode & ADODB_FETCH_NUM) { |
|
| 1011 | + if ($this->fetchMode & ADODB_FETCH_ASSOC) |
|
| 1012 | + { |
|
| 1013 | + if ($this->fetchMode & ADODB_FETCH_NUM) |
|
| 1014 | + { |
|
| 811 | 1015 | //ADODB_FETCH_BOTH mode |
| 812 | 1016 | $this->fields = @mssql_fetch_array($this->_queryID); |
| 813 | 1017 | } |
| 814 | - else { |
|
| 815 | - if ($this->hasFetchAssoc) {// only for PHP 4.2.0 or later |
|
| 1018 | + else |
|
| 1019 | + { |
|
| 1020 | + if ($this->hasFetchAssoc) |
|
| 1021 | + { |
|
| 1022 | +// only for PHP 4.2.0 or later |
|
| 816 | 1023 | $this->fields = @mssql_fetch_assoc($this->_queryID); |
| 817 | - } else { |
|
| 1024 | + } |
|
| 1025 | + else |
|
| 1026 | + { |
|
| 818 | 1027 | $flds = @mssql_fetch_array($this->_queryID); |
| 819 | - if (is_array($flds)) { |
|
| 1028 | + if (is_array($flds)) |
|
| 1029 | + { |
|
| 820 | 1030 | $fassoc = array(); |
| 821 | - foreach($flds as $k => $v) { |
|
| 822 | - if (is_numeric($k)) continue; |
|
| 1031 | + foreach($flds as $k => $v) |
|
| 1032 | + { |
|
| 1033 | + if (is_numeric($k)) |
|
| 1034 | + { |
|
| 1035 | + continue; |
|
| 1036 | + } |
|
| 823 | 1037 | $fassoc[$k] = $v; |
| 824 | 1038 | } |
| 825 | 1039 | $this->fields = $fassoc; |
| 826 | - } else |
|
| 827 | - $this->fields = false; |
|
| 1040 | + } |
|
| 1041 | + else { |
|
| 1042 | + $this->fields = false; |
|
| 1043 | + } |
|
| 828 | 1044 | } |
| 829 | 1045 | } |
| 830 | 1046 | |
| 831 | - if (is_array($this->fields)) { |
|
| 832 | - if (ADODB_ASSOC_CASE == 0) { |
|
| 833 | - foreach($this->fields as $k=>$v) { |
|
| 1047 | + if (is_array($this->fields)) |
|
| 1048 | + { |
|
| 1049 | + if (ADODB_ASSOC_CASE == 0) |
|
| 1050 | + { |
|
| 1051 | + foreach($this->fields as $k=>$v) |
|
| 1052 | + { |
|
| 834 | 1053 | $this->fields[strtolower($k)] = $v; |
| 835 | 1054 | } |
| 836 | - } else if (ADODB_ASSOC_CASE == 1) { |
|
| 837 | - foreach($this->fields as $k=>$v) { |
|
| 1055 | + } |
|
| 1056 | + else if (ADODB_ASSOC_CASE == 1) |
|
| 1057 | + { |
|
| 1058 | + foreach($this->fields as $k=>$v) |
|
| 1059 | + { |
|
| 838 | 1060 | $this->fields[strtoupper($k)] = $v; |
| 839 | 1061 | } |
| 840 | 1062 | } |
| 841 | 1063 | } |
| 842 | - } else { |
|
| 1064 | + } |
|
| 1065 | + else |
|
| 1066 | + { |
|
| 843 | 1067 | $this->fields = @mssql_fetch_row($this->_queryID); |
| 844 | 1068 | } |
| 845 | - if ($this->fields) return true; |
|
| 1069 | + if ($this->fields) |
|
| 1070 | + { |
|
| 1071 | + return true; |
|
| 1072 | + } |
|
| 846 | 1073 | $this->EOF = true; |
| 847 | 1074 | |
| 848 | 1075 | return false; |
@@ -851,21 +1078,34 @@ discard block |
||
| 851 | 1078 | |
| 852 | 1079 | // INSERT UPDATE DELETE returns false even if no error occurs in 4.0.4 |
| 853 | 1080 | // also the date format has been changed from YYYY-mm-dd to dd MMM YYYY in 4.0.4. Idiot! |
| 854 | - function _fetch($ignore_fields=false) |
|
| 1081 | + function _fetch($ignore_fields=false) |
|
| 855 | 1082 | { |
| 856 | - if ($this->fetchMode & ADODB_FETCH_ASSOC) { |
|
| 857 | - if ($this->fetchMode & ADODB_FETCH_NUM) { |
|
| 1083 | + if ($this->fetchMode & ADODB_FETCH_ASSOC) |
|
| 1084 | + { |
|
| 1085 | + if ($this->fetchMode & ADODB_FETCH_NUM) |
|
| 1086 | + { |
|
| 858 | 1087 | //ADODB_FETCH_BOTH mode |
| 859 | 1088 | $this->fields = @mssql_fetch_array($this->_queryID); |
| 860 | - } else { |
|
| 861 | - if ($this->hasFetchAssoc) // only for PHP 4.2.0 or later |
|
| 1089 | + } |
|
| 1090 | + else |
|
| 1091 | + { |
|
| 1092 | + if ($this->hasFetchAssoc) |
|
| 1093 | + { |
|
| 1094 | + // only for PHP 4.2.0 or later |
|
| 862 | 1095 | $this->fields = @mssql_fetch_assoc($this->_queryID); |
| 863 | - else { |
|
| 1096 | + } |
|
| 1097 | + else |
|
| 1098 | + { |
|
| 864 | 1099 | $this->fields = @mssql_fetch_array($this->_queryID); |
| 865 | - if (@is_array($$this->fields)) { |
|
| 1100 | + if (@is_array($$this->fields)) |
|
| 1101 | + { |
|
| 866 | 1102 | $fassoc = array(); |
| 867 | - foreach($$this->fields as $k => $v) { |
|
| 868 | - if (is_integer($k)) continue; |
|
| 1103 | + foreach($$this->fields as $k => $v) |
|
| 1104 | + { |
|
| 1105 | + if (is_integer($k)) |
|
| 1106 | + { |
|
| 1107 | + continue; |
|
| 1108 | + } |
|
| 869 | 1109 | $fassoc[$k] = $v; |
| 870 | 1110 | } |
| 871 | 1111 | $this->fields = $fassoc; |
@@ -873,17 +1113,26 @@ discard block |
||
| 873 | 1113 | } |
| 874 | 1114 | } |
| 875 | 1115 | |
| 876 | - if (!$this->fields) { |
|
| 877 | - } else if (ADODB_ASSOC_CASE == 0) { |
|
| 878 | - foreach($this->fields as $k=>$v) { |
|
| 1116 | + if (!$this->fields) |
|
| 1117 | + { |
|
| 1118 | + } |
|
| 1119 | + else if (ADODB_ASSOC_CASE == 0) |
|
| 1120 | + { |
|
| 1121 | + foreach($this->fields as $k=>$v) |
|
| 1122 | + { |
|
| 879 | 1123 | $this->fields[strtolower($k)] = $v; |
| 880 | 1124 | } |
| 881 | - } else if (ADODB_ASSOC_CASE == 1) { |
|
| 882 | - foreach($this->fields as $k=>$v) { |
|
| 1125 | + } |
|
| 1126 | + else if (ADODB_ASSOC_CASE == 1) |
|
| 1127 | + { |
|
| 1128 | + foreach($this->fields as $k=>$v) |
|
| 1129 | + { |
|
| 883 | 1130 | $this->fields[strtoupper($k)] = $v; |
| 884 | 1131 | } |
| 885 | 1132 | } |
| 886 | - } else { |
|
| 1133 | + } |
|
| 1134 | + else |
|
| 1135 | + { |
|
| 887 | 1136 | $this->fields = @mssql_fetch_row($this->_queryID); |
| 888 | 1137 | } |
| 889 | 1138 | return $this->fields; |
@@ -892,7 +1141,7 @@ discard block |
||
| 892 | 1141 | /* close() only needs to be called if you are worried about using too much memory while your script |
| 893 | 1142 | is running. All associated result memory for the specified result identifier will automatically be freed. */ |
| 894 | 1143 | |
| 895 | - function _close() |
|
| 1144 | + function _close() |
|
| 896 | 1145 | { |
| 897 | 1146 | $rez = mssql_free_result($this->_queryID); |
| 898 | 1147 | $this->_queryID = false; |
@@ -912,8 +1161,9 @@ discard block |
||
| 912 | 1161 | } |
| 913 | 1162 | |
| 914 | 1163 | |
| 915 | -class ADORecordSet_array_mssql extends ADORecordSet_array { |
|
| 916 | - function ADORecordSet_array_mssql($id=-1,$mode=false) |
|
| 1164 | +class ADORecordSet_array_mssql extends ADORecordSet_array |
|
| 1165 | +{ |
|
| 1166 | + function ADORecordSet_array_mssql($id=-1,$mode=false) |
|
| 917 | 1167 | { |
| 918 | 1168 | $this->ADORecordSet_array($id,$mode); |
| 919 | 1169 | } |
@@ -922,30 +1172,47 @@ discard block |
||
| 922 | 1172 | function UnixDate($v) |
| 923 | 1173 | { |
| 924 | 1174 | |
| 925 | - if (is_numeric(substr($v,0,1)) && ADODB_PHPVER >= 0x4200) return parent::UnixDate($v); |
|
| 1175 | + if (is_numeric(substr($v,0,1)) && ADODB_PHPVER >= 0x4200) |
|
| 1176 | + { |
|
| 1177 | + return parent::UnixDate($v); |
|
| 1178 | + } |
|
| 926 | 1179 | |
| 927 | 1180 | global $ADODB_mssql_mths,$ADODB_mssql_date_order; |
| 928 | 1181 | |
| 929 | 1182 | //Dec 30 2000 12:00AM |
| 930 | - if ($ADODB_mssql_date_order == 'dmy') { |
|
| 931 | - if (!preg_match( "|^([0-9]{1,2})[-/\. ]+([A-Za-z]{3})[-/\. ]+([0-9]{4})|" ,$v, $rr)) { |
|
| 1183 | + if ($ADODB_mssql_date_order == 'dmy') |
|
| 1184 | + { |
|
| 1185 | + if (!preg_match( "|^([0-9]{1,2})[-/\. ]+([A-Za-z]{3})[-/\. ]+([0-9]{4})|" ,$v, $rr)) |
|
| 1186 | + { |
|
| 932 | 1187 | return parent::UnixDate($v); |
| 933 | 1188 | } |
| 934 | - if ($rr[3] <= TIMESTAMP_FIRST_YEAR) return 0; |
|
| 1189 | + if ($rr[3] <= TIMESTAMP_FIRST_YEAR) |
|
| 1190 | + { |
|
| 1191 | + return 0; |
|
| 1192 | + } |
|
| 935 | 1193 | |
| 936 | 1194 | $theday = $rr[1]; |
| 937 | 1195 | $themth = substr(strtoupper($rr[2]),0,3); |
| 938 | - } else { |
|
| 939 | - if (!preg_match( "|^([A-Za-z]{3})[-/\. ]+([0-9]{1,2})[-/\. ]+([0-9]{4})|" ,$v, $rr)) { |
|
| 1196 | + } |
|
| 1197 | + else |
|
| 1198 | + { |
|
| 1199 | + if (!preg_match( "|^([A-Za-z]{3})[-/\. ]+([0-9]{1,2})[-/\. ]+([0-9]{4})|" ,$v, $rr)) |
|
| 1200 | + { |
|
| 940 | 1201 | return parent::UnixDate($v); |
| 941 | 1202 | } |
| 942 | - if ($rr[3] <= TIMESTAMP_FIRST_YEAR) return 0; |
|
| 1203 | + if ($rr[3] <= TIMESTAMP_FIRST_YEAR) |
|
| 1204 | + { |
|
| 1205 | + return 0; |
|
| 1206 | + } |
|
| 943 | 1207 | |
| 944 | 1208 | $theday = $rr[2]; |
| 945 | 1209 | $themth = substr(strtoupper($rr[1]),0,3); |
| 946 | 1210 | } |
| 947 | 1211 | $themth = $ADODB_mssql_mths[$themth]; |
| 948 | - if ($themth <= 0) return false; |
|
| 1212 | + if ($themth <= 0) |
|
| 1213 | + { |
|
| 1214 | + return false; |
|
| 1215 | + } |
|
| 949 | 1216 | // h-m-s-MM-DD-YY |
| 950 | 1217 | return mktime(0,0,0,$themth,$theday,$rr[3]); |
| 951 | 1218 | } |
@@ -953,36 +1220,64 @@ discard block |
||
| 953 | 1220 | function UnixTimeStamp($v) |
| 954 | 1221 | { |
| 955 | 1222 | |
| 956 | - if (is_numeric(substr($v,0,1)) && ADODB_PHPVER >= 0x4200) return parent::UnixTimeStamp($v); |
|
| 1223 | + if (is_numeric(substr($v,0,1)) && ADODB_PHPVER >= 0x4200) |
|
| 1224 | + { |
|
| 1225 | + return parent::UnixTimeStamp($v); |
|
| 1226 | + } |
|
| 957 | 1227 | |
| 958 | 1228 | global $ADODB_mssql_mths,$ADODB_mssql_date_order; |
| 959 | 1229 | |
| 960 | 1230 | //Dec 30 2000 12:00AM |
| 961 | - if ($ADODB_mssql_date_order == 'dmy') { |
|
| 1231 | + if ($ADODB_mssql_date_order == 'dmy') |
|
| 1232 | + { |
|
| 962 | 1233 | if (!preg_match( "|^([0-9]{1,2})[-/\. ]+([A-Za-z]{3})[-/\. ]+([0-9]{4}) +([0-9]{1,2}):([0-9]{1,2}) *([apAP]{0,1})|" |
| 963 | - ,$v, $rr)) return parent::UnixTimeStamp($v); |
|
| 964 | - if ($rr[3] <= TIMESTAMP_FIRST_YEAR) return 0; |
|
| 1234 | + ,$v, $rr)) |
|
| 1235 | + { |
|
| 1236 | + return parent::UnixTimeStamp($v); |
|
| 1237 | + } |
|
| 1238 | + if ($rr[3] <= TIMESTAMP_FIRST_YEAR) |
|
| 1239 | + { |
|
| 1240 | + return 0; |
|
| 1241 | + } |
|
| 965 | 1242 | |
| 966 | 1243 | $theday = $rr[1]; |
| 967 | 1244 | $themth = substr(strtoupper($rr[2]),0,3); |
| 968 | - } else { |
|
| 1245 | + } |
|
| 1246 | + else |
|
| 1247 | + { |
|
| 969 | 1248 | if (!preg_match( "|^([A-Za-z]{3})[-/\. ]+([0-9]{1,2})[-/\. ]+([0-9]{4}) +([0-9]{1,2}):([0-9]{1,2}) *([apAP]{0,1})|" |
| 970 | - ,$v, $rr)) return parent::UnixTimeStamp($v); |
|
| 971 | - if ($rr[3] <= TIMESTAMP_FIRST_YEAR) return 0; |
|
| 1249 | + ,$v, $rr)) |
|
| 1250 | + { |
|
| 1251 | + return parent::UnixTimeStamp($v); |
|
| 1252 | + } |
|
| 1253 | + if ($rr[3] <= TIMESTAMP_FIRST_YEAR) |
|
| 1254 | + { |
|
| 1255 | + return 0; |
|
| 1256 | + } |
|
| 972 | 1257 | |
| 973 | 1258 | $theday = $rr[2]; |
| 974 | 1259 | $themth = substr(strtoupper($rr[1]),0,3); |
| 975 | 1260 | } |
| 976 | 1261 | |
| 977 | 1262 | $themth = $ADODB_mssql_mths[$themth]; |
| 978 | - if ($themth <= 0) return false; |
|
| 1263 | + if ($themth <= 0) |
|
| 1264 | + { |
|
| 1265 | + return false; |
|
| 1266 | + } |
|
| 979 | 1267 | |
| 980 | - switch (strtoupper($rr[6])) { |
|
| 1268 | + switch (strtoupper($rr[6])) |
|
| 1269 | + { |
|
| 981 | 1270 | case 'P': |
| 982 | - if ($rr[4]<12) $rr[4] += 12; |
|
| 1271 | + if ($rr[4]<12) |
|
| 1272 | + { |
|
| 1273 | + $rr[4] += 12; |
|
| 1274 | + } |
|
| 983 | 1275 | break; |
| 984 | 1276 | case 'A': |
| 985 | - if ($rr[4]==12) $rr[4] = 0; |
|
| 1277 | + if ($rr[4]==12) |
|
| 1278 | + { |
|
| 1279 | + $rr[4] = 0; |
|
| 1280 | + } |
|
| 986 | 1281 | break; |
| 987 | 1282 | default: |
| 988 | 1283 | break; |
@@ -629,10 +629,10 @@ discard block |
||
| 629 | 629 | { |
| 630 | 630 | |
| 631 | 631 | if (strtoupper($blobtype) == 'CLOB') { |
| 632 | - $sql = "UPDATE $table SET $column='" . $val . "' WHERE $where"; |
|
| 632 | + $sql = "update $table SET $column='" . $val . "' WHERE $where"; |
|
| 633 | 633 | return $this->Execute($sql) != false; |
| 634 | 634 | } |
| 635 | - $sql = "UPDATE $table SET $column=0x".bin2hex($val)." WHERE $where"; |
|
| 635 | + $sql = "update $table SET $column=0x".bin2hex($val)." WHERE $where"; |
|
| 636 | 636 | return $this->Execute($sql) != false; |
| 637 | 637 | } |
| 638 | 638 | |
@@ -743,7 +743,7 @@ discard block |
||
| 743 | 743 | |
| 744 | 744 | function _initrs() |
| 745 | 745 | { |
| 746 | - GLOBAL $ADODB_COUNTRECS; |
|
| 746 | + global $ADODB_COUNTRECS; |
|
| 747 | 747 | $this->_numOfRows = ($ADODB_COUNTRECS)? @mssql_num_rows($this->_queryID):-1; |
| 748 | 748 | $this->_numOfFields = @mssql_num_fields($this->_queryID); |
| 749 | 749 | } |
@@ -40,6 +40,9 @@ discard block |
||
| 40 | 40 | |
| 41 | 41 | # define the LOB descriptor type for the given type |
| 42 | 42 | # returns false if no LOB descriptor |
| 43 | +/** |
|
| 44 | + * @param boolean $type |
|
| 45 | + */ |
|
| 43 | 46 | function oci_lob_desc($type) { |
| 44 | 47 | switch ($type) { |
| 45 | 48 | case OCI_B_BFILE: $result = OCI_D_FILE; break; |
@@ -1152,7 +1155,7 @@ discard block |
||
| 1152 | 1155 | * @param [magic_quotes] if $s is GET/POST var, set to get_magic_quotes_gpc(). |
| 1153 | 1156 | * This undoes the stupidity of magic quotes for GPC. |
| 1154 | 1157 | * |
| 1155 | - * @return quoted string to be sent back to database |
|
| 1158 | + * @return string string to be sent back to database |
|
| 1156 | 1159 | */ |
| 1157 | 1160 | function qstr($s,$magic_quotes=false) |
| 1158 | 1161 | { |
@@ -120,8 +120,8 @@ discard block |
||
| 120 | 120 | $fld->scale = $rs->fields[3]; |
| 121 | 121 | if ($rs->fields[1] == 'NUMBER' && $rs->fields[3] == 0) { |
| 122 | 122 | $fld->type ='INT'; |
| 123 | - $fld->max_length = $rs->fields[4]; |
|
| 124 | - } |
|
| 123 | + $fld->max_length = $rs->fields[4]; |
|
| 124 | + } |
|
| 125 | 125 | $fld->not_null = (strncmp($rs->fields[5], 'NOT',3) === 0); |
| 126 | 126 | $fld->binary = (strpos($fld->type,'BLOB') !== false); |
| 127 | 127 | $fld->default_value = $rs->fields[6]; |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | if (!function_exists('OCIPLogon')) return null; |
| 185 | 185 | |
| 186 | 186 | |
| 187 | - $this->_errorMsg = false; |
|
| 187 | + $this->_errorMsg = false; |
|
| 188 | 188 | $this->_errorCode = false; |
| 189 | 189 | |
| 190 | 190 | if($argHostname) { // added by Jorma Tuomainen <[email protected]> |
@@ -311,15 +311,15 @@ discard block |
||
| 311 | 311 | // Mark Newnham |
| 312 | 312 | function &MetaIndexes ($table, $primary = FALSE, $owner=false) |
| 313 | 313 | { |
| 314 | - // save old fetch mode |
|
| 315 | - global $ADODB_FETCH_MODE; |
|
| 314 | + // save old fetch mode |
|
| 315 | + global $ADODB_FETCH_MODE; |
|
| 316 | 316 | |
| 317 | - $save = $ADODB_FETCH_MODE; |
|
| 318 | - $ADODB_FETCH_MODE = ADODB_FETCH_NUM; |
|
| 317 | + $save = $ADODB_FETCH_MODE; |
|
| 318 | + $ADODB_FETCH_MODE = ADODB_FETCH_NUM; |
|
| 319 | 319 | |
| 320 | - if ($this->fetchMode !== FALSE) { |
|
| 321 | - $savem = $this->SetFetchMode(FALSE); |
|
| 322 | - } |
|
| 320 | + if ($this->fetchMode !== FALSE) { |
|
| 321 | + $savem = $this->SetFetchMode(FALSE); |
|
| 322 | + } |
|
| 323 | 323 | |
| 324 | 324 | // get index details |
| 325 | 325 | $table = strtoupper($table); |
@@ -334,45 +334,45 @@ discard block |
||
| 334 | 334 | |
| 335 | 335 | if ($primary==TRUE && $primary_key=='') { |
| 336 | 336 | if (isset($savem)) |
| 337 | - $this->SetFetchMode($savem); |
|
| 337 | + $this->SetFetchMode($savem); |
|
| 338 | 338 | $ADODB_FETCH_MODE = $save; |
| 339 | 339 | return $false; //There is no primary key |
| 340 | 340 | } |
| 341 | 341 | |
| 342 | - $rs = $this->Execute(sprintf("SELECT ALL_INDEXES.INDEX_NAME, ALL_INDEXES.UNIQUENESS, ALL_IND_COLUMNS.COLUMN_POSITION, ALL_IND_COLUMNS.COLUMN_NAME FROM ALL_INDEXES,ALL_IND_COLUMNS WHERE UPPER(ALL_INDEXES.TABLE_NAME)='%s' AND ALL_IND_COLUMNS.INDEX_NAME=ALL_INDEXES.INDEX_NAME",$table)); |
|
| 342 | + $rs = $this->Execute(sprintf("SELECT ALL_INDEXES.INDEX_NAME, ALL_INDEXES.UNIQUENESS, ALL_IND_COLUMNS.COLUMN_POSITION, ALL_IND_COLUMNS.COLUMN_NAME FROM ALL_INDEXES,ALL_IND_COLUMNS WHERE UPPER(ALL_INDEXES.TABLE_NAME)='%s' AND ALL_IND_COLUMNS.INDEX_NAME=ALL_INDEXES.INDEX_NAME",$table)); |
|
| 343 | 343 | |
| 344 | 344 | |
| 345 | - if (!is_object($rs)) { |
|
| 345 | + if (!is_object($rs)) { |
|
| 346 | 346 | if (isset($savem)) |
| 347 | 347 | $this->SetFetchMode($savem); |
| 348 | 348 | $ADODB_FETCH_MODE = $save; |
| 349 | - return $false; |
|
| 350 | - } |
|
| 349 | + return $false; |
|
| 350 | + } |
|
| 351 | 351 | |
| 352 | 352 | $indexes = array (); |
| 353 | - // parse index data into array |
|
| 353 | + // parse index data into array |
|
| 354 | 354 | |
| 355 | - while ($row = $rs->FetchRow()) { |
|
| 355 | + while ($row = $rs->FetchRow()) { |
|
| 356 | 356 | if ($primary && $row[0] != $primary_key) continue; |
| 357 | - if (!isset($indexes[$row[0]])) { |
|
| 357 | + if (!isset($indexes[$row[0]])) { |
|
| 358 | 358 | $indexes[$row[0]] = array( |
| 359 | 359 | 'unique' => ($row[1] == 'UNIQUE'), |
| 360 | 360 | 'columns' => array() |
| 361 | 361 | ); |
| 362 | - } |
|
| 363 | - $indexes[$row[0]]['columns'][$row[2] - 1] = $row[3]; |
|
| 364 | - } |
|
| 362 | + } |
|
| 363 | + $indexes[$row[0]]['columns'][$row[2] - 1] = $row[3]; |
|
| 364 | + } |
|
| 365 | 365 | |
| 366 | - // sort columns by order in the index |
|
| 367 | - foreach ( array_keys ($indexes) as $index ) { |
|
| 368 | - ksort ($indexes[$index]['columns']); |
|
| 369 | - } |
|
| 366 | + // sort columns by order in the index |
|
| 367 | + foreach ( array_keys ($indexes) as $index ) { |
|
| 368 | + ksort ($indexes[$index]['columns']); |
|
| 369 | + } |
|
| 370 | 370 | |
| 371 | 371 | if (isset($savem)) { |
| 372 | - $this->SetFetchMode($savem); |
|
| 372 | + $this->SetFetchMode($savem); |
|
| 373 | 373 | $ADODB_FETCH_MODE = $save; |
| 374 | 374 | } |
| 375 | - return $indexes; |
|
| 375 | + return $indexes; |
|
| 376 | 376 | } |
| 377 | 377 | |
| 378 | 378 | function BeginTrans() |
@@ -630,24 +630,24 @@ discard block |
||
| 630 | 630 | } |
| 631 | 631 | |
| 632 | 632 | /** |
| 633 | - * Usage: |
|
| 634 | - * Store BLOBs and CLOBs |
|
| 635 | - * |
|
| 636 | - * Example: to store $var in a blob |
|
| 637 | - * |
|
| 638 | - * $conn->Execute('insert into TABLE (id,ablob) values(12,empty_blob())'); |
|
| 639 | - * $conn->UpdateBlob('TABLE', 'ablob', $varHoldingBlob, 'ID=12', 'BLOB'); |
|
| 640 | - * |
|
| 641 | - * $blobtype supports 'BLOB' and 'CLOB', but you need to change to 'empty_clob()'. |
|
| 642 | - * |
|
| 643 | - * to get length of LOB: |
|
| 644 | - * select DBMS_LOB.GETLENGTH(ablob) from TABLE |
|
| 645 | - * |
|
| 646 | - * If you are using CURSOR_SHARING = force, it appears this will case a segfault |
|
| 647 | - * under oracle 8.1.7.0. Run: |
|
| 648 | - * $db->Execute('ALTER SESSION SET CURSOR_SHARING=EXACT'); |
|
| 649 | - * before UpdateBlob() then... |
|
| 650 | - */ |
|
| 633 | + * Usage: |
|
| 634 | + * Store BLOBs and CLOBs |
|
| 635 | + * |
|
| 636 | + * Example: to store $var in a blob |
|
| 637 | + * |
|
| 638 | + * $conn->Execute('insert into TABLE (id,ablob) values(12,empty_blob())'); |
|
| 639 | + * $conn->UpdateBlob('TABLE', 'ablob', $varHoldingBlob, 'ID=12', 'BLOB'); |
|
| 640 | + * |
|
| 641 | + * $blobtype supports 'BLOB' and 'CLOB', but you need to change to 'empty_clob()'. |
|
| 642 | + * |
|
| 643 | + * to get length of LOB: |
|
| 644 | + * select DBMS_LOB.GETLENGTH(ablob) from TABLE |
|
| 645 | + * |
|
| 646 | + * If you are using CURSOR_SHARING = force, it appears this will case a segfault |
|
| 647 | + * under oracle 8.1.7.0. Run: |
|
| 648 | + * $db->Execute('ALTER SESSION SET CURSOR_SHARING=EXACT'); |
|
| 649 | + * before UpdateBlob() then... |
|
| 650 | + */ |
|
| 651 | 651 | |
| 652 | 652 | function UpdateBlob($table,$column,$val,$where,$blobtype='BLOB') |
| 653 | 653 | { |
@@ -681,8 +681,8 @@ discard block |
||
| 681 | 681 | } |
| 682 | 682 | |
| 683 | 683 | /** |
| 684 | - * Usage: store file pointed to by $var in a blob |
|
| 685 | - */ |
|
| 684 | + * Usage: store file pointed to by $var in a blob |
|
| 685 | + */ |
|
| 686 | 686 | function UpdateBlobFile($table,$column,$val,$where,$blobtype='BLOB') |
| 687 | 687 | { |
| 688 | 688 | switch(strtoupper($blobtype)) { |
@@ -710,12 +710,12 @@ discard block |
||
| 710 | 710 | } |
| 711 | 711 | |
| 712 | 712 | /** |
| 713 | - * Execute SQL |
|
| 714 | - * |
|
| 715 | - * @param sql SQL statement to execute, or possibly an array holding prepared statement ($sql[0] will hold sql text) |
|
| 716 | - * @param [inputarr] holds the input data to bind to. Null elements will be set to null. |
|
| 717 | - * @return RecordSet or false |
|
| 718 | - */ |
|
| 713 | + * Execute SQL |
|
| 714 | + * |
|
| 715 | + * @param sql SQL statement to execute, or possibly an array holding prepared statement ($sql[0] will hold sql text) |
|
| 716 | + * @param [inputarr] holds the input data to bind to. Null elements will be set to null. |
|
| 717 | + * @return RecordSet or false |
|
| 718 | + */ |
|
| 719 | 719 | function &Execute($sql,$inputarr=false) |
| 720 | 720 | { |
| 721 | 721 | if ($this->fnExecute) { |
@@ -843,9 +843,9 @@ discard block |
||
| 843 | 843 | |
| 844 | 844 | if (!is_array($stmt)) return false; |
| 845 | 845 | |
| 846 | - if (($type == OCI_B_CURSOR) && sizeof($stmt) >= 5) { |
|
| 847 | - return OCIBindByName($stmt[1],":".$name,$stmt[4],$size,$type); |
|
| 848 | - } |
|
| 846 | + if (($type == OCI_B_CURSOR) && sizeof($stmt) >= 5) { |
|
| 847 | + return OCIBindByName($stmt[1],":".$name,$stmt[4],$size,$type); |
|
| 848 | + } |
|
| 849 | 849 | |
| 850 | 850 | if ($name == false) { |
| 851 | 851 | if ($type !== false) $rez = OCIBindByName($stmt[1],":".$stmt[2],$var,$size,$type); |
@@ -855,13 +855,13 @@ discard block |
||
| 855 | 855 | if ($this->debug) { |
| 856 | 856 | ADOConnection::outp("<b>Bind</b>: name = $name"); |
| 857 | 857 | } |
| 858 | - //we have to create a new Descriptor here |
|
| 858 | + //we have to create a new Descriptor here |
|
| 859 | 859 | $numlob = count($this->_refLOBs); |
| 860 | - $this->_refLOBs[$numlob]['LOB'] = OCINewDescriptor($this->_connectionID, oci_lob_desc($type)); |
|
| 860 | + $this->_refLOBs[$numlob]['LOB'] = OCINewDescriptor($this->_connectionID, oci_lob_desc($type)); |
|
| 861 | 861 | $this->_refLOBs[$numlob]['TYPE'] = $isOutput; |
| 862 | 862 | |
| 863 | 863 | $tmp = &$this->_refLOBs[$numlob]['LOB']; |
| 864 | - $rez = OCIBindByName($stmt[1], ":".$name, $tmp, -1, $type); |
|
| 864 | + $rez = OCIBindByName($stmt[1], ":".$name, $tmp, -1, $type); |
|
| 865 | 865 | if ($this->debug) { |
| 866 | 866 | ADOConnection::outp("<b>Bind</b>: descriptor has been allocated, var (".$name.") binded"); |
| 867 | 867 | } |
@@ -987,7 +987,7 @@ discard block |
||
| 987 | 987 | } |
| 988 | 988 | } |
| 989 | 989 | |
| 990 | - $this->_errorMsg = false; |
|
| 990 | + $this->_errorMsg = false; |
|
| 991 | 991 | $this->_errorCode = false; |
| 992 | 992 | if (OCIExecute($stmt,$this->_commit)) { |
| 993 | 993 | //OCIInternalDebug(1); |
@@ -1002,41 +1002,41 @@ discard block |
||
| 1002 | 1002 | //$_GLOBALS[$this -> _refLOBs[$key]['VAR']] = $tmp; |
| 1003 | 1003 | $this -> _refLOBs[$key]['VAR'] = $tmp; |
| 1004 | 1004 | } else { |
| 1005 | - $this->_refLOBs[$key]['LOB']->save($this->_refLOBs[$key]['VAR']); |
|
| 1005 | + $this->_refLOBs[$key]['LOB']->save($this->_refLOBs[$key]['VAR']); |
|
| 1006 | 1006 | $this -> _refLOBs[$key]['LOB']->free(); |
| 1007 | 1007 | unset($this -> _refLOBs[$key]); |
| 1008 | - if ($this->debug) { |
|
| 1008 | + if ($this->debug) { |
|
| 1009 | 1009 | ADOConnection::outp("<b>IN LOB</b>: LOB has been saved. <br>"); |
| 1010 | 1010 | } |
| 1011 | - } |
|
| 1011 | + } |
|
| 1012 | 1012 | } |
| 1013 | 1013 | } |
| 1014 | 1014 | |
| 1015 | - switch (@OCIStatementType($stmt)) { |
|
| 1016 | - case "SELECT": |
|
| 1015 | + switch (@OCIStatementType($stmt)) { |
|
| 1016 | + case "SELECT": |
|
| 1017 | 1017 | return $stmt; |
| 1018 | 1018 | |
| 1019 | 1019 | case 'DECLARE': |
| 1020 | - case "BEGIN": |
|
| 1021 | - if (is_array($sql) && !empty($sql[4])) { |
|
| 1020 | + case "BEGIN": |
|
| 1021 | + if (is_array($sql) && !empty($sql[4])) { |
|
| 1022 | 1022 | $cursor = $sql[4]; |
| 1023 | 1023 | if (is_resource($cursor)) { |
| 1024 | 1024 | $ok = OCIExecute($cursor); |
| 1025 | - return $cursor; |
|
| 1025 | + return $cursor; |
|
| 1026 | 1026 | } |
| 1027 | 1027 | return $stmt; |
| 1028 | - } else { |
|
| 1028 | + } else { |
|
| 1029 | 1029 | if (is_resource($stmt)) { |
| 1030 | 1030 | OCIFreeStatement($stmt); |
| 1031 | 1031 | return true; |
| 1032 | 1032 | } |
| 1033 | - return $stmt; |
|
| 1034 | - } |
|
| 1035 | - break; |
|
| 1036 | - default : |
|
| 1033 | + return $stmt; |
|
| 1034 | + } |
|
| 1035 | + break; |
|
| 1036 | + default : |
|
| 1037 | 1037 | // ociclose -- no because it could be used in a LOB? |
| 1038 | - return true; |
|
| 1039 | - } |
|
| 1038 | + return true; |
|
| 1039 | + } |
|
| 1040 | 1040 | } |
| 1041 | 1041 | return false; |
| 1042 | 1042 | } |
@@ -454,64 +454,64 @@ discard block |
||
| 454 | 454 | for ($i=0; $i < $len; $i++) { |
| 455 | 455 | $ch = $fmt[$i]; |
| 456 | 456 | switch($ch) { |
| 457 | - case 'Y': |
|
| 458 | - case 'y': |
|
| 459 | - $s .= 'YYYY'; |
|
| 460 | - break; |
|
| 461 | - case 'Q': |
|
| 462 | - case 'q': |
|
| 463 | - $s .= 'Q'; |
|
| 464 | - break; |
|
| 457 | + case 'Y': |
|
| 458 | + case 'y': |
|
| 459 | + $s .= 'YYYY'; |
|
| 460 | + break; |
|
| 461 | + case 'Q': |
|
| 462 | + case 'q': |
|
| 463 | + $s .= 'Q'; |
|
| 464 | + break; |
|
| 465 | 465 | |
| 466 | - case 'M': |
|
| 467 | - $s .= 'Mon'; |
|
| 468 | - break; |
|
| 466 | + case 'M': |
|
| 467 | + $s .= 'Mon'; |
|
| 468 | + break; |
|
| 469 | 469 | |
| 470 | - case 'm': |
|
| 471 | - $s .= 'MM'; |
|
| 472 | - break; |
|
| 473 | - case 'D': |
|
| 474 | - case 'd': |
|
| 475 | - $s .= 'DD'; |
|
| 476 | - break; |
|
| 470 | + case 'm': |
|
| 471 | + $s .= 'MM'; |
|
| 472 | + break; |
|
| 473 | + case 'D': |
|
| 474 | + case 'd': |
|
| 475 | + $s .= 'DD'; |
|
| 476 | + break; |
|
| 477 | 477 | |
| 478 | - case 'H': |
|
| 479 | - $s.= 'HH24'; |
|
| 480 | - break; |
|
| 478 | + case 'H': |
|
| 479 | + $s.= 'HH24'; |
|
| 480 | + break; |
|
| 481 | 481 | |
| 482 | - case 'h': |
|
| 483 | - $s .= 'HH'; |
|
| 484 | - break; |
|
| 482 | + case 'h': |
|
| 483 | + $s .= 'HH'; |
|
| 484 | + break; |
|
| 485 | 485 | |
| 486 | - case 'i': |
|
| 487 | - $s .= 'MI'; |
|
| 488 | - break; |
|
| 486 | + case 'i': |
|
| 487 | + $s .= 'MI'; |
|
| 488 | + break; |
|
| 489 | 489 | |
| 490 | - case 's': |
|
| 491 | - $s .= 'SS'; |
|
| 492 | - break; |
|
| 490 | + case 's': |
|
| 491 | + $s .= 'SS'; |
|
| 492 | + break; |
|
| 493 | 493 | |
| 494 | - case 'a': |
|
| 495 | - case 'A': |
|
| 496 | - $s .= 'AM'; |
|
| 497 | - break; |
|
| 494 | + case 'a': |
|
| 495 | + case 'A': |
|
| 496 | + $s .= 'AM'; |
|
| 497 | + break; |
|
| 498 | 498 | |
| 499 | - case 'w': |
|
| 500 | - $s .= 'D'; |
|
| 501 | - break; |
|
| 499 | + case 'w': |
|
| 500 | + $s .= 'D'; |
|
| 501 | + break; |
|
| 502 | 502 | |
| 503 | - case 'l': |
|
| 504 | - $s .= 'DAY'; |
|
| 505 | - break; |
|
| 503 | + case 'l': |
|
| 504 | + $s .= 'DAY'; |
|
| 505 | + break; |
|
| 506 | 506 | |
| 507 | - default: |
|
| 508 | - // handle escape characters... |
|
| 509 | - if ($ch == '\\') { |
|
| 510 | - $i++; |
|
| 511 | - $ch = substr($fmt,$i,1); |
|
| 512 | - } |
|
| 513 | - if (strpos('-/.:;, ',$ch) !== false) $s .= $ch; |
|
| 514 | - else $s .= '"'.$ch.'"'; |
|
| 507 | + default: |
|
| 508 | + // handle escape characters... |
|
| 509 | + if ($ch == '\\') { |
|
| 510 | + $i++; |
|
| 511 | + $ch = substr($fmt,$i,1); |
|
| 512 | + } |
|
| 513 | + if (strpos('-/.:;, ',$ch) !== false) $s .= $ch; |
|
| 514 | + else $s .= '"'.$ch.'"'; |
|
| 515 | 515 | |
| 516 | 516 | } |
| 517 | 517 | } |
@@ -655,9 +655,9 @@ discard block |
||
| 655 | 655 | //if (strlen($val) < 4000) return $this->Execute("UPDATE $table SET $column=:blob WHERE $where",array('blob'=>$val)) != false; |
| 656 | 656 | |
| 657 | 657 | switch(strtoupper($blobtype)) { |
| 658 | - default: ADOConnection::outp("<b>UpdateBlob</b>: Unknown blobtype=$blobtype"); return false; |
|
| 659 | - case 'BLOB': $type = OCI_B_BLOB; break; |
|
| 660 | - case 'CLOB': $type = OCI_B_CLOB; break; |
|
| 658 | + default: ADOConnection::outp("<b>UpdateBlob</b>: Unknown blobtype=$blobtype"); return false; |
|
| 659 | + case 'BLOB': $type = OCI_B_BLOB; break; |
|
| 660 | + case 'CLOB': $type = OCI_B_CLOB; break; |
|
| 661 | 661 | } |
| 662 | 662 | |
| 663 | 663 | if ($this->databaseType == 'oci8po') |
@@ -686,9 +686,9 @@ discard block |
||
| 686 | 686 | function UpdateBlobFile($table,$column,$val,$where,$blobtype='BLOB') |
| 687 | 687 | { |
| 688 | 688 | switch(strtoupper($blobtype)) { |
| 689 | - default: ADOConnection::outp( "<b>UpdateBlob</b>: Unknown blobtype=$blobtype"); return false; |
|
| 690 | - case 'BLOB': $type = OCI_B_BLOB; break; |
|
| 691 | - case 'CLOB': $type = OCI_B_CLOB; break; |
|
| 689 | + default: ADOConnection::outp( "<b>UpdateBlob</b>: Unknown blobtype=$blobtype"); return false; |
|
| 690 | + case 'BLOB': $type = OCI_B_BLOB; break; |
|
| 691 | + case 'CLOB': $type = OCI_B_CLOB; break; |
|
| 692 | 692 | } |
| 693 | 693 | |
| 694 | 694 | if ($this->databaseType == 'oci8po') |
@@ -1196,12 +1196,12 @@ discard block |
||
| 1196 | 1196 | } |
| 1197 | 1197 | switch ($mode) |
| 1198 | 1198 | { |
| 1199 | - case ADODB_FETCH_ASSOC:$this->fetchMode = OCI_ASSOC+OCI_RETURN_NULLS+OCI_RETURN_LOBS; break; |
|
| 1200 | - case ADODB_FETCH_DEFAULT: |
|
| 1201 | - case ADODB_FETCH_BOTH:$this->fetchMode = OCI_NUM+OCI_ASSOC+OCI_RETURN_NULLS+OCI_RETURN_LOBS; break; |
|
| 1202 | - case ADODB_FETCH_NUM: |
|
| 1203 | - default: |
|
| 1204 | - $this->fetchMode = OCI_NUM+OCI_RETURN_NULLS+OCI_RETURN_LOBS; break; |
|
| 1199 | + case ADODB_FETCH_ASSOC:$this->fetchMode = OCI_ASSOC+OCI_RETURN_NULLS+OCI_RETURN_LOBS; break; |
|
| 1200 | + case ADODB_FETCH_DEFAULT: |
|
| 1201 | + case ADODB_FETCH_BOTH:$this->fetchMode = OCI_NUM+OCI_ASSOC+OCI_RETURN_NULLS+OCI_RETURN_LOBS; break; |
|
| 1202 | + case ADODB_FETCH_NUM: |
|
| 1203 | + default: |
|
| 1204 | + $this->fetchMode = OCI_NUM+OCI_RETURN_NULLS+OCI_RETURN_LOBS; break; |
|
| 1205 | 1205 | } |
| 1206 | 1206 | |
| 1207 | 1207 | $this->adodbFetchMode = $mode; |
@@ -1415,37 +1415,37 @@ discard block |
||
| 1415 | 1415 | switch (strtoupper($t)) { |
| 1416 | 1416 | case 'VARCHAR': |
| 1417 | 1417 | case 'VARCHAR2': |
| 1418 | - case 'CHAR': |
|
| 1419 | - case 'VARBINARY': |
|
| 1420 | - case 'BINARY': |
|
| 1421 | - case 'NCHAR': |
|
| 1422 | - case 'NVARCHAR': |
|
| 1423 | - case 'NVARCHAR2': |
|
| 1424 | - if (isset($this) && $len <= $this->blobSize) return 'C'; |
|
| 1418 | + case 'CHAR': |
|
| 1419 | + case 'VARBINARY': |
|
| 1420 | + case 'BINARY': |
|
| 1421 | + case 'NCHAR': |
|
| 1422 | + case 'NVARCHAR': |
|
| 1423 | + case 'NVARCHAR2': |
|
| 1424 | + if (isset($this) && $len <= $this->blobSize) return 'C'; |
|
| 1425 | 1425 | |
| 1426 | - case 'NCLOB': |
|
| 1427 | - case 'LONG': |
|
| 1428 | - case 'LONG VARCHAR': |
|
| 1429 | - case 'CLOB': |
|
| 1430 | - return 'X'; |
|
| 1426 | + case 'NCLOB': |
|
| 1427 | + case 'LONG': |
|
| 1428 | + case 'LONG VARCHAR': |
|
| 1429 | + case 'CLOB': |
|
| 1430 | + return 'X'; |
|
| 1431 | 1431 | |
| 1432 | - case 'LONG RAW': |
|
| 1433 | - case 'LONG VARBINARY': |
|
| 1434 | - case 'BLOB': |
|
| 1435 | - return 'B'; |
|
| 1432 | + case 'LONG RAW': |
|
| 1433 | + case 'LONG VARBINARY': |
|
| 1434 | + case 'BLOB': |
|
| 1435 | + return 'B'; |
|
| 1436 | 1436 | |
| 1437 | - case 'DATE': |
|
| 1438 | - return ($this->connection->datetime) ? 'T' : 'D'; |
|
| 1437 | + case 'DATE': |
|
| 1438 | + return ($this->connection->datetime) ? 'T' : 'D'; |
|
| 1439 | 1439 | |
| 1440 | 1440 | |
| 1441 | - case 'TIMESTAMP': return 'T'; |
|
| 1441 | + case 'TIMESTAMP': return 'T'; |
|
| 1442 | 1442 | |
| 1443 | - case 'INT': |
|
| 1444 | - case 'SMALLINT': |
|
| 1445 | - case 'INTEGER': |
|
| 1446 | - return 'I'; |
|
| 1443 | + case 'INT': |
|
| 1444 | + case 'SMALLINT': |
|
| 1445 | + case 'INTEGER': |
|
| 1446 | + return 'I'; |
|
| 1447 | 1447 | |
| 1448 | - default: return 'N'; |
|
| 1448 | + default: return 'N'; |
|
| 1449 | 1449 | } |
| 1450 | 1450 | } |
| 1451 | 1451 | } |
@@ -1459,11 +1459,11 @@ discard block |
||
| 1459 | 1459 | } |
| 1460 | 1460 | switch ($mode) |
| 1461 | 1461 | { |
| 1462 | - case ADODB_FETCH_ASSOC:$this->fetchMode = OCI_ASSOC+OCI_RETURN_NULLS+OCI_RETURN_LOBS; break; |
|
| 1463 | - case ADODB_FETCH_DEFAULT: |
|
| 1464 | - case ADODB_FETCH_BOTH:$this->fetchMode = OCI_NUM+OCI_ASSOC+OCI_RETURN_NULLS+OCI_RETURN_LOBS; break; |
|
| 1465 | - case ADODB_FETCH_NUM: |
|
| 1466 | - default: $this->fetchMode = OCI_NUM+OCI_RETURN_NULLS+OCI_RETURN_LOBS; break; |
|
| 1462 | + case ADODB_FETCH_ASSOC:$this->fetchMode = OCI_ASSOC+OCI_RETURN_NULLS+OCI_RETURN_LOBS; break; |
|
| 1463 | + case ADODB_FETCH_DEFAULT: |
|
| 1464 | + case ADODB_FETCH_BOTH:$this->fetchMode = OCI_NUM+OCI_ASSOC+OCI_RETURN_NULLS+OCI_RETURN_LOBS; break; |
|
| 1465 | + case ADODB_FETCH_NUM: |
|
| 1466 | + default: $this->fetchMode = OCI_NUM+OCI_RETURN_NULLS+OCI_RETURN_LOBS; break; |
|
| 1467 | 1467 | } |
| 1468 | 1468 | $this->adodbFetchMode = $mode; |
| 1469 | 1469 | $this->_queryID = $queryID; |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | var $databaseType = 'oci8'; |
| 57 | 57 | var $dataProvider = 'oci8'; |
| 58 | 58 | var $replaceQuote = "''"; // string to use to replace quotes |
| 59 | - var $concat_operator='||'; |
|
| 59 | + var $concat_operator = '||'; |
|
| 60 | 60 | var $sysDate = "TRUNC(SYSDATE)"; |
| 61 | 61 | var $sysTimeStamp = 'SYSDATE'; |
| 62 | 62 | var $metaDatabasesSQL = "SELECT USERNAME FROM ALL_USERS WHERE USERNAME NOT IN ('SYS','SYSTEM','DBSNMP','OUTLN') ORDER BY 1"; |
@@ -77,12 +77,12 @@ discard block |
||
| 77 | 77 | var $_bind = false; |
| 78 | 78 | var $_hasOCIFetchStatement = false; |
| 79 | 79 | var $_getarray = false; // currently not working |
| 80 | - var $leftOuter = ''; // oracle wierdness, $col = $value (+) for LEFT OUTER, $col (+)= $value for RIGHT OUTER |
|
| 80 | + var $leftOuter = ''; // oracle wierdness, $col = $value (+) for LEFT OUTER, $col (+)= $value for RIGHT OUTER |
|
| 81 | 81 | var $session_sharing_force_blob = false; // alter session on updateblob if set to true |
| 82 | 82 | var $firstrows = true; // enable first rows optimization on SelectLimit() |
| 83 | 83 | var $selectOffsetAlg1 = 100; // when to use 1st algorithm of selectlimit. |
| 84 | - var $NLS_DATE_FORMAT = 'YYYY-MM-DD'; // To include time, use 'RRRR-MM-DD HH24:MI:SS' |
|
| 85 | - var $useDBDateFormatForTextInput=false; |
|
| 84 | + var $NLS_DATE_FORMAT = 'YYYY-MM-DD'; // To include time, use 'RRRR-MM-DD HH24:MI:SS' |
|
| 85 | + var $useDBDateFormatForTextInput = false; |
|
| 86 | 86 | var $datetime = false; // MetaType('DATE') returns 'D' (datetime==false) or 'T' (datetime == true) |
| 87 | 87 | var $_refLOBs = array(); |
| 88 | 88 | |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | $ADODB_FETCH_MODE = ADODB_FETCH_NUM; |
| 105 | 105 | if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false); |
| 106 | 106 | |
| 107 | - $rs = $this->Execute(sprintf($this->metaColumnsSQL,strtoupper($table))); |
|
| 107 | + $rs = $this->Execute(sprintf($this->metaColumnsSQL, strtoupper($table))); |
|
| 108 | 108 | |
| 109 | 109 | if (isset($savem)) $this->SetFetchMode($savem); |
| 110 | 110 | $ADODB_FETCH_MODE = $save; |
@@ -119,11 +119,11 @@ discard block |
||
| 119 | 119 | $fld->max_length = $rs->fields[2]; |
| 120 | 120 | $fld->scale = $rs->fields[3]; |
| 121 | 121 | if ($rs->fields[1] == 'NUMBER' && $rs->fields[3] == 0) { |
| 122 | - $fld->type ='INT'; |
|
| 122 | + $fld->type = 'INT'; |
|
| 123 | 123 | $fld->max_length = $rs->fields[4]; |
| 124 | 124 | } |
| 125 | - $fld->not_null = (strncmp($rs->fields[5], 'NOT',3) === 0); |
|
| 126 | - $fld->binary = (strpos($fld->type,'BLOB') !== false); |
|
| 125 | + $fld->not_null = (strncmp($rs->fields[5], 'NOT', 3) === 0); |
|
| 126 | + $fld->binary = (strpos($fld->type, 'BLOB') !== false); |
|
| 127 | 127 | $fld->default_value = $rs->fields[6]; |
| 128 | 128 | |
| 129 | 129 | if ($ADODB_FETCH_MODE == ADODB_FETCH_NUM) $retarr[] = $fld; |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | |
| 140 | 140 | function Time() |
| 141 | 141 | { |
| 142 | - $rs =& $this->Execute("select TO_CHAR($this->sysTimeStamp,'YYYY-MM-DD HH24:MI:SS') from dual"); |
|
| 142 | + $rs = & $this->Execute("select TO_CHAR($this->sysTimeStamp,'YYYY-MM-DD HH24:MI:SS') from dual"); |
|
| 143 | 143 | if ($rs && !$rs->EOF) return $this->UnixTimeStamp(reset($rs->fields)); |
| 144 | 144 | |
| 145 | 145 | return false; |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | There are 3 connection modes, 0 = non-persistent, 1 = persistent, 2 = force new connection |
| 180 | 180 | |
| 181 | 181 | */ |
| 182 | - function _connect($argHostname, $argUsername, $argPassword, $argDatabasename,$mode=0) |
|
| 182 | + function _connect($argHostname, $argUsername, $argPassword, $argDatabasename, $mode = 0) |
|
| 183 | 183 | { |
| 184 | 184 | if (!function_exists('OCIPLogon')) return null; |
| 185 | 185 | |
@@ -187,45 +187,45 @@ discard block |
||
| 187 | 187 | $this->_errorMsg = false; |
| 188 | 188 | $this->_errorCode = false; |
| 189 | 189 | |
| 190 | - if($argHostname) { // added by Jorma Tuomainen <[email protected]> |
|
| 190 | + if ($argHostname) { // added by Jorma Tuomainen <[email protected]> |
|
| 191 | 191 | if (empty($argDatabasename)) $argDatabasename = $argHostname; |
| 192 | 192 | else { |
| 193 | - if(strpos($argHostname,":")) { |
|
| 194 | - $argHostinfo=explode(":",$argHostname); |
|
| 195 | - $argHostname=$argHostinfo[0]; |
|
| 196 | - $argHostport=$argHostinfo[1]; |
|
| 193 | + if (strpos($argHostname, ":")) { |
|
| 194 | + $argHostinfo = explode(":", $argHostname); |
|
| 195 | + $argHostname = $argHostinfo[0]; |
|
| 196 | + $argHostport = $argHostinfo[1]; |
|
| 197 | 197 | } else { |
| 198 | - $argHostport="1521"; |
|
| 198 | + $argHostport = "1521"; |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | if ($this->connectSID) { |
| 202 | - $argDatabasename="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=".$argHostname |
|
| 202 | + $argDatabasename = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=".$argHostname |
|
| 203 | 203 | .")(PORT=$argHostport))(CONNECT_DATA=(SID=$argDatabasename)))"; |
| 204 | 204 | } else |
| 205 | - $argDatabasename="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=".$argHostname |
|
| 205 | + $argDatabasename = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=".$argHostname |
|
| 206 | 206 | .")(PORT=$argHostport))(CONNECT_DATA=(SERVICE_NAME=$argDatabasename)))"; |
| 207 | 207 | } |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | //if ($argHostname) print "<p>Connect: 1st argument should be left blank for $this->databaseType</p>"; |
| 211 | - if ($mode==1) { |
|
| 211 | + if ($mode == 1) { |
|
| 212 | 212 | $this->_connectionID = ($this->charSet) ? |
| 213 | - OCIPLogon($argUsername,$argPassword, $argDatabasename) |
|
| 213 | + OCIPLogon($argUsername, $argPassword, $argDatabasename) |
|
| 214 | 214 | : |
| 215 | - OCIPLogon($argUsername,$argPassword, $argDatabasename, $this->charSet) |
|
| 215 | + OCIPLogon($argUsername, $argPassword, $argDatabasename, $this->charSet) |
|
| 216 | 216 | ; |
| 217 | 217 | if ($this->_connectionID && $this->autoRollback) OCIrollback($this->_connectionID); |
| 218 | - } else if ($mode==2) { |
|
| 218 | + } else if ($mode == 2) { |
|
| 219 | 219 | $this->_connectionID = ($this->charSet) ? |
| 220 | - OCINLogon($argUsername,$argPassword, $argDatabasename) |
|
| 220 | + OCINLogon($argUsername, $argPassword, $argDatabasename) |
|
| 221 | 221 | : |
| 222 | - OCINLogon($argUsername,$argPassword, $argDatabasename, $this->charSet); |
|
| 222 | + OCINLogon($argUsername, $argPassword, $argDatabasename, $this->charSet); |
|
| 223 | 223 | |
| 224 | 224 | } else { |
| 225 | 225 | $this->_connectionID = ($this->charSet) ? |
| 226 | - OCILogon($argUsername,$argPassword, $argDatabasename) |
|
| 226 | + OCILogon($argUsername, $argPassword, $argDatabasename) |
|
| 227 | 227 | : |
| 228 | - OCILogon($argUsername,$argPassword, $argDatabasename,$this->charSet); |
|
| 228 | + OCILogon($argUsername, $argPassword, $argDatabasename, $this->charSet); |
|
| 229 | 229 | } |
| 230 | 230 | if (!$this->_connectionID) return false; |
| 231 | 231 | if ($this->_initdate) { |
@@ -249,13 +249,13 @@ discard block |
||
| 249 | 249 | // returns true or false |
| 250 | 250 | function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename) |
| 251 | 251 | { |
| 252 | - return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename,1); |
|
| 252 | + return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename, 1); |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | // returns true or false |
| 256 | 256 | function _nconnect($argHostname, $argUsername, $argPassword, $argDatabasename) |
| 257 | 257 | { |
| 258 | - return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename,2); |
|
| 258 | + return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename, 2); |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | function _affectedrows() |
@@ -264,7 +264,7 @@ discard block |
||
| 264 | 264 | return 0; |
| 265 | 265 | } |
| 266 | 266 | |
| 267 | - function IfNull( $field, $ifNull ) |
|
| 267 | + function IfNull($field, $ifNull) |
|
| 268 | 268 | { |
| 269 | 269 | return " NVL($field, $ifNull) "; // if Oracle |
| 270 | 270 | } |
@@ -275,7 +275,7 @@ discard block |
||
| 275 | 275 | if (empty($d) && $d !== 0) return 'null'; |
| 276 | 276 | |
| 277 | 277 | if (is_string($d)) $d = ADORecordSet::UnixDate($d); |
| 278 | - return "TO_DATE(".adodb_date($this->fmtDate,$d).",'".$this->NLS_DATE_FORMAT."')"; |
|
| 278 | + return "TO_DATE(".adodb_date($this->fmtDate, $d).",'".$this->NLS_DATE_FORMAT."')"; |
|
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | |
@@ -284,23 +284,23 @@ discard block |
||
| 284 | 284 | { |
| 285 | 285 | if (empty($ts) && $ts !== 0) return 'null'; |
| 286 | 286 | if (is_string($ts)) $ts = ADORecordSet::UnixTimeStamp($ts); |
| 287 | - return 'TO_DATE('.adodb_date($this->fmtTimeStamp,$ts).",'RRRR-MM-DD, HH:MI:SS AM')"; |
|
| 287 | + return 'TO_DATE('.adodb_date($this->fmtTimeStamp, $ts).",'RRRR-MM-DD, HH:MI:SS AM')"; |
|
| 288 | 288 | } |
| 289 | 289 | |
| 290 | - function RowLock($tables,$where,$flds='1 as ignore') |
|
| 290 | + function RowLock($tables, $where, $flds = '1 as ignore') |
|
| 291 | 291 | { |
| 292 | 292 | if ($this->autoCommit) $this->BeginTrans(); |
| 293 | 293 | return $this->GetOne("select $flds from $tables where $where for update"); |
| 294 | 294 | } |
| 295 | 295 | |
| 296 | - function &MetaTables($ttype=false,$showSchema=false,$mask=false) |
|
| 296 | + function &MetaTables($ttype = false, $showSchema = false, $mask = false) |
|
| 297 | 297 | { |
| 298 | 298 | if ($mask) { |
| 299 | 299 | $save = $this->metaTablesSQL; |
| 300 | 300 | $mask = $this->qstr(strtoupper($mask)); |
| 301 | 301 | $this->metaTablesSQL .= " AND table_name like $mask"; |
| 302 | 302 | } |
| 303 | - $ret =& ADOConnection::MetaTables($ttype,$showSchema); |
|
| 303 | + $ret = & ADOConnection::MetaTables($ttype, $showSchema); |
|
| 304 | 304 | |
| 305 | 305 | if ($mask) { |
| 306 | 306 | $this->metaTablesSQL = $save; |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | // Mark Newnham |
| 312 | - function &MetaIndexes ($table, $primary = FALSE, $owner=false) |
|
| 312 | + function &MetaIndexes($table, $primary = FALSE, $owner = false) |
|
| 313 | 313 | { |
| 314 | 314 | // save old fetch mode |
| 315 | 315 | global $ADODB_FETCH_MODE; |
@@ -328,18 +328,18 @@ discard block |
||
| 328 | 328 | $primary_key = ''; |
| 329 | 329 | |
| 330 | 330 | $false = false; |
| 331 | - $rs = $this->Execute(sprintf("SELECT * FROM ALL_CONSTRAINTS WHERE UPPER(TABLE_NAME)='%s' AND CONSTRAINT_TYPE='P'",$table)); |
|
| 331 | + $rs = $this->Execute(sprintf("SELECT * FROM ALL_CONSTRAINTS WHERE UPPER(TABLE_NAME)='%s' AND CONSTRAINT_TYPE='P'", $table)); |
|
| 332 | 332 | if ($row = $rs->FetchRow()) |
| 333 | 333 | $primary_key = $row[1]; //constraint_name |
| 334 | 334 | |
| 335 | - if ($primary==TRUE && $primary_key=='') { |
|
| 335 | + if ($primary == TRUE && $primary_key == '') { |
|
| 336 | 336 | if (isset($savem)) |
| 337 | 337 | $this->SetFetchMode($savem); |
| 338 | 338 | $ADODB_FETCH_MODE = $save; |
| 339 | 339 | return $false; //There is no primary key |
| 340 | 340 | } |
| 341 | 341 | |
| 342 | - $rs = $this->Execute(sprintf("SELECT ALL_INDEXES.INDEX_NAME, ALL_INDEXES.UNIQUENESS, ALL_IND_COLUMNS.COLUMN_POSITION, ALL_IND_COLUMNS.COLUMN_NAME FROM ALL_INDEXES,ALL_IND_COLUMNS WHERE UPPER(ALL_INDEXES.TABLE_NAME)='%s' AND ALL_IND_COLUMNS.INDEX_NAME=ALL_INDEXES.INDEX_NAME",$table)); |
|
| 342 | + $rs = $this->Execute(sprintf("SELECT ALL_INDEXES.INDEX_NAME, ALL_INDEXES.UNIQUENESS, ALL_IND_COLUMNS.COLUMN_POSITION, ALL_IND_COLUMNS.COLUMN_NAME FROM ALL_INDEXES,ALL_IND_COLUMNS WHERE UPPER(ALL_INDEXES.TABLE_NAME)='%s' AND ALL_IND_COLUMNS.INDEX_NAME=ALL_INDEXES.INDEX_NAME", $table)); |
|
| 343 | 343 | |
| 344 | 344 | |
| 345 | 345 | if (!is_object($rs)) { |
@@ -349,7 +349,7 @@ discard block |
||
| 349 | 349 | return $false; |
| 350 | 350 | } |
| 351 | 351 | |
| 352 | - $indexes = array (); |
|
| 352 | + $indexes = array(); |
|
| 353 | 353 | // parse index data into array |
| 354 | 354 | |
| 355 | 355 | while ($row = $rs->FetchRow()) { |
@@ -364,8 +364,8 @@ discard block |
||
| 364 | 364 | } |
| 365 | 365 | |
| 366 | 366 | // sort columns by order in the index |
| 367 | - foreach ( array_keys ($indexes) as $index ) { |
|
| 368 | - ksort ($indexes[$index]['columns']); |
|
| 367 | + foreach (array_keys($indexes) as $index) { |
|
| 368 | + ksort($indexes[$index]['columns']); |
|
| 369 | 369 | } |
| 370 | 370 | |
| 371 | 371 | if (isset($savem)) { |
@@ -384,7 +384,7 @@ discard block |
||
| 384 | 384 | return true; |
| 385 | 385 | } |
| 386 | 386 | |
| 387 | - function CommitTrans($ok=true) |
|
| 387 | + function CommitTrans($ok = true) |
|
| 388 | 388 | { |
| 389 | 389 | if ($this->transOff) return true; |
| 390 | 390 | if (!$ok) return $this->RollbackTrans(); |
@@ -445,15 +445,15 @@ discard block |
||
| 445 | 445 | } |
| 446 | 446 | |
| 447 | 447 | // Format date column in sql string given an input format that understands Y M D |
| 448 | - function SQLDate($fmt, $col=false) |
|
| 448 | + function SQLDate($fmt, $col = false) |
|
| 449 | 449 | { |
| 450 | 450 | if (!$col) $col = $this->sysTimeStamp; |
| 451 | 451 | $s = 'TO_CHAR('.$col.",'"; |
| 452 | 452 | |
| 453 | 453 | $len = strlen($fmt); |
| 454 | - for ($i=0; $i < $len; $i++) { |
|
| 454 | + for ($i = 0; $i < $len; $i++) { |
|
| 455 | 455 | $ch = $fmt[$i]; |
| 456 | - switch($ch) { |
|
| 456 | + switch ($ch) { |
|
| 457 | 457 | case 'Y': |
| 458 | 458 | case 'y': |
| 459 | 459 | $s .= 'YYYY'; |
@@ -476,7 +476,7 @@ discard block |
||
| 476 | 476 | break; |
| 477 | 477 | |
| 478 | 478 | case 'H': |
| 479 | - $s.= 'HH24'; |
|
| 479 | + $s .= 'HH24'; |
|
| 480 | 480 | break; |
| 481 | 481 | |
| 482 | 482 | case 'h': |
@@ -508,14 +508,14 @@ discard block |
||
| 508 | 508 | // handle escape characters... |
| 509 | 509 | if ($ch == '\\') { |
| 510 | 510 | $i++; |
| 511 | - $ch = substr($fmt,$i,1); |
|
| 511 | + $ch = substr($fmt, $i, 1); |
|
| 512 | 512 | } |
| 513 | - if (strpos('-/.:;, ',$ch) !== false) $s .= $ch; |
|
| 513 | + if (strpos('-/.:;, ', $ch) !== false) $s .= $ch; |
|
| 514 | 514 | else $s .= '"'.$ch.'"'; |
| 515 | 515 | |
| 516 | 516 | } |
| 517 | 517 | } |
| 518 | - return $s. "')"; |
|
| 518 | + return $s."')"; |
|
| 519 | 519 | } |
| 520 | 520 | |
| 521 | 521 | |
@@ -534,14 +534,14 @@ discard block |
||
| 534 | 534 | This implementation does not appear to work with oracle 8.0.5 or earlier. Comment |
| 535 | 535 | out this function then, and the slower SelectLimit() in the base class will be used. |
| 536 | 536 | */ |
| 537 | - function &SelectLimit($sql,$nrows=-1,$offset=-1, $inputarr=false,$secs2cache=0) |
|
| 537 | + function &SelectLimit($sql, $nrows = -1, $offset = -1, $inputarr = false, $secs2cache = 0) |
|
| 538 | 538 | { |
| 539 | 539 | // seems that oracle only supports 1 hint comment in 8i |
| 540 | 540 | if ($this->firstrows) { |
| 541 | - if (strpos($sql,'/*+') !== false) |
|
| 542 | - $sql = str_replace('/*+ ','/*+FIRST_ROWS ',$sql); |
|
| 541 | + if (strpos($sql, '/*+') !== false) |
|
| 542 | + $sql = str_replace('/*+ ', '/*+FIRST_ROWS ', $sql); |
|
| 543 | 543 | else |
| 544 | - $sql = preg_replace('/^[ \t\n]*select/i','SELECT /*+FIRST_ROWS*/',$sql); |
|
| 544 | + $sql = preg_replace('/^[ \t\n]*select/i', 'SELECT /*+FIRST_ROWS*/', $sql); |
|
| 545 | 545 | } |
| 546 | 546 | |
| 547 | 547 | if ($offset < $this->selectOffsetAlg1) { |
@@ -558,7 +558,7 @@ discard block |
||
| 558 | 558 | } |
| 559 | 559 | // note that $nrows = 0 still has to work ==> no rows returned |
| 560 | 560 | |
| 561 | - $rs =& ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache); |
|
| 561 | + $rs = & ADOConnection::SelectLimit($sql, $nrows, $offset, $inputarr, $secs2cache); |
|
| 562 | 562 | return $rs; |
| 563 | 563 | |
| 564 | 564 | } else { |
@@ -568,25 +568,25 @@ discard block |
||
| 568 | 568 | $q_fields = "SELECT * FROM (".$sql.") WHERE NULL = NULL"; |
| 569 | 569 | |
| 570 | 570 | $false = false; |
| 571 | - if (! $stmt_arr = $this->Prepare($q_fields)) { |
|
| 571 | + if (!$stmt_arr = $this->Prepare($q_fields)) { |
|
| 572 | 572 | return $false; |
| 573 | 573 | } |
| 574 | 574 | $stmt = $stmt_arr[1]; |
| 575 | 575 | |
| 576 | 576 | if (is_array($inputarr)) { |
| 577 | - foreach($inputarr as $k => $v) { |
|
| 577 | + foreach ($inputarr as $k => $v) { |
|
| 578 | 578 | if (is_array($v)) { |
| 579 | 579 | if (sizeof($v) == 2) // suggested by g.giunta@libero. |
| 580 | - OCIBindByName($stmt,":$k",$inputarr[$k][0],$v[1]); |
|
| 580 | + OCIBindByName($stmt, ":$k", $inputarr[$k][0], $v[1]); |
|
| 581 | 581 | else |
| 582 | - OCIBindByName($stmt,":$k",$inputarr[$k][0],$v[1],$v[2]); |
|
| 582 | + OCIBindByName($stmt, ":$k", $inputarr[$k][0], $v[1], $v[2]); |
|
| 583 | 583 | } else { |
| 584 | 584 | $len = -1; |
| 585 | 585 | if ($v === ' ') $len = 1; |
| 586 | 586 | if (isset($bindarr)) { // is prepared sql, so no need to ocibindbyname again |
| 587 | 587 | $bindarr[$k] = $v; |
| 588 | 588 | } else { // dynamic sql, so rebind every time |
| 589 | - OCIBindByName($stmt,":$k",$inputarr[$k],$len); |
|
| 589 | + OCIBindByName($stmt, ":$k", $inputarr[$k], $len); |
|
| 590 | 590 | } |
| 591 | 591 | } |
| 592 | 592 | } |
@@ -598,7 +598,7 @@ discard block |
||
| 598 | 598 | } |
| 599 | 599 | |
| 600 | 600 | $ncols = OCINumCols($stmt); |
| 601 | - for ( $i = 1; $i <= $ncols; $i++ ) { |
|
| 601 | + for ($i = 1; $i <= $ncols; $i++) { |
|
| 602 | 602 | $cols[] = '"'.OCIColumnName($stmt, $i).'"'; |
| 603 | 603 | } |
| 604 | 604 | $result = false; |
@@ -622,8 +622,8 @@ discard block |
||
| 622 | 622 | $inputarr['adodb_nrows'] = $nrows; |
| 623 | 623 | $inputarr['adodb_offset'] = $offset; |
| 624 | 624 | |
| 625 | - if ($secs2cache>0) $rs =& $this->CacheExecute($secs2cache, $sql,$inputarr); |
|
| 626 | - else $rs =& $this->Execute($sql,$inputarr); |
|
| 625 | + if ($secs2cache > 0) $rs = & $this->CacheExecute($secs2cache, $sql, $inputarr); |
|
| 626 | + else $rs = & $this->Execute($sql, $inputarr); |
|
| 627 | 627 | return $rs; |
| 628 | 628 | } |
| 629 | 629 | |
@@ -649,12 +649,12 @@ discard block |
||
| 649 | 649 | * before UpdateBlob() then... |
| 650 | 650 | */ |
| 651 | 651 | |
| 652 | - function UpdateBlob($table,$column,$val,$where,$blobtype='BLOB') |
|
| 652 | + function UpdateBlob($table, $column, $val, $where, $blobtype = 'BLOB') |
|
| 653 | 653 | { |
| 654 | 654 | |
| 655 | 655 | //if (strlen($val) < 4000) return $this->Execute("UPDATE $table SET $column=:blob WHERE $where",array('blob'=>$val)) != false; |
| 656 | 656 | |
| 657 | - switch(strtoupper($blobtype)) { |
|
| 657 | + switch (strtoupper($blobtype)) { |
|
| 658 | 658 | default: ADOConnection::outp("<b>UpdateBlob</b>: Unknown blobtype=$blobtype"); return false; |
| 659 | 659 | case 'BLOB': $type = OCI_B_BLOB; break; |
| 660 | 660 | case 'CLOB': $type = OCI_B_CLOB; break; |
@@ -666,11 +666,11 @@ discard block |
||
| 666 | 666 | $sql = "UPDATE $table set $column=EMPTY_{$blobtype}() WHERE $where RETURNING $column INTO :blob"; |
| 667 | 667 | |
| 668 | 668 | $desc = OCINewDescriptor($this->_connectionID, OCI_D_LOB); |
| 669 | - $arr['blob'] = array($desc,-1,$type); |
|
| 669 | + $arr['blob'] = array($desc, -1, $type); |
|
| 670 | 670 | if ($this->session_sharing_force_blob) $this->Execute('ALTER SESSION SET CURSOR_SHARING=EXACT'); |
| 671 | 671 | $commit = $this->autoCommit; |
| 672 | 672 | if ($commit) $this->BeginTrans(); |
| 673 | - $rs = $this->Execute($sql,$arr); |
|
| 673 | + $rs = $this->Execute($sql, $arr); |
|
| 674 | 674 | if ($rez = !empty($rs)) $desc->save($val); |
| 675 | 675 | $desc->free(); |
| 676 | 676 | if ($commit) $this->CommitTrans(); |
@@ -683,10 +683,10 @@ discard block |
||
| 683 | 683 | /** |
| 684 | 684 | * Usage: store file pointed to by $var in a blob |
| 685 | 685 | */ |
| 686 | - function UpdateBlobFile($table,$column,$val,$where,$blobtype='BLOB') |
|
| 686 | + function UpdateBlobFile($table, $column, $val, $where, $blobtype = 'BLOB') |
|
| 687 | 687 | { |
| 688 | - switch(strtoupper($blobtype)) { |
|
| 689 | - default: ADOConnection::outp( "<b>UpdateBlob</b>: Unknown blobtype=$blobtype"); return false; |
|
| 688 | + switch (strtoupper($blobtype)) { |
|
| 689 | + default: ADOConnection::outp("<b>UpdateBlob</b>: Unknown blobtype=$blobtype"); return false; |
|
| 690 | 690 | case 'BLOB': $type = OCI_B_BLOB; break; |
| 691 | 691 | case 'CLOB': $type = OCI_B_CLOB; break; |
| 692 | 692 | } |
@@ -697,10 +697,10 @@ discard block |
||
| 697 | 697 | $sql = "UPDATE $table set $column=EMPTY_{$blobtype}() WHERE $where RETURNING $column INTO :blob"; |
| 698 | 698 | |
| 699 | 699 | $desc = OCINewDescriptor($this->_connectionID, OCI_D_LOB); |
| 700 | - $arr['blob'] = array($desc,-1,$type); |
|
| 700 | + $arr['blob'] = array($desc, -1, $type); |
|
| 701 | 701 | |
| 702 | 702 | $this->BeginTrans(); |
| 703 | - $rs = ADODB_oci8::Execute($sql,$arr); |
|
| 703 | + $rs = ADODB_oci8::Execute($sql, $arr); |
|
| 704 | 704 | if ($rez = !empty($rs)) $desc->savefile($val); |
| 705 | 705 | $desc->free(); |
| 706 | 706 | $this->CommitTrans(); |
@@ -716,11 +716,11 @@ discard block |
||
| 716 | 716 | * @param [inputarr] holds the input data to bind to. Null elements will be set to null. |
| 717 | 717 | * @return RecordSet or false |
| 718 | 718 | */ |
| 719 | - function &Execute($sql,$inputarr=false) |
|
| 719 | + function &Execute($sql, $inputarr = false) |
|
| 720 | 720 | { |
| 721 | 721 | if ($this->fnExecute) { |
| 722 | 722 | $fn = $this->fnExecute; |
| 723 | - $ret =& $fn($this,$sql,$inputarr); |
|
| 723 | + $ret = & $fn($this, $sql, $inputarr); |
|
| 724 | 724 | if (isset($ret)) return $ret; |
| 725 | 725 | } |
| 726 | 726 | if ($inputarr) { |
@@ -735,16 +735,16 @@ discard block |
||
| 735 | 735 | else |
| 736 | 736 | $stmt = $sql; |
| 737 | 737 | |
| 738 | - foreach($inputarr as $arr) { |
|
| 739 | - $ret =& $this->_Execute($stmt,$arr); |
|
| 738 | + foreach ($inputarr as $arr) { |
|
| 739 | + $ret = & $this->_Execute($stmt, $arr); |
|
| 740 | 740 | if (!$ret) return $ret; |
| 741 | 741 | } |
| 742 | 742 | } else { |
| 743 | - $ret =& $this->_Execute($sql,$inputarr); |
|
| 743 | + $ret = & $this->_Execute($sql, $inputarr); |
|
| 744 | 744 | } |
| 745 | 745 | |
| 746 | 746 | } else { |
| 747 | - $ret =& $this->_Execute($sql,false); |
|
| 747 | + $ret = & $this->_Execute($sql, false); |
|
| 748 | 748 | } |
| 749 | 749 | |
| 750 | 750 | return $ret; |
@@ -755,11 +755,11 @@ discard block |
||
| 755 | 755 | |
| 756 | 756 | $stmt = $this->Prepare('insert into emp (empno, ename) values (:empno, :ename)'); |
| 757 | 757 | */ |
| 758 | - function Prepare($sql,$cursor=false) |
|
| 758 | + function Prepare($sql, $cursor = false) |
|
| 759 | 759 | { |
| 760 | 760 | static $BINDNUM = 0; |
| 761 | 761 | |
| 762 | - $stmt = OCIParse($this->_connectionID,$sql); |
|
| 762 | + $stmt = OCIParse($this->_connectionID, $sql); |
|
| 763 | 763 | |
| 764 | 764 | if (!$stmt) return false; |
| 765 | 765 | |
@@ -767,9 +767,9 @@ discard block |
||
| 767 | 767 | |
| 768 | 768 | $sttype = @OCIStatementType($stmt); |
| 769 | 769 | if ($sttype == 'BEGIN' || $sttype == 'DECLARE') { |
| 770 | - return array($sql,$stmt,0,$BINDNUM, ($cursor) ? OCINewCursor($this->_connectionID) : false); |
|
| 770 | + return array($sql, $stmt, 0, $BINDNUM, ($cursor) ? OCINewCursor($this->_connectionID) : false); |
|
| 771 | 771 | } |
| 772 | - return array($sql,$stmt,0,$BINDNUM); |
|
| 772 | + return array($sql, $stmt, 0, $BINDNUM); |
|
| 773 | 773 | } |
| 774 | 774 | |
| 775 | 775 | /* |
@@ -786,23 +786,23 @@ discard block |
||
| 786 | 786 | array('VAR1' => 'Mr Bean')); |
| 787 | 787 | |
| 788 | 788 | */ |
| 789 | - function &ExecuteCursor($sql,$cursorName='rs',$params=false) |
|
| 789 | + function &ExecuteCursor($sql, $cursorName = 'rs', $params = false) |
|
| 790 | 790 | { |
| 791 | 791 | if (is_array($sql)) $stmt = $sql; |
| 792 | - else $stmt = ADODB_oci8::Prepare($sql,true); # true to allocate OCINewCursor |
|
| 792 | + else $stmt = ADODB_oci8::Prepare($sql, true); # true to allocate OCINewCursor |
|
| 793 | 793 | |
| 794 | 794 | if (is_array($stmt) && sizeof($stmt) >= 5) { |
| 795 | 795 | $hasref = true; |
| 796 | 796 | $this->Parameter($stmt, $ignoreCur, $cursorName, false, -1, OCI_B_CURSOR); |
| 797 | 797 | if ($params) { |
| 798 | - foreach($params as $k => $v) { |
|
| 799 | - $this->Parameter($stmt,$params[$k], $k); |
|
| 798 | + foreach ($params as $k => $v) { |
|
| 799 | + $this->Parameter($stmt, $params[$k], $k); |
|
| 800 | 800 | } |
| 801 | 801 | } |
| 802 | 802 | } else |
| 803 | 803 | $hasref = false; |
| 804 | 804 | |
| 805 | - $rs =& $this->Execute($stmt); |
|
| 805 | + $rs = & $this->Execute($stmt); |
|
| 806 | 806 | if ($rs->databaseType == 'array') OCIFreeCursor($stmt[4]); |
| 807 | 807 | else if ($hasref) $rs->_refcursor = $stmt[4]; |
| 808 | 808 | return $rs; |
@@ -838,18 +838,18 @@ discard block |
||
| 838 | 838 | Note that the order of parameters differs from OCIBindByName, |
| 839 | 839 | because we default the names to :0, :1, :2 |
| 840 | 840 | */ |
| 841 | - function Bind(&$stmt,&$var,$size=4000,$type=false,$name=false,$isOutput=false) |
|
| 841 | + function Bind(&$stmt, &$var, $size = 4000, $type = false, $name = false, $isOutput = false) |
|
| 842 | 842 | { |
| 843 | 843 | |
| 844 | 844 | if (!is_array($stmt)) return false; |
| 845 | 845 | |
| 846 | 846 | if (($type == OCI_B_CURSOR) && sizeof($stmt) >= 5) { |
| 847 | - return OCIBindByName($stmt[1],":".$name,$stmt[4],$size,$type); |
|
| 847 | + return OCIBindByName($stmt[1], ":".$name, $stmt[4], $size, $type); |
|
| 848 | 848 | } |
| 849 | 849 | |
| 850 | 850 | if ($name == false) { |
| 851 | - if ($type !== false) $rez = OCIBindByName($stmt[1],":".$stmt[2],$var,$size,$type); |
|
| 852 | - else $rez = OCIBindByName($stmt[1],":".$stmt[2],$var,$size); // +1 byte for null terminator |
|
| 851 | + if ($type !== false) $rez = OCIBindByName($stmt[1], ":".$stmt[2], $var, $size, $type); |
|
| 852 | + else $rez = OCIBindByName($stmt[1], ":".$stmt[2], $var, $size); // +1 byte for null terminator |
|
| 853 | 853 | $stmt[2] += 1; |
| 854 | 854 | } else if (oci_lob_desc($type)) { |
| 855 | 855 | if ($this->debug) { |
@@ -882,14 +882,14 @@ discard block |
||
| 882 | 882 | if ($this->debug) |
| 883 | 883 | ADOConnection::outp("<b>Bind</b>: name = $name"); |
| 884 | 884 | |
| 885 | - if ($type !== false) $rez = OCIBindByName($stmt[1],":".$name,$var,$size,$type); |
|
| 886 | - else $rez = OCIBindByName($stmt[1],":".$name,$var,$size); // +1 byte for null terminator |
|
| 885 | + if ($type !== false) $rez = OCIBindByName($stmt[1], ":".$name, $var, $size, $type); |
|
| 886 | + else $rez = OCIBindByName($stmt[1], ":".$name, $var, $size); // +1 byte for null terminator |
|
| 887 | 887 | } |
| 888 | 888 | |
| 889 | 889 | return $rez; |
| 890 | 890 | } |
| 891 | 891 | |
| 892 | - function Param($name,$type=false) |
|
| 892 | + function Param($name, $type = false) |
|
| 893 | 893 | { |
| 894 | 894 | return ':'.$name; |
| 895 | 895 | } |
@@ -910,14 +910,14 @@ discard block |
||
| 910 | 910 | |
| 911 | 911 | See OCIBindByName documentation at php.net. |
| 912 | 912 | */ |
| 913 | - function Parameter(&$stmt,&$var,$name,$isOutput=false,$maxLen=4000,$type=false) |
|
| 913 | + function Parameter(&$stmt, &$var, $name, $isOutput = false, $maxLen = 4000, $type = false) |
|
| 914 | 914 | { |
| 915 | - if ($this->debug) { |
|
| 915 | + if ($this->debug) { |
|
| 916 | 916 | $prefix = ($isOutput) ? 'Out' : 'In'; |
| 917 | 917 | $ztype = (empty($type)) ? 'false' : $type; |
| 918 | - ADOConnection::outp( "{$prefix}Parameter(\$stmt, \$php_var='$var', \$name='$name', \$maxLen=$maxLen, \$type=$ztype);"); |
|
| 918 | + ADOConnection::outp("{$prefix}Parameter(\$stmt, \$php_var='$var', \$name='$name', \$maxLen=$maxLen, \$type=$ztype);"); |
|
| 919 | 919 | } |
| 920 | - return $this->Bind($stmt,$var,$maxLen,$type,$name,$isOutput); |
|
| 920 | + return $this->Bind($stmt, $var, $maxLen, $type, $name, $isOutput); |
|
| 921 | 921 | } |
| 922 | 922 | |
| 923 | 923 | /* |
@@ -935,7 +935,7 @@ discard block |
||
| 935 | 935 | $db->bind($stmt,1); $db->bind($stmt,2); $db->bind($stmt,3); |
| 936 | 936 | $db->execute($stmt); |
| 937 | 937 | */ |
| 938 | - function _query($sql,$inputarr) |
|
| 938 | + function _query($sql, $inputarr) |
|
| 939 | 939 | { |
| 940 | 940 | if (is_array($sql)) { // is prepared sql |
| 941 | 941 | $stmt = $sql[1]; |
@@ -950,38 +950,38 @@ discard block |
||
| 950 | 950 | } else { |
| 951 | 951 | // one statement to bind them all |
| 952 | 952 | $bindarr = array(); |
| 953 | - foreach($inputarr as $k => $v) { |
|
| 953 | + foreach ($inputarr as $k => $v) { |
|
| 954 | 954 | $bindarr[$k] = $v; |
| 955 | - OCIBindByName($stmt,":$k",$bindarr[$k],is_string($v) && strlen($v)>4000 ? -1 : 4000); |
|
| 955 | + OCIBindByName($stmt, ":$k", $bindarr[$k], is_string($v) && strlen($v) > 4000 ? -1 : 4000); |
|
| 956 | 956 | } |
| 957 | 957 | $this->_bind[$bindpos] = &$bindarr; |
| 958 | 958 | } |
| 959 | 959 | } |
| 960 | 960 | } else { |
| 961 | - $stmt=OCIParse($this->_connectionID,$sql); |
|
| 961 | + $stmt = OCIParse($this->_connectionID, $sql); |
|
| 962 | 962 | } |
| 963 | 963 | |
| 964 | 964 | $this->_stmt = $stmt; |
| 965 | 965 | if (!$stmt) return false; |
| 966 | 966 | |
| 967 | - if (defined('ADODB_PREFETCH_ROWS')) @OCISetPrefetch($stmt,ADODB_PREFETCH_ROWS); |
|
| 967 | + if (defined('ADODB_PREFETCH_ROWS')) @OCISetPrefetch($stmt, ADODB_PREFETCH_ROWS); |
|
| 968 | 968 | |
| 969 | 969 | if (is_array($inputarr)) { |
| 970 | - foreach($inputarr as $k => $v) { |
|
| 970 | + foreach ($inputarr as $k => $v) { |
|
| 971 | 971 | if (is_array($v)) { |
| 972 | 972 | if (sizeof($v) == 2) // suggested by g.giunta@libero. |
| 973 | - OCIBindByName($stmt,":$k",$inputarr[$k][0],$v[1]); |
|
| 973 | + OCIBindByName($stmt, ":$k", $inputarr[$k][0], $v[1]); |
|
| 974 | 974 | else |
| 975 | - OCIBindByName($stmt,":$k",$inputarr[$k][0],$v[1],$v[2]); |
|
| 975 | + OCIBindByName($stmt, ":$k", $inputarr[$k][0], $v[1], $v[2]); |
|
| 976 | 976 | |
| 977 | - if ($this->debug==99) echo "name=:$k",' var='.$inputarr[$k][0],' len='.$v[1],' type='.$v[2],'<br>'; |
|
| 977 | + if ($this->debug == 99) echo "name=:$k", ' var='.$inputarr[$k][0], ' len='.$v[1], ' type='.$v[2], '<br>'; |
|
| 978 | 978 | } else { |
| 979 | 979 | $len = -1; |
| 980 | 980 | if ($v === ' ') $len = 1; |
| 981 | 981 | if (isset($bindarr)) { // is prepared sql, so no need to ocibindbyname again |
| 982 | 982 | $bindarr[$k] = $v; |
| 983 | 983 | } else { // dynamic sql, so rebind every time |
| 984 | - OCIBindByName($stmt,":$k",$inputarr[$k],$len); |
|
| 984 | + OCIBindByName($stmt, ":$k", $inputarr[$k], $len); |
|
| 985 | 985 | } |
| 986 | 986 | } |
| 987 | 987 | } |
@@ -989,7 +989,7 @@ discard block |
||
| 989 | 989 | |
| 990 | 990 | $this->_errorMsg = false; |
| 991 | 991 | $this->_errorCode = false; |
| 992 | - if (OCIExecute($stmt,$this->_commit)) { |
|
| 992 | + if (OCIExecute($stmt, $this->_commit)) { |
|
| 993 | 993 | //OCIInternalDebug(1); |
| 994 | 994 | if (count($this -> _refLOBs) > 0) { |
| 995 | 995 | |
@@ -1059,7 +1059,7 @@ discard block |
||
| 1059 | 1059 | $this->_connectionID = false; |
| 1060 | 1060 | } |
| 1061 | 1061 | |
| 1062 | - function MetaPrimaryKeys($table, $owner=false,$internalKey=false) |
|
| 1062 | + function MetaPrimaryKeys($table, $owner = false, $internalKey = false) |
|
| 1063 | 1063 | { |
| 1064 | 1064 | if ($internalKey) return array('ROWID'); |
| 1065 | 1065 | |
@@ -1083,9 +1083,9 @@ discard block |
||
| 1083 | 1083 | |
| 1084 | 1084 | $rs = $this->Execute($sql); |
| 1085 | 1085 | if ($rs && !$rs->EOF) { |
| 1086 | - $arr =& $rs->GetArray(); |
|
| 1086 | + $arr = & $rs->GetArray(); |
|
| 1087 | 1087 | $a = array(); |
| 1088 | - foreach($arr as $v) { |
|
| 1088 | + foreach ($arr as $v) { |
|
| 1089 | 1089 | $a[] = reset($v); |
| 1090 | 1090 | } |
| 1091 | 1091 | return $a; |
@@ -1094,7 +1094,7 @@ discard block |
||
| 1094 | 1094 | } |
| 1095 | 1095 | |
| 1096 | 1096 | // http://gis.mit.edu/classes/11.521/sqlnotes/referential_integrity.html |
| 1097 | - function MetaForeignKeys($table, $owner=false) |
|
| 1097 | + function MetaForeignKeys($table, $owner = false) |
|
| 1098 | 1098 | { |
| 1099 | 1099 | global $ADODB_FETCH_MODE; |
| 1100 | 1100 | |
@@ -1114,9 +1114,9 @@ discard block |
||
| 1114 | 1114 | from {$tabp}constraints |
| 1115 | 1115 | where constraint_type = 'R' and table_name = $table $owner"; |
| 1116 | 1116 | |
| 1117 | - $constraints =& $this->GetArray($sql); |
|
| 1117 | + $constraints = & $this->GetArray($sql); |
|
| 1118 | 1118 | $arr = false; |
| 1119 | - foreach($constraints as $constr) { |
|
| 1119 | + foreach ($constraints as $constr) { |
|
| 1120 | 1120 | $cons = $this->qstr($constr[0]); |
| 1121 | 1121 | $rowner = $this->qstr($constr[1]); |
| 1122 | 1122 | $rcons = $this->qstr($constr[2]); |
@@ -1124,7 +1124,7 @@ discard block |
||
| 1124 | 1124 | $tabcol = $this->GetArray("select table_name,column_name from {$tabp}cons_columns where owner=$rowner and constraint_name=$rcons order by position"); |
| 1125 | 1125 | |
| 1126 | 1126 | if ($cols && $tabcol) |
| 1127 | - for ($i=0, $max=sizeof($cols); $i < $max; $i++) { |
|
| 1127 | + for ($i = 0, $max = sizeof($cols); $i < $max; $i++) { |
|
| 1128 | 1128 | $arr[$tabcol[$i][0]] = $cols[$i][0].'='.$tabcol[$i][1]; |
| 1129 | 1129 | } |
| 1130 | 1130 | } |
@@ -1154,23 +1154,23 @@ discard block |
||
| 1154 | 1154 | * |
| 1155 | 1155 | * @return quoted string to be sent back to database |
| 1156 | 1156 | */ |
| 1157 | - function qstr($s,$magic_quotes=false) |
|
| 1157 | + function qstr($s, $magic_quotes = false) |
|
| 1158 | 1158 | { |
| 1159 | - $nofixquotes=false; |
|
| 1159 | + $nofixquotes = false; |
|
| 1160 | 1160 | |
| 1161 | - if ($this->noNullStrings && strlen($s)==0)$s = ' '; |
|
| 1161 | + if ($this->noNullStrings && strlen($s) == 0)$s = ' '; |
|
| 1162 | 1162 | if (!$magic_quotes) { |
| 1163 | - if ($this->replaceQuote[0] == '\\'){ |
|
| 1164 | - $s = str_replace('\\','\\\\',$s); |
|
| 1163 | + if ($this->replaceQuote[0] == '\\') { |
|
| 1164 | + $s = str_replace('\\', '\\\\', $s); |
|
| 1165 | 1165 | } |
| 1166 | - return "'".str_replace("'",$this->replaceQuote,$s)."'"; |
|
| 1166 | + return "'".str_replace("'", $this->replaceQuote, $s)."'"; |
|
| 1167 | 1167 | } |
| 1168 | 1168 | |
| 1169 | 1169 | // undo magic quotes for " |
| 1170 | - $s = str_replace('\\"','"',$s); |
|
| 1170 | + $s = str_replace('\\"', '"', $s); |
|
| 1171 | 1171 | |
| 1172 | - $s = str_replace('\\\\','\\',$s); |
|
| 1173 | - return "'".str_replace("\\'",$this->replaceQuote,$s)."'"; |
|
| 1172 | + $s = str_replace('\\\\', '\\', $s); |
|
| 1173 | + return "'".str_replace("\\'", $this->replaceQuote, $s)."'"; |
|
| 1174 | 1174 | |
| 1175 | 1175 | } |
| 1176 | 1176 | |
@@ -1183,12 +1183,12 @@ discard block |
||
| 1183 | 1183 | class ADORecordset_oci8 extends ADORecordSet { |
| 1184 | 1184 | |
| 1185 | 1185 | var $databaseType = 'oci8'; |
| 1186 | - var $bind=false; |
|
| 1186 | + var $bind = false; |
|
| 1187 | 1187 | var $_fieldobjs; |
| 1188 | 1188 | |
| 1189 | 1189 | //var $_arr = false; |
| 1190 | 1190 | |
| 1191 | - function ADORecordset_oci8($queryID,$mode=false) |
|
| 1191 | + function ADORecordset_oci8($queryID, $mode = false) |
|
| 1192 | 1192 | { |
| 1193 | 1193 | if ($mode === false) { |
| 1194 | 1194 | global $ADODB_FETCH_MODE; |
@@ -1196,12 +1196,12 @@ discard block |
||
| 1196 | 1196 | } |
| 1197 | 1197 | switch ($mode) |
| 1198 | 1198 | { |
| 1199 | - case ADODB_FETCH_ASSOC:$this->fetchMode = OCI_ASSOC+OCI_RETURN_NULLS+OCI_RETURN_LOBS; break; |
|
| 1199 | + case ADODB_FETCH_ASSOC:$this->fetchMode = OCI_ASSOC + OCI_RETURN_NULLS + OCI_RETURN_LOBS; break; |
|
| 1200 | 1200 | case ADODB_FETCH_DEFAULT: |
| 1201 | - case ADODB_FETCH_BOTH:$this->fetchMode = OCI_NUM+OCI_ASSOC+OCI_RETURN_NULLS+OCI_RETURN_LOBS; break; |
|
| 1201 | + case ADODB_FETCH_BOTH:$this->fetchMode = OCI_NUM + OCI_ASSOC + OCI_RETURN_NULLS + OCI_RETURN_LOBS; break; |
|
| 1202 | 1202 | case ADODB_FETCH_NUM: |
| 1203 | 1203 | default: |
| 1204 | - $this->fetchMode = OCI_NUM+OCI_RETURN_NULLS+OCI_RETURN_LOBS; break; |
|
| 1204 | + $this->fetchMode = OCI_NUM + OCI_RETURN_NULLS + OCI_RETURN_LOBS; break; |
|
| 1205 | 1205 | } |
| 1206 | 1206 | |
| 1207 | 1207 | $this->adodbFetchMode = $mode; |
@@ -1243,10 +1243,10 @@ discard block |
||
| 1243 | 1243 | { |
| 1244 | 1244 | $this->_numOfRows = -1; |
| 1245 | 1245 | $this->_numOfFields = OCInumcols($this->_queryID); |
| 1246 | - if ($this->_numOfFields>0) { |
|
| 1246 | + if ($this->_numOfFields > 0) { |
|
| 1247 | 1247 | $this->_fieldobjs = array(); |
| 1248 | 1248 | $max = $this->_numOfFields; |
| 1249 | - for ($i=0;$i<$max; $i++) $this->_fieldobjs[] = $this->_FetchField($i); |
|
| 1249 | + for ($i = 0; $i < $max; $i++) $this->_fieldobjs[] = $this->_FetchField($i); |
|
| 1250 | 1250 | } |
| 1251 | 1251 | } |
| 1252 | 1252 | |
@@ -1259,7 +1259,7 @@ discard block |
||
| 1259 | 1259 | { |
| 1260 | 1260 | $fld = new ADOFieldObject; |
| 1261 | 1261 | $fieldOffset += 1; |
| 1262 | - $fld->name =OCIcolumnname($this->_queryID, $fieldOffset); |
|
| 1262 | + $fld->name = OCIcolumnname($this->_queryID, $fieldOffset); |
|
| 1263 | 1263 | $fld->type = OCIcolumntype($this->_queryID, $fieldOffset); |
| 1264 | 1264 | $fld->max_length = OCIcolumnsize($this->_queryID, $fieldOffset); |
| 1265 | 1265 | if ($fld->type == 'NUMBER') { |
@@ -1297,7 +1297,7 @@ discard block |
||
| 1297 | 1297 | |
| 1298 | 1298 | function MoveNext() |
| 1299 | 1299 | { |
| 1300 | - if (@OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode)) { |
|
| 1300 | + if (@OCIfetchinto($this->_queryID, $this->fields, $this->fetchMode)) { |
|
| 1301 | 1301 | $this->_currentRow += 1; |
| 1302 | 1302 | return true; |
| 1303 | 1303 | } |
@@ -1343,16 +1343,16 @@ discard block |
||
| 1343 | 1343 | } */ |
| 1344 | 1344 | |
| 1345 | 1345 | /* Optimize SelectLimit() by using OCIFetch() instead of OCIFetchInto() */ |
| 1346 | - function &GetArrayLimit($nrows,$offset=-1) |
|
| 1346 | + function &GetArrayLimit($nrows, $offset = -1) |
|
| 1347 | 1347 | { |
| 1348 | 1348 | if ($offset <= 0) { |
| 1349 | - $arr =& $this->GetArray($nrows); |
|
| 1349 | + $arr = & $this->GetArray($nrows); |
|
| 1350 | 1350 | return $arr; |
| 1351 | 1351 | } |
| 1352 | - for ($i=1; $i < $offset; $i++) |
|
| 1352 | + for ($i = 1; $i < $offset; $i++) |
|
| 1353 | 1353 | if (!@OCIFetch($this->_queryID)) return array(); |
| 1354 | 1354 | |
| 1355 | - if (!@OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode)) return array(); |
|
| 1355 | + if (!@OCIfetchinto($this->_queryID, $this->fields, $this->fetchMode)) return array(); |
|
| 1356 | 1356 | $results = array(); |
| 1357 | 1357 | $cnt = 0; |
| 1358 | 1358 | while (!$this->EOF && $nrows != $cnt) { |
@@ -1369,7 +1369,7 @@ discard block |
||
| 1369 | 1369 | { |
| 1370 | 1370 | if (!$this->bind) { |
| 1371 | 1371 | $this->bind = array(); |
| 1372 | - for ($i=0; $i < $this->_numOfFields; $i++) { |
|
| 1372 | + for ($i = 0; $i < $this->_numOfFields; $i++) { |
|
| 1373 | 1373 | $o = $this->FetchField($i); |
| 1374 | 1374 | $this->bind[strtoupper($o->name)] = $i; |
| 1375 | 1375 | } |
@@ -1387,7 +1387,7 @@ discard block |
||
| 1387 | 1387 | |
| 1388 | 1388 | function _fetch() |
| 1389 | 1389 | { |
| 1390 | - return @OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode); |
|
| 1390 | + return @OCIfetchinto($this->_queryID, $this->fields, $this->fetchMode); |
|
| 1391 | 1391 | } |
| 1392 | 1392 | |
| 1393 | 1393 | /* close() only needs to be called if you are worried about using too much memory while your script |
@@ -1405,7 +1405,7 @@ discard block |
||
| 1405 | 1405 | |
| 1406 | 1406 | } |
| 1407 | 1407 | |
| 1408 | - function MetaType($t,$len=-1) |
|
| 1408 | + function MetaType($t, $len = -1) |
|
| 1409 | 1409 | { |
| 1410 | 1410 | if (is_object($t)) { |
| 1411 | 1411 | $fieldobj = $t; |
@@ -1451,7 +1451,7 @@ discard block |
||
| 1451 | 1451 | } |
| 1452 | 1452 | |
| 1453 | 1453 | class ADORecordSet_ext_oci8 extends ADORecordSet_oci8 { |
| 1454 | - function ADORecordSet_ext_oci8($queryID,$mode=false) |
|
| 1454 | + function ADORecordSet_ext_oci8($queryID, $mode = false) |
|
| 1455 | 1455 | { |
| 1456 | 1456 | if ($mode === false) { |
| 1457 | 1457 | global $ADODB_FETCH_MODE; |
@@ -1459,11 +1459,11 @@ discard block |
||
| 1459 | 1459 | } |
| 1460 | 1460 | switch ($mode) |
| 1461 | 1461 | { |
| 1462 | - case ADODB_FETCH_ASSOC:$this->fetchMode = OCI_ASSOC+OCI_RETURN_NULLS+OCI_RETURN_LOBS; break; |
|
| 1462 | + case ADODB_FETCH_ASSOC:$this->fetchMode = OCI_ASSOC + OCI_RETURN_NULLS + OCI_RETURN_LOBS; break; |
|
| 1463 | 1463 | case ADODB_FETCH_DEFAULT: |
| 1464 | - case ADODB_FETCH_BOTH:$this->fetchMode = OCI_NUM+OCI_ASSOC+OCI_RETURN_NULLS+OCI_RETURN_LOBS; break; |
|
| 1464 | + case ADODB_FETCH_BOTH:$this->fetchMode = OCI_NUM + OCI_ASSOC + OCI_RETURN_NULLS + OCI_RETURN_LOBS; break; |
|
| 1465 | 1465 | case ADODB_FETCH_NUM: |
| 1466 | - default: $this->fetchMode = OCI_NUM+OCI_RETURN_NULLS+OCI_RETURN_LOBS; break; |
|
| 1466 | + default: $this->fetchMode = OCI_NUM + OCI_RETURN_NULLS + OCI_RETURN_LOBS; break; |
|
| 1467 | 1467 | } |
| 1468 | 1468 | $this->adodbFetchMode = $mode; |
| 1469 | 1469 | $this->_queryID = $queryID; |
@@ -15,7 +15,10 @@ discard block |
||
| 15 | 15 | */ |
| 16 | 16 | |
| 17 | 17 | // security - hide paths |
| 18 | -if (!defined('ADODB_DIR')) die(); |
|
| 18 | +if (!defined('ADODB_DIR')) |
|
| 19 | +{ |
|
| 20 | + die(); |
|
| 21 | +} |
|
| 19 | 22 | |
| 20 | 23 | /* |
| 21 | 24 | NLS_Date_Format |
@@ -40,8 +43,10 @@ discard block |
||
| 40 | 43 | |
| 41 | 44 | # define the LOB descriptor type for the given type |
| 42 | 45 | # returns false if no LOB descriptor |
| 43 | -function oci_lob_desc($type) { |
|
| 44 | - switch ($type) { |
|
| 46 | +function oci_lob_desc($type) |
|
| 47 | +{ |
|
| 48 | + switch ($type) |
|
| 49 | + { |
|
| 45 | 50 | case OCI_B_BFILE: $result = OCI_D_FILE; break; |
| 46 | 51 | case OCI_B_CFILEE: $result = OCI_D_FILE; break; |
| 47 | 52 | case OCI_B_CLOB: $result = OCI_D_LOB; break; |
@@ -52,7 +57,8 @@ discard block |
||
| 52 | 57 | return $result; |
| 53 | 58 | } |
| 54 | 59 | |
| 55 | -class ADODB_oci8 extends ADOConnection { |
|
| 60 | +class ADODB_oci8 extends ADOConnection |
|
| 61 | +{ |
|
| 56 | 62 | var $databaseType = 'oci8'; |
| 57 | 63 | var $dataProvider = 'oci8'; |
| 58 | 64 | var $replaceQuote = "''"; // string to use to replace quotes |
@@ -88,10 +94,13 @@ discard block |
||
| 88 | 94 | |
| 89 | 95 | // var $ansiOuter = true; // if oracle9 |
| 90 | 96 | |
| 91 | - function ADODB_oci8() |
|
| 97 | + function ADODB_oci8() |
|
| 92 | 98 | { |
| 93 | 99 | $this->_hasOCIFetchStatement = ADODB_PHPVER >= 0x4200; |
| 94 | - if (defined('ADODB_EXTENSION')) $this->rsPrefix .= 'ext_'; |
|
| 100 | + if (defined('ADODB_EXTENSION')) |
|
| 101 | + { |
|
| 102 | + $this->rsPrefix .= 'ext_'; |
|
| 103 | + } |
|
| 95 | 104 | } |
| 96 | 105 | |
| 97 | 106 | /* Function &MetaColumns($table) added by [email protected]*/ |
@@ -102,23 +111,33 @@ discard block |
||
| 102 | 111 | $false = false; |
| 103 | 112 | $save = $ADODB_FETCH_MODE; |
| 104 | 113 | $ADODB_FETCH_MODE = ADODB_FETCH_NUM; |
| 105 | - if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false); |
|
| 114 | + if ($this->fetchMode !== false) |
|
| 115 | + { |
|
| 116 | + $savem = $this->SetFetchMode(false); |
|
| 117 | + } |
|
| 106 | 118 | |
| 107 | 119 | $rs = $this->Execute(sprintf($this->metaColumnsSQL,strtoupper($table))); |
| 108 | 120 | |
| 109 | - if (isset($savem)) $this->SetFetchMode($savem); |
|
| 121 | + if (isset($savem)) |
|
| 122 | + { |
|
| 123 | + $this->SetFetchMode($savem); |
|
| 124 | + } |
|
| 110 | 125 | $ADODB_FETCH_MODE = $save; |
| 111 | - if (!$rs) { |
|
| 126 | + if (!$rs) |
|
| 127 | + { |
|
| 112 | 128 | return $false; |
| 113 | 129 | } |
| 114 | 130 | $retarr = array(); |
| 115 | - while (!$rs->EOF) { //print_r($rs->fields); |
|
| 131 | + while (!$rs->EOF) |
|
| 132 | + { |
|
| 133 | +//print_r($rs->fields); |
|
| 116 | 134 | $fld = new ADOFieldObject(); |
| 117 | 135 | $fld->name = $rs->fields[0]; |
| 118 | 136 | $fld->type = $rs->fields[1]; |
| 119 | 137 | $fld->max_length = $rs->fields[2]; |
| 120 | 138 | $fld->scale = $rs->fields[3]; |
| 121 | - if ($rs->fields[1] == 'NUMBER' && $rs->fields[3] == 0) { |
|
| 139 | + if ($rs->fields[1] == 'NUMBER' && $rs->fields[3] == 0) |
|
| 140 | + { |
|
| 122 | 141 | $fld->type ='INT'; |
| 123 | 142 | $fld->max_length = $rs->fields[4]; |
| 124 | 143 | } |
@@ -126,21 +145,32 @@ discard block |
||
| 126 | 145 | $fld->binary = (strpos($fld->type,'BLOB') !== false); |
| 127 | 146 | $fld->default_value = $rs->fields[6]; |
| 128 | 147 | |
| 129 | - if ($ADODB_FETCH_MODE == ADODB_FETCH_NUM) $retarr[] = $fld; |
|
| 130 | - else $retarr[strtoupper($fld->name)] = $fld; |
|
| 148 | + if ($ADODB_FETCH_MODE == ADODB_FETCH_NUM) |
|
| 149 | + { |
|
| 150 | + $retarr[] = $fld; |
|
| 151 | + } |
|
| 152 | + else { |
|
| 153 | + $retarr[strtoupper($fld->name)] = $fld; |
|
| 154 | + } |
|
| 131 | 155 | $rs->MoveNext(); |
| 132 | 156 | } |
| 133 | 157 | $rs->Close(); |
| 134 | 158 | if (empty($retarr)) |
| 135 | - return $false; |
|
| 136 | - else |
|
| 137 | - return $retarr; |
|
| 159 | + { |
|
| 160 | + return $false; |
|
| 161 | + } |
|
| 162 | + else { |
|
| 163 | + return $retarr; |
|
| 164 | + } |
|
| 138 | 165 | } |
| 139 | 166 | |
| 140 | 167 | function Time() |
| 141 | 168 | { |
| 142 | 169 | $rs =& $this->Execute("select TO_CHAR($this->sysTimeStamp,'YYYY-MM-DD HH24:MI:SS') from dual"); |
| 143 | - if ($rs && !$rs->EOF) return $this->UnixTimeStamp(reset($rs->fields)); |
|
| 170 | + if ($rs && !$rs->EOF) |
|
| 171 | + { |
|
| 172 | + return $this->UnixTimeStamp(reset($rs->fields)); |
|
| 173 | + } |
|
| 144 | 174 | |
| 145 | 175 | return false; |
| 146 | 176 | } |
@@ -181,54 +211,81 @@ discard block |
||
| 181 | 211 | */ |
| 182 | 212 | function _connect($argHostname, $argUsername, $argPassword, $argDatabasename,$mode=0) |
| 183 | 213 | { |
| 184 | - if (!function_exists('OCIPLogon')) return null; |
|
| 214 | + if (!function_exists('OCIPLogon')) |
|
| 215 | + { |
|
| 216 | + return null; |
|
| 217 | + } |
|
| 185 | 218 | |
| 186 | 219 | |
| 187 | 220 | $this->_errorMsg = false; |
| 188 | 221 | $this->_errorCode = false; |
| 189 | 222 | |
| 190 | - if($argHostname) { // added by Jorma Tuomainen <[email protected]> |
|
| 191 | - if (empty($argDatabasename)) $argDatabasename = $argHostname; |
|
| 192 | - else { |
|
| 193 | - if(strpos($argHostname,":")) { |
|
| 223 | + if($argHostname) |
|
| 224 | + { |
|
| 225 | +// added by Jorma Tuomainen <[email protected]> |
|
| 226 | + if (empty($argDatabasename)) |
|
| 227 | + { |
|
| 228 | + $argDatabasename = $argHostname; |
|
| 229 | + } |
|
| 230 | + else |
|
| 231 | + { |
|
| 232 | + if(strpos($argHostname,":")) |
|
| 233 | + { |
|
| 194 | 234 | $argHostinfo=explode(":",$argHostname); |
| 195 | 235 | $argHostname=$argHostinfo[0]; |
| 196 | 236 | $argHostport=$argHostinfo[1]; |
| 197 | - } else { |
|
| 237 | + } |
|
| 238 | + else |
|
| 239 | + { |
|
| 198 | 240 | $argHostport="1521"; |
| 199 | 241 | } |
| 200 | 242 | |
| 201 | - if ($this->connectSID) { |
|
| 243 | + if ($this->connectSID) |
|
| 244 | + { |
|
| 202 | 245 | $argDatabasename="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=".$argHostname |
| 203 | 246 | .")(PORT=$argHostport))(CONNECT_DATA=(SID=$argDatabasename)))"; |
| 204 | - } else |
|
| 205 | - $argDatabasename="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=".$argHostname |
|
| 247 | + } |
|
| 248 | + else { |
|
| 249 | + $argDatabasename="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=".$argHostname |
|
| 206 | 250 | .")(PORT=$argHostport))(CONNECT_DATA=(SERVICE_NAME=$argDatabasename)))"; |
| 251 | + } |
|
| 207 | 252 | } |
| 208 | 253 | } |
| 209 | 254 | |
| 210 | 255 | //if ($argHostname) print "<p>Connect: 1st argument should be left blank for $this->databaseType</p>"; |
| 211 | - if ($mode==1) { |
|
| 256 | + if ($mode==1) |
|
| 257 | + { |
|
| 212 | 258 | $this->_connectionID = ($this->charSet) ? |
| 213 | 259 | OCIPLogon($argUsername,$argPassword, $argDatabasename) |
| 214 | 260 | : |
| 215 | 261 | OCIPLogon($argUsername,$argPassword, $argDatabasename, $this->charSet) |
| 216 | 262 | ; |
| 217 | - if ($this->_connectionID && $this->autoRollback) OCIrollback($this->_connectionID); |
|
| 218 | - } else if ($mode==2) { |
|
| 263 | + if ($this->_connectionID && $this->autoRollback) |
|
| 264 | + { |
|
| 265 | + OCIrollback($this->_connectionID); |
|
| 266 | + } |
|
| 267 | + } |
|
| 268 | + else if ($mode==2) |
|
| 269 | + { |
|
| 219 | 270 | $this->_connectionID = ($this->charSet) ? |
| 220 | 271 | OCINLogon($argUsername,$argPassword, $argDatabasename) |
| 221 | 272 | : |
| 222 | 273 | OCINLogon($argUsername,$argPassword, $argDatabasename, $this->charSet); |
| 223 | 274 | |
| 224 | - } else { |
|
| 275 | + } |
|
| 276 | + else |
|
| 277 | + { |
|
| 225 | 278 | $this->_connectionID = ($this->charSet) ? |
| 226 | 279 | OCILogon($argUsername,$argPassword, $argDatabasename) |
| 227 | 280 | : |
| 228 | 281 | OCILogon($argUsername,$argPassword, $argDatabasename,$this->charSet); |
| 229 | 282 | } |
| 230 | - if (!$this->_connectionID) return false; |
|
| 231 | - if ($this->_initdate) { |
|
| 283 | + if (!$this->_connectionID) |
|
| 284 | + { |
|
| 285 | + return false; |
|
| 286 | + } |
|
| 287 | + if ($this->_initdate) |
|
| 288 | + { |
|
| 232 | 289 | $this->Execute("ALTER SESSION SET NLS_DATE_FORMAT='".$this->NLS_DATE_FORMAT."'"); |
| 233 | 290 | } |
| 234 | 291 | |
@@ -260,11 +317,14 @@ discard block |
||
| 260 | 317 | |
| 261 | 318 | function _affectedrows() |
| 262 | 319 | { |
| 263 | - if (is_resource($this->_stmt)) return @OCIRowCount($this->_stmt); |
|
| 320 | + if (is_resource($this->_stmt)) |
|
| 321 | + { |
|
| 322 | + return @OCIRowCount($this->_stmt); |
|
| 323 | + } |
|
| 264 | 324 | return 0; |
| 265 | 325 | } |
| 266 | 326 | |
| 267 | - function IfNull( $field, $ifNull ) |
|
| 327 | + function IfNull( $field, $ifNull ) |
|
| 268 | 328 | { |
| 269 | 329 | return " NVL($field, $ifNull) "; // if Oracle |
| 270 | 330 | } |
@@ -272,9 +332,15 @@ discard block |
||
| 272 | 332 | // format and return date string in database date format |
| 273 | 333 | function DBDate($d) |
| 274 | 334 | { |
| 275 | - if (empty($d) && $d !== 0) return 'null'; |
|
| 335 | + if (empty($d) && $d !== 0) |
|
| 336 | + { |
|
| 337 | + return 'null'; |
|
| 338 | + } |
|
| 276 | 339 | |
| 277 | - if (is_string($d)) $d = ADORecordSet::UnixDate($d); |
|
| 340 | + if (is_string($d)) |
|
| 341 | + { |
|
| 342 | + $d = ADORecordSet::UnixDate($d); |
|
| 343 | + } |
|
| 278 | 344 | return "TO_DATE(".adodb_date($this->fmtDate,$d).",'".$this->NLS_DATE_FORMAT."')"; |
| 279 | 345 | } |
| 280 | 346 | |
@@ -282,27 +348,38 @@ discard block |
||
| 282 | 348 | // format and return date string in database timestamp format |
| 283 | 349 | function DBTimeStamp($ts) |
| 284 | 350 | { |
| 285 | - if (empty($ts) && $ts !== 0) return 'null'; |
|
| 286 | - if (is_string($ts)) $ts = ADORecordSet::UnixTimeStamp($ts); |
|
| 351 | + if (empty($ts) && $ts !== 0) |
|
| 352 | + { |
|
| 353 | + return 'null'; |
|
| 354 | + } |
|
| 355 | + if (is_string($ts)) |
|
| 356 | + { |
|
| 357 | + $ts = ADORecordSet::UnixTimeStamp($ts); |
|
| 358 | + } |
|
| 287 | 359 | return 'TO_DATE('.adodb_date($this->fmtTimeStamp,$ts).",'RRRR-MM-DD, HH:MI:SS AM')"; |
| 288 | 360 | } |
| 289 | 361 | |
| 290 | - function RowLock($tables,$where,$flds='1 as ignore') |
|
| 362 | + function RowLock($tables,$where,$flds='1 as ignore') |
|
| 291 | 363 | { |
| 292 | - if ($this->autoCommit) $this->BeginTrans(); |
|
| 364 | + if ($this->autoCommit) |
|
| 365 | + { |
|
| 366 | + $this->BeginTrans(); |
|
| 367 | + } |
|
| 293 | 368 | return $this->GetOne("select $flds from $tables where $where for update"); |
| 294 | 369 | } |
| 295 | 370 | |
| 296 | 371 | function &MetaTables($ttype=false,$showSchema=false,$mask=false) |
| 297 | 372 | { |
| 298 | - if ($mask) { |
|
| 373 | + if ($mask) |
|
| 374 | + { |
|
| 299 | 375 | $save = $this->metaTablesSQL; |
| 300 | 376 | $mask = $this->qstr(strtoupper($mask)); |
| 301 | 377 | $this->metaTablesSQL .= " AND table_name like $mask"; |
| 302 | 378 | } |
| 303 | 379 | $ret =& ADOConnection::MetaTables($ttype,$showSchema); |
| 304 | 380 | |
| 305 | - if ($mask) { |
|
| 381 | + if ($mask) |
|
| 382 | + { |
|
| 306 | 383 | $this->metaTablesSQL = $save; |
| 307 | 384 | } |
| 308 | 385 | return $ret; |
@@ -317,7 +394,8 @@ discard block |
||
| 317 | 394 | $save = $ADODB_FETCH_MODE; |
| 318 | 395 | $ADODB_FETCH_MODE = ADODB_FETCH_NUM; |
| 319 | 396 | |
| 320 | - if ($this->fetchMode !== FALSE) { |
|
| 397 | + if ($this->fetchMode !== FALSE) |
|
| 398 | + { |
|
| 321 | 399 | $savem = $this->SetFetchMode(FALSE); |
| 322 | 400 | } |
| 323 | 401 | |
@@ -330,11 +408,17 @@ discard block |
||
| 330 | 408 | $false = false; |
| 331 | 409 | $rs = $this->Execute(sprintf("SELECT * FROM ALL_CONSTRAINTS WHERE UPPER(TABLE_NAME)='%s' AND CONSTRAINT_TYPE='P'",$table)); |
| 332 | 410 | if ($row = $rs->FetchRow()) |
| 333 | - $primary_key = $row[1]; //constraint_name |
|
| 411 | + { |
|
| 412 | + $primary_key = $row[1]; |
|
| 413 | + } |
|
| 414 | + //constraint_name |
|
| 334 | 415 | |
| 335 | - if ($primary==TRUE && $primary_key=='') { |
|
| 336 | - if (isset($savem)) |
|
| 337 | - $this->SetFetchMode($savem); |
|
| 416 | + if ($primary==TRUE && $primary_key=='') |
|
| 417 | + { |
|
| 418 | + if (isset($savem)) |
|
| 419 | + { |
|
| 420 | + $this->SetFetchMode($savem); |
|
| 421 | + } |
|
| 338 | 422 | $ADODB_FETCH_MODE = $save; |
| 339 | 423 | return $false; //There is no primary key |
| 340 | 424 | } |
@@ -342,9 +426,12 @@ discard block |
||
| 342 | 426 | $rs = $this->Execute(sprintf("SELECT ALL_INDEXES.INDEX_NAME, ALL_INDEXES.UNIQUENESS, ALL_IND_COLUMNS.COLUMN_POSITION, ALL_IND_COLUMNS.COLUMN_NAME FROM ALL_INDEXES,ALL_IND_COLUMNS WHERE UPPER(ALL_INDEXES.TABLE_NAME)='%s' AND ALL_IND_COLUMNS.INDEX_NAME=ALL_INDEXES.INDEX_NAME",$table)); |
| 343 | 427 | |
| 344 | 428 | |
| 345 | - if (!is_object($rs)) { |
|
| 346 | - if (isset($savem)) |
|
| 347 | - $this->SetFetchMode($savem); |
|
| 429 | + if (!is_object($rs)) |
|
| 430 | + { |
|
| 431 | + if (isset($savem)) |
|
| 432 | + { |
|
| 433 | + $this->SetFetchMode($savem); |
|
| 434 | + } |
|
| 348 | 435 | $ADODB_FETCH_MODE = $save; |
| 349 | 436 | return $false; |
| 350 | 437 | } |
@@ -352,9 +439,14 @@ discard block |
||
| 352 | 439 | $indexes = array (); |
| 353 | 440 | // parse index data into array |
| 354 | 441 | |
| 355 | - while ($row = $rs->FetchRow()) { |
|
| 356 | - if ($primary && $row[0] != $primary_key) continue; |
|
| 357 | - if (!isset($indexes[$row[0]])) { |
|
| 442 | + while ($row = $rs->FetchRow()) |
|
| 443 | + { |
|
| 444 | + if ($primary && $row[0] != $primary_key) |
|
| 445 | + { |
|
| 446 | + continue; |
|
| 447 | + } |
|
| 448 | + if (!isset($indexes[$row[0]])) |
|
| 449 | + { |
|
| 358 | 450 | $indexes[$row[0]] = array( |
| 359 | 451 | 'unique' => ($row[1] == 'UNIQUE'), |
| 360 | 452 | 'columns' => array() |
@@ -364,11 +456,13 @@ discard block |
||
| 364 | 456 | } |
| 365 | 457 | |
| 366 | 458 | // sort columns by order in the index |
| 367 | - foreach ( array_keys ($indexes) as $index ) { |
|
| 459 | + foreach ( array_keys ($indexes) as $index ) |
|
| 460 | + { |
|
| 368 | 461 | ksort ($indexes[$index]['columns']); |
| 369 | 462 | } |
| 370 | 463 | |
| 371 | - if (isset($savem)) { |
|
| 464 | + if (isset($savem)) |
|
| 465 | + { |
|
| 372 | 466 | $this->SetFetchMode($savem); |
| 373 | 467 | $ADODB_FETCH_MODE = $save; |
| 374 | 468 | } |
@@ -376,20 +470,32 @@ discard block |
||
| 376 | 470 | } |
| 377 | 471 | |
| 378 | 472 | function BeginTrans() |
| 379 | - { |
|
| 380 | - if ($this->transOff) return true; |
|
| 473 | + { |
|
| 474 | + if ($this->transOff) |
|
| 475 | + { |
|
| 476 | + return true; |
|
| 477 | + } |
|
| 381 | 478 | $this->transCnt += 1; |
| 382 | 479 | $this->autoCommit = false; |
| 383 | 480 | $this->_commit = OCI_DEFAULT; |
| 384 | 481 | return true; |
| 385 | 482 | } |
| 386 | 483 | |
| 387 | - function CommitTrans($ok=true) |
|
| 388 | - { |
|
| 389 | - if ($this->transOff) return true; |
|
| 390 | - if (!$ok) return $this->RollbackTrans(); |
|
| 484 | + function CommitTrans($ok=true) |
|
| 485 | + { |
|
| 486 | + if ($this->transOff) |
|
| 487 | + { |
|
| 488 | + return true; |
|
| 489 | + } |
|
| 490 | + if (!$ok) |
|
| 491 | + { |
|
| 492 | + return $this->RollbackTrans(); |
|
| 493 | + } |
|
| 391 | 494 | |
| 392 | - if ($this->transCnt) $this->transCnt -= 1; |
|
| 495 | + if ($this->transCnt) |
|
| 496 | + { |
|
| 497 | + $this->transCnt -= 1; |
|
| 498 | + } |
|
| 393 | 499 | $ret = OCIcommit($this->_connectionID); |
| 394 | 500 | $this->_commit = OCI_COMMIT_ON_SUCCESS; |
| 395 | 501 | $this->autoCommit = true; |
@@ -398,8 +504,14 @@ discard block |
||
| 398 | 504 | |
| 399 | 505 | function RollbackTrans() |
| 400 | 506 | { |
| 401 | - if ($this->transOff) return true; |
|
| 402 | - if ($this->transCnt) $this->transCnt -= 1; |
|
| 507 | + if ($this->transOff) |
|
| 508 | + { |
|
| 509 | + return true; |
|
| 510 | + } |
|
| 511 | + if ($this->transCnt) |
|
| 512 | + { |
|
| 513 | + $this->transCnt -= 1; |
|
| 514 | + } |
|
| 403 | 515 | $ret = OCIrollback($this->_connectionID); |
| 404 | 516 | $this->_commit = OCI_COMMIT_ON_SUCCESS; |
| 405 | 517 | $this->autoCommit = true; |
@@ -407,35 +519,61 @@ discard block |
||
| 407 | 519 | } |
| 408 | 520 | |
| 409 | 521 | |
| 410 | - function SelectDB($dbName) |
|
| 522 | + function SelectDB($dbName) |
|
| 411 | 523 | { |
| 412 | 524 | return false; |
| 413 | 525 | } |
| 414 | 526 | |
| 415 | - function ErrorMsg() |
|
| 527 | + function ErrorMsg() |
|
| 416 | 528 | { |
| 417 | - if ($this->_errorMsg !== false) return $this->_errorMsg; |
|
| 529 | + if ($this->_errorMsg !== false) |
|
| 530 | + { |
|
| 531 | + return $this->_errorMsg; |
|
| 532 | + } |
|
| 418 | 533 | |
| 419 | - if (is_resource($this->_stmt)) $arr = @OCIerror($this->_stmt); |
|
| 420 | - if (empty($arr)) { |
|
| 534 | + if (is_resource($this->_stmt)) |
|
| 535 | + { |
|
| 536 | + $arr = @OCIerror($this->_stmt); |
|
| 537 | + } |
|
| 538 | + if (empty($arr)) |
|
| 539 | + { |
|
| 421 | 540 | $arr = @OCIerror($this->_connectionID); |
| 422 | - if ($arr === false) $arr = @OCIError(); |
|
| 423 | - if ($arr === false) return ''; |
|
| 541 | + if ($arr === false) |
|
| 542 | + { |
|
| 543 | + $arr = @OCIError(); |
|
| 544 | + } |
|
| 545 | + if ($arr === false) |
|
| 546 | + { |
|
| 547 | + return ''; |
|
| 548 | + } |
|
| 424 | 549 | } |
| 425 | 550 | $this->_errorMsg = $arr['message']; |
| 426 | 551 | $this->_errorCode = $arr['code']; |
| 427 | 552 | return $this->_errorMsg; |
| 428 | 553 | } |
| 429 | 554 | |
| 430 | - function ErrorNo() |
|
| 555 | + function ErrorNo() |
|
| 431 | 556 | { |
| 432 | - if ($this->_errorCode !== false) return $this->_errorCode; |
|
| 557 | + if ($this->_errorCode !== false) |
|
| 558 | + { |
|
| 559 | + return $this->_errorCode; |
|
| 560 | + } |
|
| 433 | 561 | |
| 434 | - if (is_resource($this->_stmt)) $arr = @OCIError($this->_stmt); |
|
| 435 | - if (empty($arr)) { |
|
| 562 | + if (is_resource($this->_stmt)) |
|
| 563 | + { |
|
| 564 | + $arr = @OCIError($this->_stmt); |
|
| 565 | + } |
|
| 566 | + if (empty($arr)) |
|
| 567 | + { |
|
| 436 | 568 | $arr = @OCIError($this->_connectionID); |
| 437 | - if ($arr == false) $arr = @OCIError(); |
|
| 438 | - if ($arr == false) return ''; |
|
| 569 | + if ($arr == false) |
|
| 570 | + { |
|
| 571 | + $arr = @OCIError(); |
|
| 572 | + } |
|
| 573 | + if ($arr == false) |
|
| 574 | + { |
|
| 575 | + return ''; |
|
| 576 | + } |
|
| 439 | 577 | } |
| 440 | 578 | |
| 441 | 579 | $this->_errorMsg = $arr['message']; |
@@ -446,14 +584,19 @@ discard block |
||
| 446 | 584 | |
| 447 | 585 | // Format date column in sql string given an input format that understands Y M D |
| 448 | 586 | function SQLDate($fmt, $col=false) |
| 449 | - { |
|
| 450 | - if (!$col) $col = $this->sysTimeStamp; |
|
| 587 | + { |
|
| 588 | + if (!$col) |
|
| 589 | + { |
|
| 590 | + $col = $this->sysTimeStamp; |
|
| 591 | + } |
|
| 451 | 592 | $s = 'TO_CHAR('.$col.",'"; |
| 452 | 593 | |
| 453 | 594 | $len = strlen($fmt); |
| 454 | - for ($i=0; $i < $len; $i++) { |
|
| 595 | + for ($i=0; $i < $len; $i++) |
|
| 596 | + { |
|
| 455 | 597 | $ch = $fmt[$i]; |
| 456 | - switch($ch) { |
|
| 598 | + switch($ch) |
|
| 599 | + { |
|
| 457 | 600 | case 'Y': |
| 458 | 601 | case 'y': |
| 459 | 602 | $s .= 'YYYY'; |
@@ -506,12 +649,18 @@ discard block |
||
| 506 | 649 | |
| 507 | 650 | default: |
| 508 | 651 | // handle escape characters... |
| 509 | - if ($ch == '\\') { |
|
| 652 | + if ($ch == '\\') |
|
| 653 | + { |
|
| 510 | 654 | $i++; |
| 511 | 655 | $ch = substr($fmt,$i,1); |
| 512 | 656 | } |
| 513 | - if (strpos('-/.:;, ',$ch) !== false) $s .= $ch; |
|
| 514 | - else $s .= '"'.$ch.'"'; |
|
| 657 | + if (strpos('-/.:;, ',$ch) !== false) |
|
| 658 | + { |
|
| 659 | + $s .= $ch; |
|
| 660 | + } |
|
| 661 | + else { |
|
| 662 | + $s .= '"'.$ch.'"'; |
|
| 663 | + } |
|
| 515 | 664 | |
| 516 | 665 | } |
| 517 | 666 | } |
@@ -537,20 +686,32 @@ discard block |
||
| 537 | 686 | function &SelectLimit($sql,$nrows=-1,$offset=-1, $inputarr=false,$secs2cache=0) |
| 538 | 687 | { |
| 539 | 688 | // seems that oracle only supports 1 hint comment in 8i |
| 540 | - if ($this->firstrows) { |
|
| 689 | + if ($this->firstrows) |
|
| 690 | + { |
|
| 541 | 691 | if (strpos($sql,'/*+') !== false) |
| 542 | - $sql = str_replace('/*+ ','/*+FIRST_ROWS ',$sql); |
|
| 543 | - else |
|
| 544 | - $sql = preg_replace('/^[ \t\n]*select/i','SELECT /*+FIRST_ROWS*/',$sql); |
|
| 692 | + { |
|
| 693 | + $sql = str_replace('/*+ ','/*+FIRST_ROWS ',$sql); |
|
| 694 | + } |
|
| 695 | + else { |
|
| 696 | + $sql = preg_replace('/^[ \t\n]*select/i','SELECT /*+FIRST_ROWS*/',$sql); |
|
| 697 | + } |
|
| 545 | 698 | } |
| 546 | 699 | |
| 547 | - if ($offset < $this->selectOffsetAlg1) { |
|
| 548 | - if ($nrows > 0) { |
|
| 549 | - if ($offset > 0) $nrows += $offset; |
|
| 700 | + if ($offset < $this->selectOffsetAlg1) |
|
| 701 | + { |
|
| 702 | + if ($nrows > 0) |
|
| 703 | + { |
|
| 704 | + if ($offset > 0) |
|
| 705 | + { |
|
| 706 | + $nrows += $offset; |
|
| 707 | + } |
|
| 550 | 708 | //$inputarr['adodb_rownum'] = $nrows; |
| 551 | - if ($this->databaseType == 'oci8po') { |
|
| 709 | + if ($this->databaseType == 'oci8po') |
|
| 710 | + { |
|
| 552 | 711 | $sql = "select * from (".$sql.") where rownum <= ?"; |
| 553 | - } else { |
|
| 712 | + } |
|
| 713 | + else |
|
| 714 | + { |
|
| 554 | 715 | $sql = "select * from (".$sql.") where rownum <= :adodb_offset"; |
| 555 | 716 | } |
| 556 | 717 | $inputarr['adodb_offset'] = $nrows; |
@@ -561,44 +722,66 @@ discard block |
||
| 561 | 722 | $rs =& ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache); |
| 562 | 723 | return $rs; |
| 563 | 724 | |
| 564 | - } else { |
|
| 725 | + } |
|
| 726 | + else |
|
| 727 | + { |
|
| 565 | 728 | // Algorithm by Tomas V V Cox, from PEAR DB oci8.php |
| 566 | 729 | |
| 567 | 730 | // Let Oracle return the name of the columns |
| 568 | 731 | $q_fields = "SELECT * FROM (".$sql.") WHERE NULL = NULL"; |
| 569 | 732 | |
| 570 | 733 | $false = false; |
| 571 | - if (! $stmt_arr = $this->Prepare($q_fields)) { |
|
| 734 | + if (! $stmt_arr = $this->Prepare($q_fields)) |
|
| 735 | + { |
|
| 572 | 736 | return $false; |
| 573 | 737 | } |
| 574 | 738 | $stmt = $stmt_arr[1]; |
| 575 | 739 | |
| 576 | - if (is_array($inputarr)) { |
|
| 577 | - foreach($inputarr as $k => $v) { |
|
| 578 | - if (is_array($v)) { |
|
| 579 | - if (sizeof($v) == 2) // suggested by g.giunta@libero. |
|
| 740 | + if (is_array($inputarr)) |
|
| 741 | + { |
|
| 742 | + foreach($inputarr as $k => $v) |
|
| 743 | + { |
|
| 744 | + if (is_array($v)) |
|
| 745 | + { |
|
| 746 | + if (sizeof($v) == 2) |
|
| 747 | + { |
|
| 748 | + // suggested by g.giunta@libero. |
|
| 580 | 749 | OCIBindByName($stmt,":$k",$inputarr[$k][0],$v[1]); |
| 581 | - else |
|
| 582 | - OCIBindByName($stmt,":$k",$inputarr[$k][0],$v[1],$v[2]); |
|
| 583 | - } else { |
|
| 750 | + } |
|
| 751 | + else { |
|
| 752 | + OCIBindByName($stmt,":$k",$inputarr[$k][0],$v[1],$v[2]); |
|
| 753 | + } |
|
| 754 | + } |
|
| 755 | + else |
|
| 756 | + { |
|
| 584 | 757 | $len = -1; |
| 585 | - if ($v === ' ') $len = 1; |
|
| 586 | - if (isset($bindarr)) { // is prepared sql, so no need to ocibindbyname again |
|
| 758 | + if ($v === ' ') |
|
| 759 | + { |
|
| 760 | + $len = 1; |
|
| 761 | + } |
|
| 762 | + if (isset($bindarr)) |
|
| 763 | + { |
|
| 764 | +// is prepared sql, so no need to ocibindbyname again |
|
| 587 | 765 | $bindarr[$k] = $v; |
| 588 | - } else { // dynamic sql, so rebind every time |
|
| 766 | + } |
|
| 767 | + else |
|
| 768 | + { |
|
| 769 | +// dynamic sql, so rebind every time |
|
| 589 | 770 | OCIBindByName($stmt,":$k",$inputarr[$k],$len); |
| 590 | 771 | } |
| 591 | 772 | } |
| 592 | 773 | } |
| 593 | 774 | } |
| 594 | 775 | |
| 595 | - if (!OCIExecute($stmt, OCI_DEFAULT)) { |
|
| 776 | + if (!OCIExecute($stmt, OCI_DEFAULT)) |
|
| 777 | + { |
|
| 596 | 778 | OCIFreeStatement($stmt); |
| 597 | 779 | return $false; |
| 598 | 780 | } |
| 599 | 781 | |
| 600 | 782 | $ncols = OCINumCols($stmt); |
| 601 | - for ( $i = 1; $i <= $ncols; $i++ ) { |
|
| 783 | + for ( $i = 1; $i <= $ncols; $i++ ) |
|
| 784 | + { |
|
| 602 | 785 | $cols[] = '"'.OCIColumnName($stmt, $i).'"'; |
| 603 | 786 | } |
| 604 | 787 | $result = false; |
@@ -608,12 +791,15 @@ discard block |
||
| 608 | 791 | $nrows += $offset; |
| 609 | 792 | $offset += 1; // in Oracle rownum starts at 1 |
| 610 | 793 | |
| 611 | - if ($this->databaseType == 'oci8po') { |
|
| 794 | + if ($this->databaseType == 'oci8po') |
|
| 795 | + { |
|
| 612 | 796 | $sql = "SELECT $fields FROM". |
| 613 | 797 | "(SELECT rownum as adodb_rownum, $fields FROM". |
| 614 | 798 | " ($sql) WHERE rownum <= ?". |
| 615 | 799 | ") WHERE adodb_rownum >= ?"; |
| 616 | - } else { |
|
| 800 | + } |
|
| 801 | + else |
|
| 802 | + { |
|
| 617 | 803 | $sql = "SELECT $fields FROM". |
| 618 | 804 | "(SELECT rownum as adodb_rownum, $fields FROM". |
| 619 | 805 | " ($sql) WHERE rownum <= :adodb_nrows". |
@@ -622,8 +808,13 @@ discard block |
||
| 622 | 808 | $inputarr['adodb_nrows'] = $nrows; |
| 623 | 809 | $inputarr['adodb_offset'] = $offset; |
| 624 | 810 | |
| 625 | - if ($secs2cache>0) $rs =& $this->CacheExecute($secs2cache, $sql,$inputarr); |
|
| 626 | - else $rs =& $this->Execute($sql,$inputarr); |
|
| 811 | + if ($secs2cache>0) |
|
| 812 | + { |
|
| 813 | + $rs =& $this->CacheExecute($secs2cache, $sql,$inputarr); |
|
| 814 | + } |
|
| 815 | + else { |
|
| 816 | + $rs =& $this->Execute($sql,$inputarr); |
|
| 817 | + } |
|
| 627 | 818 | return $rs; |
| 628 | 819 | } |
| 629 | 820 | |
@@ -654,29 +845,51 @@ discard block |
||
| 654 | 845 | |
| 655 | 846 | //if (strlen($val) < 4000) return $this->Execute("UPDATE $table SET $column=:blob WHERE $where",array('blob'=>$val)) != false; |
| 656 | 847 | |
| 657 | - switch(strtoupper($blobtype)) { |
|
| 848 | + switch(strtoupper($blobtype)) |
|
| 849 | + { |
|
| 658 | 850 | default: ADOConnection::outp("<b>UpdateBlob</b>: Unknown blobtype=$blobtype"); return false; |
| 659 | 851 | case 'BLOB': $type = OCI_B_BLOB; break; |
| 660 | 852 | case 'CLOB': $type = OCI_B_CLOB; break; |
| 661 | 853 | } |
| 662 | 854 | |
| 663 | - if ($this->databaseType == 'oci8po') |
|
| 664 | - $sql = "UPDATE $table set $column=EMPTY_{$blobtype}() WHERE $where RETURNING $column INTO ?"; |
|
| 665 | - else |
|
| 666 | - $sql = "UPDATE $table set $column=EMPTY_{$blobtype}() WHERE $where RETURNING $column INTO :blob"; |
|
| 855 | + if ($this->databaseType == 'oci8po') |
|
| 856 | + { |
|
| 857 | + $sql = "UPDATE $table set $column=EMPTY_{$blobtype}() WHERE $where RETURNING $column INTO ?"; |
|
| 858 | + } |
|
| 859 | + else { |
|
| 860 | + $sql = "UPDATE $table set $column=EMPTY_{$blobtype}() WHERE $where RETURNING $column INTO :blob"; |
|
| 861 | + } |
|
| 667 | 862 | |
| 668 | 863 | $desc = OCINewDescriptor($this->_connectionID, OCI_D_LOB); |
| 669 | 864 | $arr['blob'] = array($desc,-1,$type); |
| 670 | - if ($this->session_sharing_force_blob) $this->Execute('ALTER SESSION SET CURSOR_SHARING=EXACT'); |
|
| 865 | + if ($this->session_sharing_force_blob) |
|
| 866 | + { |
|
| 867 | + $this->Execute('ALTER SESSION SET CURSOR_SHARING=EXACT'); |
|
| 868 | + } |
|
| 671 | 869 | $commit = $this->autoCommit; |
| 672 | - if ($commit) $this->BeginTrans(); |
|
| 870 | + if ($commit) |
|
| 871 | + { |
|
| 872 | + $this->BeginTrans(); |
|
| 873 | + } |
|
| 673 | 874 | $rs = $this->Execute($sql,$arr); |
| 674 | - if ($rez = !empty($rs)) $desc->save($val); |
|
| 875 | + if ($rez = !empty($rs)) |
|
| 876 | + { |
|
| 877 | + $desc->save($val); |
|
| 878 | + } |
|
| 675 | 879 | $desc->free(); |
| 676 | - if ($commit) $this->CommitTrans(); |
|
| 677 | - if ($this->session_sharing_force_blob) $this->Execute('ALTER SESSION SET CURSOR_SHARING=FORCE'); |
|
| 880 | + if ($commit) |
|
| 881 | + { |
|
| 882 | + $this->CommitTrans(); |
|
| 883 | + } |
|
| 884 | + if ($this->session_sharing_force_blob) |
|
| 885 | + { |
|
| 886 | + $this->Execute('ALTER SESSION SET CURSOR_SHARING=FORCE'); |
|
| 887 | + } |
|
| 678 | 888 | |
| 679 | - if ($rez) $rs->Close(); |
|
| 889 | + if ($rez) |
|
| 890 | + { |
|
| 891 | + $rs->Close(); |
|
| 892 | + } |
|
| 680 | 893 | return $rez; |
| 681 | 894 | } |
| 682 | 895 | |
@@ -685,27 +898,37 @@ discard block |
||
| 685 | 898 | */ |
| 686 | 899 | function UpdateBlobFile($table,$column,$val,$where,$blobtype='BLOB') |
| 687 | 900 | { |
| 688 | - switch(strtoupper($blobtype)) { |
|
| 901 | + switch(strtoupper($blobtype)) |
|
| 902 | + { |
|
| 689 | 903 | default: ADOConnection::outp( "<b>UpdateBlob</b>: Unknown blobtype=$blobtype"); return false; |
| 690 | 904 | case 'BLOB': $type = OCI_B_BLOB; break; |
| 691 | 905 | case 'CLOB': $type = OCI_B_CLOB; break; |
| 692 | 906 | } |
| 693 | 907 | |
| 694 | - if ($this->databaseType == 'oci8po') |
|
| 695 | - $sql = "UPDATE $table set $column=EMPTY_{$blobtype}() WHERE $where RETURNING $column INTO ?"; |
|
| 696 | - else |
|
| 697 | - $sql = "UPDATE $table set $column=EMPTY_{$blobtype}() WHERE $where RETURNING $column INTO :blob"; |
|
| 908 | + if ($this->databaseType == 'oci8po') |
|
| 909 | + { |
|
| 910 | + $sql = "UPDATE $table set $column=EMPTY_{$blobtype}() WHERE $where RETURNING $column INTO ?"; |
|
| 911 | + } |
|
| 912 | + else { |
|
| 913 | + $sql = "UPDATE $table set $column=EMPTY_{$blobtype}() WHERE $where RETURNING $column INTO :blob"; |
|
| 914 | + } |
|
| 698 | 915 | |
| 699 | 916 | $desc = OCINewDescriptor($this->_connectionID, OCI_D_LOB); |
| 700 | 917 | $arr['blob'] = array($desc,-1,$type); |
| 701 | 918 | |
| 702 | 919 | $this->BeginTrans(); |
| 703 | 920 | $rs = ADODB_oci8::Execute($sql,$arr); |
| 704 | - if ($rez = !empty($rs)) $desc->savefile($val); |
|
| 921 | + if ($rez = !empty($rs)) |
|
| 922 | + { |
|
| 923 | + $desc->savefile($val); |
|
| 924 | + } |
|
| 705 | 925 | $desc->free(); |
| 706 | 926 | $this->CommitTrans(); |
| 707 | 927 | |
| 708 | - if ($rez) $rs->Close(); |
|
| 928 | + if ($rez) |
|
| 929 | + { |
|
| 930 | + $rs->Close(); |
|
| 931 | + } |
|
| 709 | 932 | return $rez; |
| 710 | 933 | } |
| 711 | 934 | |
@@ -718,32 +941,49 @@ discard block |
||
| 718 | 941 | */ |
| 719 | 942 | function &Execute($sql,$inputarr=false) |
| 720 | 943 | { |
| 721 | - if ($this->fnExecute) { |
|
| 944 | + if ($this->fnExecute) |
|
| 945 | + { |
|
| 722 | 946 | $fn = $this->fnExecute; |
| 723 | 947 | $ret =& $fn($this,$sql,$inputarr); |
| 724 | - if (isset($ret)) return $ret; |
|
| 948 | + if (isset($ret)) |
|
| 949 | + { |
|
| 950 | + return $ret; |
|
| 951 | + } |
|
| 725 | 952 | } |
| 726 | - if ($inputarr) { |
|
| 953 | + if ($inputarr) |
|
| 954 | + { |
|
| 727 | 955 | #if (!is_array($inputarr)) $inputarr = array($inputarr); |
| 728 | 956 | |
| 729 | 957 | $element0 = reset($inputarr); |
| 730 | 958 | |
| 731 | 959 | # is_object check because oci8 descriptors can be passed in |
| 732 | - if (is_array($element0) && !is_object(reset($element0))) { |
|
| 960 | + if (is_array($element0) && !is_object(reset($element0))) |
|
| 961 | + { |
|
| 733 | 962 | if (is_string($sql)) |
| 734 | - $stmt = $this->Prepare($sql); |
|
| 735 | - else |
|
| 736 | - $stmt = $sql; |
|
| 963 | + { |
|
| 964 | + $stmt = $this->Prepare($sql); |
|
| 965 | + } |
|
| 966 | + else { |
|
| 967 | + $stmt = $sql; |
|
| 968 | + } |
|
| 737 | 969 | |
| 738 | - foreach($inputarr as $arr) { |
|
| 970 | + foreach($inputarr as $arr) |
|
| 971 | + { |
|
| 739 | 972 | $ret =& $this->_Execute($stmt,$arr); |
| 740 | - if (!$ret) return $ret; |
|
| 973 | + if (!$ret) |
|
| 974 | + { |
|
| 975 | + return $ret; |
|
| 976 | + } |
|
| 741 | 977 | } |
| 742 | - } else { |
|
| 978 | + } |
|
| 979 | + else |
|
| 980 | + { |
|
| 743 | 981 | $ret =& $this->_Execute($sql,$inputarr); |
| 744 | 982 | } |
| 745 | 983 | |
| 746 | - } else { |
|
| 984 | + } |
|
| 985 | + else |
|
| 986 | + { |
|
| 747 | 987 | $ret =& $this->_Execute($sql,false); |
| 748 | 988 | } |
| 749 | 989 | |
@@ -761,12 +1001,16 @@ discard block |
||
| 761 | 1001 | |
| 762 | 1002 | $stmt = OCIParse($this->_connectionID,$sql); |
| 763 | 1003 | |
| 764 | - if (!$stmt) return false; |
|
| 1004 | + if (!$stmt) |
|
| 1005 | + { |
|
| 1006 | + return false; |
|
| 1007 | + } |
|
| 765 | 1008 | |
| 766 | 1009 | $BINDNUM += 1; |
| 767 | 1010 | |
| 768 | 1011 | $sttype = @OCIStatementType($stmt); |
| 769 | - if ($sttype == 'BEGIN' || $sttype == 'DECLARE') { |
|
| 1012 | + if ($sttype == 'BEGIN' || $sttype == 'DECLARE') |
|
| 1013 | + { |
|
| 770 | 1014 | return array($sql,$stmt,0,$BINDNUM, ($cursor) ? OCINewCursor($this->_connectionID) : false); |
| 771 | 1015 | } |
| 772 | 1016 | return array($sql,$stmt,0,$BINDNUM); |
@@ -788,23 +1032,40 @@ discard block |
||
| 788 | 1032 | */ |
| 789 | 1033 | function &ExecuteCursor($sql,$cursorName='rs',$params=false) |
| 790 | 1034 | { |
| 791 | - if (is_array($sql)) $stmt = $sql; |
|
| 792 | - else $stmt = ADODB_oci8::Prepare($sql,true); # true to allocate OCINewCursor |
|
| 1035 | + if (is_array($sql)) |
|
| 1036 | + { |
|
| 1037 | + $stmt = $sql; |
|
| 1038 | + } |
|
| 1039 | + else { |
|
| 1040 | + $stmt = ADODB_oci8::Prepare($sql,true); |
|
| 1041 | + } |
|
| 1042 | + # true to allocate OCINewCursor |
|
| 793 | 1043 | |
| 794 | - if (is_array($stmt) && sizeof($stmt) >= 5) { |
|
| 1044 | + if (is_array($stmt) && sizeof($stmt) >= 5) |
|
| 1045 | + { |
|
| 795 | 1046 | $hasref = true; |
| 796 | 1047 | $this->Parameter($stmt, $ignoreCur, $cursorName, false, -1, OCI_B_CURSOR); |
| 797 | - if ($params) { |
|
| 798 | - foreach($params as $k => $v) { |
|
| 1048 | + if ($params) |
|
| 1049 | + { |
|
| 1050 | + foreach($params as $k => $v) |
|
| 1051 | + { |
|
| 799 | 1052 | $this->Parameter($stmt,$params[$k], $k); |
| 800 | 1053 | } |
| 801 | 1054 | } |
| 802 | - } else |
|
| 803 | - $hasref = false; |
|
| 1055 | + } |
|
| 1056 | + else { |
|
| 1057 | + $hasref = false; |
|
| 1058 | + } |
|
| 804 | 1059 | |
| 805 | 1060 | $rs =& $this->Execute($stmt); |
| 806 | - if ($rs->databaseType == 'array') OCIFreeCursor($stmt[4]); |
|
| 807 | - else if ($hasref) $rs->_refcursor = $stmt[4]; |
|
| 1061 | + if ($rs->databaseType == 'array') |
|
| 1062 | + { |
|
| 1063 | + OCIFreeCursor($stmt[4]); |
|
| 1064 | + } |
|
| 1065 | + else if ($hasref) |
|
| 1066 | + { |
|
| 1067 | + $rs->_refcursor = $stmt[4]; |
|
| 1068 | + } |
|
| 808 | 1069 | return $rs; |
| 809 | 1070 | } |
| 810 | 1071 | |
@@ -841,18 +1102,32 @@ discard block |
||
| 841 | 1102 | function Bind(&$stmt,&$var,$size=4000,$type=false,$name=false,$isOutput=false) |
| 842 | 1103 | { |
| 843 | 1104 | |
| 844 | - if (!is_array($stmt)) return false; |
|
| 1105 | + if (!is_array($stmt)) |
|
| 1106 | + { |
|
| 1107 | + return false; |
|
| 1108 | + } |
|
| 845 | 1109 | |
| 846 | - if (($type == OCI_B_CURSOR) && sizeof($stmt) >= 5) { |
|
| 1110 | + if (($type == OCI_B_CURSOR) && sizeof($stmt) >= 5) |
|
| 1111 | + { |
|
| 847 | 1112 | return OCIBindByName($stmt[1],":".$name,$stmt[4],$size,$type); |
| 848 | 1113 | } |
| 849 | 1114 | |
| 850 | - if ($name == false) { |
|
| 851 | - if ($type !== false) $rez = OCIBindByName($stmt[1],":".$stmt[2],$var,$size,$type); |
|
| 852 | - else $rez = OCIBindByName($stmt[1],":".$stmt[2],$var,$size); // +1 byte for null terminator |
|
| 1115 | + if ($name == false) |
|
| 1116 | + { |
|
| 1117 | + if ($type !== false) |
|
| 1118 | + { |
|
| 1119 | + $rez = OCIBindByName($stmt[1],":".$stmt[2],$var,$size,$type); |
|
| 1120 | + } |
|
| 1121 | + else { |
|
| 1122 | + $rez = OCIBindByName($stmt[1],":".$stmt[2],$var,$size); |
|
| 1123 | + } |
|
| 1124 | + // +1 byte for null terminator |
|
| 853 | 1125 | $stmt[2] += 1; |
| 854 | - } else if (oci_lob_desc($type)) { |
|
| 855 | - if ($this->debug) { |
|
| 1126 | + } |
|
| 1127 | + else if (oci_lob_desc($type)) |
|
| 1128 | + { |
|
| 1129 | + if ($this->debug) |
|
| 1130 | + { |
|
| 856 | 1131 | ADOConnection::outp("<b>Bind</b>: name = $name"); |
| 857 | 1132 | } |
| 858 | 1133 | //we have to create a new Descriptor here |
@@ -862,28 +1137,43 @@ discard block |
||
| 862 | 1137 | |
| 863 | 1138 | $tmp = &$this->_refLOBs[$numlob]['LOB']; |
| 864 | 1139 | $rez = OCIBindByName($stmt[1], ":".$name, $tmp, -1, $type); |
| 865 | - if ($this->debug) { |
|
| 1140 | + if ($this->debug) |
|
| 1141 | + { |
|
| 866 | 1142 | ADOConnection::outp("<b>Bind</b>: descriptor has been allocated, var (".$name.") binded"); |
| 867 | 1143 | } |
| 868 | 1144 | |
| 869 | 1145 | // if type is input then write data to lob now |
| 870 | - if ($isOutput == false) { |
|
| 1146 | + if ($isOutput == false) |
|
| 1147 | + { |
|
| 871 | 1148 | $var = $this->BlobEncode($var); |
| 872 | 1149 | $tmp->WriteTemporary($var); |
| 873 | 1150 | $this->_refLOBs[$numlob]['VAR'] = &$var; |
| 874 | - if ($this->debug) { |
|
| 1151 | + if ($this->debug) |
|
| 1152 | + { |
|
| 875 | 1153 | ADOConnection::outp("<b>Bind</b>: LOB has been written to temp"); |
| 876 | 1154 | } |
| 877 | - } else { |
|
| 1155 | + } |
|
| 1156 | + else |
|
| 1157 | + { |
|
| 878 | 1158 | $this->_refLOBs[$numlob]['VAR'] = &$var; |
| 879 | 1159 | } |
| 880 | 1160 | $rez = $tmp; |
| 881 | - } else { |
|
| 882 | - if ($this->debug) |
|
| 883 | - ADOConnection::outp("<b>Bind</b>: name = $name"); |
|
| 1161 | + } |
|
| 1162 | + else |
|
| 1163 | + { |
|
| 1164 | + if ($this->debug) |
|
| 1165 | + { |
|
| 1166 | + ADOConnection::outp("<b>Bind</b>: name = $name"); |
|
| 1167 | + } |
|
| 884 | 1168 | |
| 885 | - if ($type !== false) $rez = OCIBindByName($stmt[1],":".$name,$var,$size,$type); |
|
| 886 | - else $rez = OCIBindByName($stmt[1],":".$name,$var,$size); // +1 byte for null terminator |
|
| 1169 | + if ($type !== false) |
|
| 1170 | + { |
|
| 1171 | + $rez = OCIBindByName($stmt[1],":".$name,$var,$size,$type); |
|
| 1172 | + } |
|
| 1173 | + else { |
|
| 1174 | + $rez = OCIBindByName($stmt[1],":".$name,$var,$size); |
|
| 1175 | + } |
|
| 1176 | + // +1 byte for null terminator |
|
| 887 | 1177 | } |
| 888 | 1178 | |
| 889 | 1179 | return $rez; |
@@ -912,7 +1202,8 @@ discard block |
||
| 912 | 1202 | */ |
| 913 | 1203 | function Parameter(&$stmt,&$var,$name,$isOutput=false,$maxLen=4000,$type=false) |
| 914 | 1204 | { |
| 915 | - if ($this->debug) { |
|
| 1205 | + if ($this->debug) |
|
| 1206 | + { |
|
| 916 | 1207 | $prefix = ($isOutput) ? 'Out' : 'In'; |
| 917 | 1208 | $ztype = (empty($type)) ? 'false' : $type; |
| 918 | 1209 | ADOConnection::outp( "{$prefix}Parameter(\$stmt, \$php_var='$var', \$name='$name', \$maxLen=$maxLen, \$type=$ztype);"); |
@@ -937,50 +1228,85 @@ discard block |
||
| 937 | 1228 | */ |
| 938 | 1229 | function _query($sql,$inputarr) |
| 939 | 1230 | { |
| 940 | - if (is_array($sql)) { // is prepared sql |
|
| 1231 | + if (is_array($sql)) |
|
| 1232 | + { |
|
| 1233 | +// is prepared sql |
|
| 941 | 1234 | $stmt = $sql[1]; |
| 942 | 1235 | |
| 943 | 1236 | // we try to bind to permanent array, so that OCIBindByName is persistent |
| 944 | 1237 | // and carried out once only - note that max array element size is 4000 chars |
| 945 | - if (is_array($inputarr)) { |
|
| 1238 | + if (is_array($inputarr)) |
|
| 1239 | + { |
|
| 946 | 1240 | $bindpos = $sql[3]; |
| 947 | - if (isset($this->_bind[$bindpos])) { |
|
| 1241 | + if (isset($this->_bind[$bindpos])) |
|
| 1242 | + { |
|
| 948 | 1243 | // all tied up already |
| 949 | 1244 | $bindarr = &$this->_bind[$bindpos]; |
| 950 | - } else { |
|
| 1245 | + } |
|
| 1246 | + else |
|
| 1247 | + { |
|
| 951 | 1248 | // one statement to bind them all |
| 952 | 1249 | $bindarr = array(); |
| 953 | - foreach($inputarr as $k => $v) { |
|
| 1250 | + foreach($inputarr as $k => $v) |
|
| 1251 | + { |
|
| 954 | 1252 | $bindarr[$k] = $v; |
| 955 | 1253 | OCIBindByName($stmt,":$k",$bindarr[$k],is_string($v) && strlen($v)>4000 ? -1 : 4000); |
| 956 | 1254 | } |
| 957 | 1255 | $this->_bind[$bindpos] = &$bindarr; |
| 958 | 1256 | } |
| 959 | 1257 | } |
| 960 | - } else { |
|
| 1258 | + } |
|
| 1259 | + else |
|
| 1260 | + { |
|
| 961 | 1261 | $stmt=OCIParse($this->_connectionID,$sql); |
| 962 | 1262 | } |
| 963 | 1263 | |
| 964 | 1264 | $this->_stmt = $stmt; |
| 965 | - if (!$stmt) return false; |
|
| 1265 | + if (!$stmt) |
|
| 1266 | + { |
|
| 1267 | + return false; |
|
| 1268 | + } |
|
| 966 | 1269 | |
| 967 | - if (defined('ADODB_PREFETCH_ROWS')) @OCISetPrefetch($stmt,ADODB_PREFETCH_ROWS); |
|
| 1270 | + if (defined('ADODB_PREFETCH_ROWS')) |
|
| 1271 | + { |
|
| 1272 | + @OCISetPrefetch($stmt,ADODB_PREFETCH_ROWS); |
|
| 1273 | + } |
|
| 968 | 1274 | |
| 969 | - if (is_array($inputarr)) { |
|
| 970 | - foreach($inputarr as $k => $v) { |
|
| 971 | - if (is_array($v)) { |
|
| 972 | - if (sizeof($v) == 2) // suggested by g.giunta@libero. |
|
| 1275 | + if (is_array($inputarr)) |
|
| 1276 | + { |
|
| 1277 | + foreach($inputarr as $k => $v) |
|
| 1278 | + { |
|
| 1279 | + if (is_array($v)) |
|
| 1280 | + { |
|
| 1281 | + if (sizeof($v) == 2) |
|
| 1282 | + { |
|
| 1283 | + // suggested by g.giunta@libero. |
|
| 973 | 1284 | OCIBindByName($stmt,":$k",$inputarr[$k][0],$v[1]); |
| 974 | - else |
|
| 975 | - OCIBindByName($stmt,":$k",$inputarr[$k][0],$v[1],$v[2]); |
|
| 1285 | + } |
|
| 1286 | + else { |
|
| 1287 | + OCIBindByName($stmt,":$k",$inputarr[$k][0],$v[1],$v[2]); |
|
| 1288 | + } |
|
| 976 | 1289 | |
| 977 | - if ($this->debug==99) echo "name=:$k",' var='.$inputarr[$k][0],' len='.$v[1],' type='.$v[2],'<br>'; |
|
| 978 | - } else { |
|
| 1290 | + if ($this->debug==99) |
|
| 1291 | + { |
|
| 1292 | + echo "name=:$k",' var='.$inputarr[$k][0],' len='.$v[1],' type='.$v[2],'<br>'; |
|
| 1293 | + } |
|
| 1294 | + } |
|
| 1295 | + else |
|
| 1296 | + { |
|
| 979 | 1297 | $len = -1; |
| 980 | - if ($v === ' ') $len = 1; |
|
| 981 | - if (isset($bindarr)) { // is prepared sql, so no need to ocibindbyname again |
|
| 1298 | + if ($v === ' ') |
|
| 1299 | + { |
|
| 1300 | + $len = 1; |
|
| 1301 | + } |
|
| 1302 | + if (isset($bindarr)) |
|
| 1303 | + { |
|
| 1304 | +// is prepared sql, so no need to ocibindbyname again |
|
| 982 | 1305 | $bindarr[$k] = $v; |
| 983 | - } else { // dynamic sql, so rebind every time |
|
| 1306 | + } |
|
| 1307 | + else |
|
| 1308 | + { |
|
| 1309 | +// dynamic sql, so rebind every time |
|
| 984 | 1310 | OCIBindByName($stmt,":$k",$inputarr[$k],$len); |
| 985 | 1311 | } |
| 986 | 1312 | } |
@@ -989,44 +1315,58 @@ discard block |
||
| 989 | 1315 | |
| 990 | 1316 | $this->_errorMsg = false; |
| 991 | 1317 | $this->_errorCode = false; |
| 992 | - if (OCIExecute($stmt,$this->_commit)) { |
|
| 1318 | + if (OCIExecute($stmt,$this->_commit)) |
|
| 1319 | + { |
|
| 993 | 1320 | //OCIInternalDebug(1); |
| 994 | - if (count($this -> _refLOBs) > 0) { |
|
| 1321 | + if (count($this -> _refLOBs) > 0) |
|
| 1322 | + { |
|
| 995 | 1323 | |
| 996 | - foreach ($this -> _refLOBs as $key => $value) { |
|
| 997 | - if ($this -> _refLOBs[$key]['TYPE'] == true) { |
|
| 1324 | + foreach ($this -> _refLOBs as $key => $value) |
|
| 1325 | + { |
|
| 1326 | + if ($this -> _refLOBs[$key]['TYPE'] == true) |
|
| 1327 | + { |
|
| 998 | 1328 | $tmp = $this -> _refLOBs[$key]['LOB'] -> load(); |
| 999 | - if ($this -> debug) { |
|
| 1329 | + if ($this -> debug) |
|
| 1330 | + { |
|
| 1000 | 1331 | ADOConnection::outp("<b>OUT LOB</b>: LOB has been loaded. <br>"); |
| 1001 | 1332 | } |
| 1002 | 1333 | //$_GLOBALS[$this -> _refLOBs[$key]['VAR']] = $tmp; |
| 1003 | 1334 | $this -> _refLOBs[$key]['VAR'] = $tmp; |
| 1004 | - } else { |
|
| 1335 | + } |
|
| 1336 | + else |
|
| 1337 | + { |
|
| 1005 | 1338 | $this->_refLOBs[$key]['LOB']->save($this->_refLOBs[$key]['VAR']); |
| 1006 | 1339 | $this -> _refLOBs[$key]['LOB']->free(); |
| 1007 | 1340 | unset($this -> _refLOBs[$key]); |
| 1008 | - if ($this->debug) { |
|
| 1341 | + if ($this->debug) |
|
| 1342 | + { |
|
| 1009 | 1343 | ADOConnection::outp("<b>IN LOB</b>: LOB has been saved. <br>"); |
| 1010 | 1344 | } |
| 1011 | 1345 | } |
| 1012 | 1346 | } |
| 1013 | 1347 | } |
| 1014 | 1348 | |
| 1015 | - switch (@OCIStatementType($stmt)) { |
|
| 1349 | + switch (@OCIStatementType($stmt)) |
|
| 1350 | + { |
|
| 1016 | 1351 | case "SELECT": |
| 1017 | 1352 | return $stmt; |
| 1018 | 1353 | |
| 1019 | 1354 | case 'DECLARE': |
| 1020 | 1355 | case "BEGIN": |
| 1021 | - if (is_array($sql) && !empty($sql[4])) { |
|
| 1356 | + if (is_array($sql) && !empty($sql[4])) |
|
| 1357 | + { |
|
| 1022 | 1358 | $cursor = $sql[4]; |
| 1023 | - if (is_resource($cursor)) { |
|
| 1359 | + if (is_resource($cursor)) |
|
| 1360 | + { |
|
| 1024 | 1361 | $ok = OCIExecute($cursor); |
| 1025 | 1362 | return $cursor; |
| 1026 | 1363 | } |
| 1027 | 1364 | return $stmt; |
| 1028 | - } else { |
|
| 1029 | - if (is_resource($stmt)) { |
|
| 1365 | + } |
|
| 1366 | + else |
|
| 1367 | + { |
|
| 1368 | + if (is_resource($stmt)) |
|
| 1369 | + { |
|
| 1030 | 1370 | OCIFreeStatement($stmt); |
| 1031 | 1371 | return true; |
| 1032 | 1372 | } |
@@ -1044,11 +1384,19 @@ discard block |
||
| 1044 | 1384 | // returns true or false |
| 1045 | 1385 | function _close() |
| 1046 | 1386 | { |
| 1047 | - if (!$this->_connectionID) return; |
|
| 1387 | + if (!$this->_connectionID) |
|
| 1388 | + { |
|
| 1389 | + return; |
|
| 1390 | + } |
|
| 1048 | 1391 | |
| 1049 | - if (!$this->autoCommit) OCIRollback($this->_connectionID); |
|
| 1050 | - if (count($this->_refLOBs) > 0) { |
|
| 1051 | - foreach ($this ->_refLOBs as $key => $value) { |
|
| 1392 | + if (!$this->autoCommit) |
|
| 1393 | + { |
|
| 1394 | + OCIRollback($this->_connectionID); |
|
| 1395 | + } |
|
| 1396 | + if (count($this->_refLOBs) > 0) |
|
| 1397 | + { |
|
| 1398 | + foreach ($this ->_refLOBs as $key => $value) |
|
| 1399 | + { |
|
| 1052 | 1400 | $this->_refLOBs[$key]['LOB']->free(); |
| 1053 | 1401 | unset($this->_refLOBs[$key]); |
| 1054 | 1402 | } |
@@ -1061,14 +1409,20 @@ discard block |
||
| 1061 | 1409 | |
| 1062 | 1410 | function MetaPrimaryKeys($table, $owner=false,$internalKey=false) |
| 1063 | 1411 | { |
| 1064 | - if ($internalKey) return array('ROWID'); |
|
| 1412 | + if ($internalKey) |
|
| 1413 | + { |
|
| 1414 | + return array('ROWID'); |
|
| 1415 | + } |
|
| 1065 | 1416 | |
| 1066 | 1417 | // tested with oracle 8.1.7 |
| 1067 | 1418 | $table = strtoupper($table); |
| 1068 | - if ($owner) { |
|
| 1419 | + if ($owner) |
|
| 1420 | + { |
|
| 1069 | 1421 | $owner_clause = "AND ((a.OWNER = b.OWNER) AND (a.OWNER = UPPER('$owner')))"; |
| 1070 | 1422 | $ptab = 'ALL_'; |
| 1071 | - } else { |
|
| 1423 | + } |
|
| 1424 | + else |
|
| 1425 | + { |
|
| 1072 | 1426 | $owner_clause = ''; |
| 1073 | 1427 | $ptab = 'USER_'; |
| 1074 | 1428 | } |
@@ -1082,15 +1436,19 @@ discard block |
||
| 1082 | 1436 | AND (a.constraint_name = b.constraint_name)"; |
| 1083 | 1437 | |
| 1084 | 1438 | $rs = $this->Execute($sql); |
| 1085 | - if ($rs && !$rs->EOF) { |
|
| 1439 | + if ($rs && !$rs->EOF) |
|
| 1440 | + { |
|
| 1086 | 1441 | $arr =& $rs->GetArray(); |
| 1087 | 1442 | $a = array(); |
| 1088 | - foreach($arr as $v) { |
|
| 1443 | + foreach($arr as $v) |
|
| 1444 | + { |
|
| 1089 | 1445 | $a[] = reset($v); |
| 1090 | 1446 | } |
| 1091 | 1447 | return $a; |
| 1092 | 1448 | } |
| 1093 | - else return false; |
|
| 1449 | + else { |
|
| 1450 | + return false; |
|
| 1451 | + } |
|
| 1094 | 1452 | } |
| 1095 | 1453 | |
| 1096 | 1454 | // http://gis.mit.edu/classes/11.521/sqlnotes/referential_integrity.html |
@@ -1101,11 +1459,14 @@ discard block |
||
| 1101 | 1459 | $save = $ADODB_FETCH_MODE; |
| 1102 | 1460 | $ADODB_FETCH_MODE = ADODB_FETCH_NUM; |
| 1103 | 1461 | $table = $this->qstr(strtoupper($table)); |
| 1104 | - if (!$owner) { |
|
| 1462 | + if (!$owner) |
|
| 1463 | + { |
|
| 1105 | 1464 | $owner = $this->user; |
| 1106 | 1465 | $tabp = 'user_'; |
| 1107 | - } else |
|
| 1108 | - $tabp = 'all_'; |
|
| 1466 | + } |
|
| 1467 | + else { |
|
| 1468 | + $tabp = 'all_'; |
|
| 1469 | + } |
|
| 1109 | 1470 | |
| 1110 | 1471 | $owner = ' and owner='.$this->qstr(strtoupper($owner)); |
| 1111 | 1472 | |
@@ -1116,15 +1477,20 @@ discard block |
||
| 1116 | 1477 | |
| 1117 | 1478 | $constraints =& $this->GetArray($sql); |
| 1118 | 1479 | $arr = false; |
| 1119 | - foreach($constraints as $constr) { |
|
| 1480 | + foreach($constraints as $constr) |
|
| 1481 | + { |
|
| 1120 | 1482 | $cons = $this->qstr($constr[0]); |
| 1121 | 1483 | $rowner = $this->qstr($constr[1]); |
| 1122 | 1484 | $rcons = $this->qstr($constr[2]); |
| 1123 | 1485 | $cols = $this->GetArray("select column_name from {$tabp}cons_columns where constraint_name=$cons $owner order by position"); |
| 1124 | 1486 | $tabcol = $this->GetArray("select table_name,column_name from {$tabp}cons_columns where owner=$rowner and constraint_name=$rcons order by position"); |
| 1125 | 1487 | |
| 1126 | - if ($cols && $tabcol) |
|
| 1127 | - for ($i=0, $max=sizeof($cols); $i < $max; $i++) { |
|
| 1488 | + if ($cols && $tabcol) |
|
| 1489 | + { |
|
| 1490 | + for ($i=0, $max=sizeof($cols); |
|
| 1491 | + } |
|
| 1492 | + $i < $max; $i++) |
|
| 1493 | + { |
|
| 1128 | 1494 | $arr[$tabcol[$i][0]] = $cols[$i][0].'='.$tabcol[$i][1]; |
| 1129 | 1495 | } |
| 1130 | 1496 | } |
@@ -1155,12 +1521,17 @@ discard block |
||
| 1155 | 1521 | * @return quoted string to be sent back to database |
| 1156 | 1522 | */ |
| 1157 | 1523 | function qstr($s,$magic_quotes=false) |
| 1158 | - { |
|
| 1524 | + { |
|
| 1159 | 1525 | $nofixquotes=false; |
| 1160 | 1526 | |
| 1161 | - if ($this->noNullStrings && strlen($s)==0)$s = ' '; |
|
| 1162 | - if (!$magic_quotes) { |
|
| 1163 | - if ($this->replaceQuote[0] == '\\'){ |
|
| 1527 | + if ($this->noNullStrings && strlen($s)==0) |
|
| 1528 | + { |
|
| 1529 | + $s = ' '; |
|
| 1530 | + } |
|
| 1531 | + if (!$magic_quotes) |
|
| 1532 | + { |
|
| 1533 | + if ($this->replaceQuote[0] == '\\') |
|
| 1534 | + { |
|
| 1164 | 1535 | $s = str_replace('\\','\\\\',$s); |
| 1165 | 1536 | } |
| 1166 | 1537 | return "'".str_replace("'",$this->replaceQuote,$s)."'"; |
@@ -1180,7 +1551,8 @@ discard block |
||
| 1180 | 1551 | Class Name: Recordset |
| 1181 | 1552 | --------------------------------------------------------------------------------------*/ |
| 1182 | 1553 | |
| 1183 | -class ADORecordset_oci8 extends ADORecordSet { |
|
| 1554 | +class ADORecordset_oci8 extends ADORecordSet |
|
| 1555 | +{ |
|
| 1184 | 1556 | |
| 1185 | 1557 | var $databaseType = 'oci8'; |
| 1186 | 1558 | var $bind=false; |
@@ -1190,7 +1562,8 @@ discard block |
||
| 1190 | 1562 | |
| 1191 | 1563 | function ADORecordset_oci8($queryID,$mode=false) |
| 1192 | 1564 | { |
| 1193 | - if ($mode === false) { |
|
| 1565 | + if ($mode === false) |
|
| 1566 | + { |
|
| 1194 | 1567 | global $ADODB_FETCH_MODE; |
| 1195 | 1568 | $mode = $ADODB_FETCH_MODE; |
| 1196 | 1569 | } |
@@ -1211,10 +1584,14 @@ discard block |
||
| 1211 | 1584 | |
| 1212 | 1585 | function Init() |
| 1213 | 1586 | { |
| 1214 | - if ($this->_inited) return; |
|
| 1587 | + if ($this->_inited) |
|
| 1588 | + { |
|
| 1589 | + return; |
|
| 1590 | + } |
|
| 1215 | 1591 | |
| 1216 | 1592 | $this->_inited = true; |
| 1217 | - if ($this->_queryID) { |
|
| 1593 | + if ($this->_queryID) |
|
| 1594 | + { |
|
| 1218 | 1595 | |
| 1219 | 1596 | $this->_currentRow = 0; |
| 1220 | 1597 | @$this->_initrs(); |
@@ -1227,11 +1604,14 @@ discard block |
||
| 1227 | 1604 | if ($err && $this->connection->debug) ADOConnection::outp($err); |
| 1228 | 1605 | */ |
| 1229 | 1606 | |
| 1230 | - if (!is_array($this->fields)) { |
|
| 1607 | + if (!is_array($this->fields)) |
|
| 1608 | + { |
|
| 1231 | 1609 | $this->_numOfRows = 0; |
| 1232 | 1610 | $this->fields = array(); |
| 1233 | 1611 | } |
| 1234 | - } else { |
|
| 1612 | + } |
|
| 1613 | + else |
|
| 1614 | + { |
|
| 1235 | 1615 | $this->fields = array(); |
| 1236 | 1616 | $this->_numOfRows = 0; |
| 1237 | 1617 | $this->_numOfFields = 0; |
@@ -1243,10 +1623,14 @@ discard block |
||
| 1243 | 1623 | { |
| 1244 | 1624 | $this->_numOfRows = -1; |
| 1245 | 1625 | $this->_numOfFields = OCInumcols($this->_queryID); |
| 1246 | - if ($this->_numOfFields>0) { |
|
| 1626 | + if ($this->_numOfFields>0) |
|
| 1627 | + { |
|
| 1247 | 1628 | $this->_fieldobjs = array(); |
| 1248 | 1629 | $max = $this->_numOfFields; |
| 1249 | - for ($i=0;$i<$max; $i++) $this->_fieldobjs[] = $this->_FetchField($i); |
|
| 1630 | + for ($i=0;$i<$max; $i++) |
|
| 1631 | + { |
|
| 1632 | + $this->_fieldobjs[] = $this->_FetchField($i); |
|
| 1633 | + } |
|
| 1250 | 1634 | } |
| 1251 | 1635 | } |
| 1252 | 1636 | |
@@ -1262,10 +1646,14 @@ discard block |
||
| 1262 | 1646 | $fld->name =OCIcolumnname($this->_queryID, $fieldOffset); |
| 1263 | 1647 | $fld->type = OCIcolumntype($this->_queryID, $fieldOffset); |
| 1264 | 1648 | $fld->max_length = OCIcolumnsize($this->_queryID, $fieldOffset); |
| 1265 | - if ($fld->type == 'NUMBER') { |
|
| 1649 | + if ($fld->type == 'NUMBER') |
|
| 1650 | + { |
|
| 1266 | 1651 | $p = OCIColumnPrecision($this->_queryID, $fieldOffset); |
| 1267 | 1652 | $sc = OCIColumnScale($this->_queryID, $fieldOffset); |
| 1268 | - if ($p != 0 && $sc == 0) $fld->type = 'INT'; |
|
| 1653 | + if ($p != 0 && $sc == 0) |
|
| 1654 | + { |
|
| 1655 | + $fld->type = 'INT'; |
|
| 1656 | + } |
|
| 1269 | 1657 | //echo " $this->name ($p.$sc) "; |
| 1270 | 1658 | } |
| 1271 | 1659 | return $fld; |
@@ -1297,11 +1685,13 @@ discard block |
||
| 1297 | 1685 | |
| 1298 | 1686 | function MoveNext() |
| 1299 | 1687 | { |
| 1300 | - if (@OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode)) { |
|
| 1688 | + if (@OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode)) |
|
| 1689 | + { |
|
| 1301 | 1690 | $this->_currentRow += 1; |
| 1302 | 1691 | return true; |
| 1303 | 1692 | } |
| 1304 | - if (!$this->EOF) { |
|
| 1693 | + if (!$this->EOF) |
|
| 1694 | + { |
|
| 1305 | 1695 | $this->_currentRow += 1; |
| 1306 | 1696 | $this->EOF = true; |
| 1307 | 1697 | } |
@@ -1345,17 +1735,24 @@ discard block |
||
| 1345 | 1735 | /* Optimize SelectLimit() by using OCIFetch() instead of OCIFetchInto() */ |
| 1346 | 1736 | function &GetArrayLimit($nrows,$offset=-1) |
| 1347 | 1737 | { |
| 1348 | - if ($offset <= 0) { |
|
| 1738 | + if ($offset <= 0) |
|
| 1739 | + { |
|
| 1349 | 1740 | $arr =& $this->GetArray($nrows); |
| 1350 | 1741 | return $arr; |
| 1351 | 1742 | } |
| 1352 | - for ($i=1; $i < $offset; $i++) |
|
| 1353 | - if (!@OCIFetch($this->_queryID)) return array(); |
|
| 1743 | + for ($i=1; $i < $offset; $i++) |
|
| 1744 | + { |
|
| 1745 | + if (!@OCIFetch($this->_queryID)) return array(); |
|
| 1746 | + } |
|
| 1354 | 1747 | |
| 1355 | - if (!@OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode)) return array(); |
|
| 1748 | + if (!@OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode)) |
|
| 1749 | + { |
|
| 1750 | + return array(); |
|
| 1751 | + } |
|
| 1356 | 1752 | $results = array(); |
| 1357 | 1753 | $cnt = 0; |
| 1358 | - while (!$this->EOF && $nrows != $cnt) { |
|
| 1754 | + while (!$this->EOF && $nrows != $cnt) |
|
| 1755 | + { |
|
| 1359 | 1756 | $results[$cnt++] = $this->fields; |
| 1360 | 1757 | $this->MoveNext(); |
| 1361 | 1758 | } |
@@ -1367,9 +1764,11 @@ discard block |
||
| 1367 | 1764 | /* Use associative array to get fields array */ |
| 1368 | 1765 | function Fields($colname) |
| 1369 | 1766 | { |
| 1370 | - if (!$this->bind) { |
|
| 1767 | + if (!$this->bind) |
|
| 1768 | + { |
|
| 1371 | 1769 | $this->bind = array(); |
| 1372 | - for ($i=0; $i < $this->_numOfFields; $i++) { |
|
| 1770 | + for ($i=0; $i < $this->_numOfFields; $i++) |
|
| 1771 | + { |
|
| 1373 | 1772 | $o = $this->FetchField($i); |
| 1374 | 1773 | $this->bind[strtoupper($o->name)] = $i; |
| 1375 | 1774 | } |
@@ -1385,7 +1784,7 @@ discard block |
||
| 1385 | 1784 | return false; |
| 1386 | 1785 | } |
| 1387 | 1786 | |
| 1388 | - function _fetch() |
|
| 1787 | + function _fetch() |
|
| 1389 | 1788 | { |
| 1390 | 1789 | return @OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode); |
| 1391 | 1790 | } |
@@ -1393,10 +1792,14 @@ discard block |
||
| 1393 | 1792 | /* close() only needs to be called if you are worried about using too much memory while your script |
| 1394 | 1793 | is running. All associated result memory for the specified result identifier will automatically be freed. */ |
| 1395 | 1794 | |
| 1396 | - function _close() |
|
| 1795 | + function _close() |
|
| 1397 | 1796 | { |
| 1398 | - if ($this->connection->_stmt === $this->_queryID) $this->connection->_stmt = false; |
|
| 1399 | - if (!empty($this->_refcursor)) { |
|
| 1797 | + if ($this->connection->_stmt === $this->_queryID) |
|
| 1798 | + { |
|
| 1799 | + $this->connection->_stmt = false; |
|
| 1800 | + } |
|
| 1801 | + if (!empty($this->_refcursor)) |
|
| 1802 | + { |
|
| 1400 | 1803 | OCIFreeCursor($this->_refcursor); |
| 1401 | 1804 | $this->_refcursor = false; |
| 1402 | 1805 | } |
@@ -1407,12 +1810,14 @@ discard block |
||
| 1407 | 1810 | |
| 1408 | 1811 | function MetaType($t,$len=-1) |
| 1409 | 1812 | { |
| 1410 | - if (is_object($t)) { |
|
| 1813 | + if (is_object($t)) |
|
| 1814 | + { |
|
| 1411 | 1815 | $fieldobj = $t; |
| 1412 | 1816 | $t = $fieldobj->type; |
| 1413 | 1817 | $len = $fieldobj->max_length; |
| 1414 | 1818 | } |
| 1415 | - switch (strtoupper($t)) { |
|
| 1819 | + switch (strtoupper($t)) |
|
| 1820 | + { |
|
| 1416 | 1821 | case 'VARCHAR': |
| 1417 | 1822 | case 'VARCHAR2': |
| 1418 | 1823 | case 'CHAR': |
@@ -1421,7 +1826,10 @@ discard block |
||
| 1421 | 1826 | case 'NCHAR': |
| 1422 | 1827 | case 'NVARCHAR': |
| 1423 | 1828 | case 'NVARCHAR2': |
| 1424 | - if (isset($this) && $len <= $this->blobSize) return 'C'; |
|
| 1829 | + if (isset($this) && $len <= $this->blobSize) |
|
| 1830 | + { |
|
| 1831 | + return 'C'; |
|
| 1832 | + } |
|
| 1425 | 1833 | |
| 1426 | 1834 | case 'NCLOB': |
| 1427 | 1835 | case 'LONG': |
@@ -1450,10 +1858,12 @@ discard block |
||
| 1450 | 1858 | } |
| 1451 | 1859 | } |
| 1452 | 1860 | |
| 1453 | -class ADORecordSet_ext_oci8 extends ADORecordSet_oci8 { |
|
| 1454 | - function ADORecordSet_ext_oci8($queryID,$mode=false) |
|
| 1861 | +class ADORecordSet_ext_oci8 extends ADORecordSet_oci8 |
|
| 1862 | +{ |
|
| 1863 | + function ADORecordSet_ext_oci8($queryID,$mode=false) |
|
| 1455 | 1864 | { |
| 1456 | - if ($mode === false) { |
|
| 1865 | + if ($mode === false) |
|
| 1866 | + { |
|
| 1457 | 1867 | global $ADODB_FETCH_MODE; |
| 1458 | 1868 | $mode = $ADODB_FETCH_MODE; |
| 1459 | 1869 | } |
@@ -609,12 +609,12 @@ discard block |
||
| 609 | 609 | $offset += 1; // in Oracle rownum starts at 1 |
| 610 | 610 | |
| 611 | 611 | if ($this->databaseType == 'oci8po') { |
| 612 | - $sql = "SELECT $fields FROM". |
|
| 612 | + $sql = "select $fields FROM". |
|
| 613 | 613 | "(SELECT rownum as adodb_rownum, $fields FROM". |
| 614 | 614 | " ($sql) WHERE rownum <= ?". |
| 615 | 615 | ") WHERE adodb_rownum >= ?"; |
| 616 | 616 | } else { |
| 617 | - $sql = "SELECT $fields FROM". |
|
| 617 | + $sql = "select $fields FROM". |
|
| 618 | 618 | "(SELECT rownum as adodb_rownum, $fields FROM". |
| 619 | 619 | " ($sql) WHERE rownum <= :adodb_nrows". |
| 620 | 620 | ") WHERE adodb_rownum >= :adodb_offset"; |
@@ -661,9 +661,9 @@ discard block |
||
| 661 | 661 | } |
| 662 | 662 | |
| 663 | 663 | if ($this->databaseType == 'oci8po') |
| 664 | - $sql = "UPDATE $table set $column=EMPTY_{$blobtype}() WHERE $where RETURNING $column INTO ?"; |
|
| 664 | + $sql = "update $table set $column=EMPTY_{$blobtype}() WHERE $where RETURNING $column INTO ?"; |
|
| 665 | 665 | else |
| 666 | - $sql = "UPDATE $table set $column=EMPTY_{$blobtype}() WHERE $where RETURNING $column INTO :blob"; |
|
| 666 | + $sql = "update $table set $column=EMPTY_{$blobtype}() WHERE $where RETURNING $column INTO :blob"; |
|
| 667 | 667 | |
| 668 | 668 | $desc = OCINewDescriptor($this->_connectionID, OCI_D_LOB); |
| 669 | 669 | $arr['blob'] = array($desc,-1,$type); |
@@ -692,9 +692,9 @@ discard block |
||
| 692 | 692 | } |
| 693 | 693 | |
| 694 | 694 | if ($this->databaseType == 'oci8po') |
| 695 | - $sql = "UPDATE $table set $column=EMPTY_{$blobtype}() WHERE $where RETURNING $column INTO ?"; |
|
| 695 | + $sql = "update $table set $column=EMPTY_{$blobtype}() WHERE $where RETURNING $column INTO ?"; |
|
| 696 | 696 | else |
| 697 | - $sql = "UPDATE $table set $column=EMPTY_{$blobtype}() WHERE $where RETURNING $column INTO :blob"; |
|
| 697 | + $sql = "update $table set $column=EMPTY_{$blobtype}() WHERE $where RETURNING $column INTO :blob"; |
|
| 698 | 698 | |
| 699 | 699 | $desc = OCINewDescriptor($this->_connectionID, OCI_D_LOB); |
| 700 | 700 | $arr['blob'] = array($desc,-1,$type); |
@@ -155,6 +155,10 @@ |
||
| 155 | 155 | |
| 156 | 156 | |
| 157 | 157 | // returns query ID if successful, otherwise false |
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * @param string $sql |
|
| 161 | + */ |
|
| 158 | 162 | function _query($sql,$inputarr=false) |
| 159 | 163 | { |
| 160 | 164 | // <G. Giunta 2003/03/03/> Reset error messages before executing |
@@ -95,9 +95,9 @@ discard block |
||
| 95 | 95 | /* there seems to be a bug in the oracle extension -- always returns ORA-00000 - no error */ |
| 96 | 96 | function ErrorMsg() |
| 97 | 97 | { |
| 98 | - if ($this->_errorMsg !== false) return $this->_errorMsg; |
|
| 98 | + if ($this->_errorMsg !== false) return $this->_errorMsg; |
|
| 99 | 99 | |
| 100 | - if (is_resource($this->_curs)) $this->_errorMsg = @ora_error($this->_curs); |
|
| 100 | + if (is_resource($this->_curs)) $this->_errorMsg = @ora_error($this->_curs); |
|
| 101 | 101 | if (empty($this->_errorMsg)) $this->_errorMsg = @ora_error($this->_connectionID); |
| 102 | 102 | return $this->_errorMsg; |
| 103 | 103 | } |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | |
| 110 | 110 | if (is_resource($this->_curs)) $this->_errorCode = @ora_errorcode($this->_curs); |
| 111 | 111 | if (empty($this->_errorCode)) $this->_errorCode = @ora_errorcode($this->_connectionID); |
| 112 | - return $this->_errorCode; |
|
| 112 | + return $this->_errorCode; |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | |
@@ -119,12 +119,12 @@ discard block |
||
| 119 | 119 | { |
| 120 | 120 | if (!function_exists('ora_plogon')) return null; |
| 121 | 121 | |
| 122 | - // <G. Giunta 2003/03/03/> Reset error messages before connecting |
|
| 123 | - $this->_errorMsg = false; |
|
| 124 | - $this->_errorCode = false; |
|
| 122 | + // <G. Giunta 2003/03/03/> Reset error messages before connecting |
|
| 123 | + $this->_errorMsg = false; |
|
| 124 | + $this->_errorCode = false; |
|
| 125 | 125 | |
| 126 | - // G. Giunta 2003/08/13 - This looks danegrously suspicious: why should we want to set |
|
| 127 | - // the oracle home to the host name of remote DB? |
|
| 126 | + // G. Giunta 2003/08/13 - This looks danegrously suspicious: why should we want to set |
|
| 127 | + // the oracle home to the host name of remote DB? |
|
| 128 | 128 | // if ($argHostname) putenv("ORACLE_HOME=$argHostname"); |
| 129 | 129 | |
| 130 | 130 | if($argHostname) { // code copied from version submitted for oci8 by Jorma Tuomainen <[email protected]> |
@@ -177,9 +177,9 @@ discard block |
||
| 177 | 177 | // returns query ID if successful, otherwise false |
| 178 | 178 | function _query($sql,$inputarr=false) |
| 179 | 179 | { |
| 180 | - // <G. Giunta 2003/03/03/> Reset error messages before executing |
|
| 181 | - $this->_errorMsg = false; |
|
| 182 | - $this->_errorCode = false; |
|
| 180 | + // <G. Giunta 2003/03/03/> Reset error messages before executing |
|
| 181 | + $this->_errorMsg = false; |
|
| 182 | + $this->_errorCode = false; |
|
| 183 | 183 | |
| 184 | 184 | $curs = ora_open($this->_connectionID); |
| 185 | 185 | |
@@ -187,11 +187,11 @@ discard block |
||
| 187 | 187 | $this->_curs = $curs; |
| 188 | 188 | if (!ora_parse($curs,$sql)) return false; |
| 189 | 189 | if (ora_exec($curs)) return $curs; |
| 190 | - // <G. Giunta 2004/03/03> before we close the cursor, we have to store the error message |
|
| 191 | - // that we can obtain ONLY from the cursor (and not from the connection) |
|
| 192 | - $this->_errorCode = @ora_errorcode($curs); |
|
| 193 | - $this->_errorMsg = @ora_error($curs); |
|
| 194 | - // </G. Giunta 2004/03/03> |
|
| 190 | + // <G. Giunta 2004/03/03> before we close the cursor, we have to store the error message |
|
| 191 | + // that we can obtain ONLY from the cursor (and not from the connection) |
|
| 192 | + $this->_errorCode = @ora_errorcode($curs); |
|
| 193 | + $this->_errorMsg = @ora_error($curs); |
|
| 194 | + // </G. Giunta 2004/03/03> |
|
| 195 | 195 | @ora_close($curs); |
| 196 | 196 | return false; |
| 197 | 197 | } |
@@ -310,30 +310,30 @@ |
||
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | switch (strtoupper($t)) { |
| 313 | - case 'VARCHAR': |
|
| 314 | - case 'VARCHAR2': |
|
| 315 | - case 'CHAR': |
|
| 316 | - case 'VARBINARY': |
|
| 317 | - case 'BINARY': |
|
| 318 | - if ($len <= $this->blobSize) return 'C'; |
|
| 319 | - case 'LONG': |
|
| 320 | - case 'LONG VARCHAR': |
|
| 321 | - case 'CLOB': |
|
| 322 | - return 'X'; |
|
| 323 | - case 'LONG RAW': |
|
| 324 | - case 'LONG VARBINARY': |
|
| 325 | - case 'BLOB': |
|
| 326 | - return 'B'; |
|
| 327 | - |
|
| 328 | - case 'DATE': return 'D'; |
|
| 329 | - |
|
| 330 | - //case 'T': return 'T'; |
|
| 331 | - |
|
| 332 | - case 'BIT': return 'L'; |
|
| 333 | - case 'INT': |
|
| 334 | - case 'SMALLINT': |
|
| 335 | - case 'INTEGER': return 'I'; |
|
| 336 | - default: return 'N'; |
|
| 313 | + case 'VARCHAR': |
|
| 314 | + case 'VARCHAR2': |
|
| 315 | + case 'CHAR': |
|
| 316 | + case 'VARBINARY': |
|
| 317 | + case 'BINARY': |
|
| 318 | + if ($len <= $this->blobSize) return 'C'; |
|
| 319 | + case 'LONG': |
|
| 320 | + case 'LONG VARCHAR': |
|
| 321 | + case 'CLOB': |
|
| 322 | + return 'X'; |
|
| 323 | + case 'LONG RAW': |
|
| 324 | + case 'LONG VARBINARY': |
|
| 325 | + case 'BLOB': |
|
| 326 | + return 'B'; |
|
| 327 | + |
|
| 328 | + case 'DATE': return 'D'; |
|
| 329 | + |
|
| 330 | + //case 'T': return 'T'; |
|
| 331 | + |
|
| 332 | + case 'BIT': return 'L'; |
|
| 333 | + case 'INT': |
|
| 334 | + case 'SMALLINT': |
|
| 335 | + case 'INTEGER': return 'I'; |
|
| 336 | + default: return 'N'; |
|
| 337 | 337 | } |
| 338 | 338 | } |
| 339 | 339 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | class ADODB_oracle extends ADOConnection { |
| 21 | 21 | var $databaseType = "oracle"; |
| 22 | 22 | var $replaceQuote = "''"; // string to use to replace quotes |
| 23 | - var $concat_operator='||'; |
|
| 23 | + var $concat_operator = '||'; |
|
| 24 | 24 | var $_curs; |
| 25 | 25 | var $_initdate = true; // init date to YYYY-MM-DD |
| 26 | 26 | var $metaTablesSQL = 'select table_name from cat'; |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | { |
| 35 | 35 | if (is_string($d)) $d = ADORecordSet::UnixDate($d); |
| 36 | 36 | if (is_object($d)) $ds = $d->format($this->fmtDate); |
| 37 | - else $ds = adodb_date($this->fmtDate,$d); |
|
| 37 | + else $ds = adodb_date($this->fmtDate, $d); |
|
| 38 | 38 | return 'TO_DATE('.$ds.",'YYYY-MM-DD')"; |
| 39 | 39 | } |
| 40 | 40 | |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | |
| 45 | 45 | if (is_string($ts)) $ts = ADORecordSet::UnixTimeStamp($ts); |
| 46 | 46 | if (is_object($ts)) $ds = $ts->format($this->fmtDate); |
| 47 | - else $ds = adodb_date($this->fmtTimeStamp,$ts); |
|
| 47 | + else $ds = adodb_date($this->fmtTimeStamp, $ts); |
|
| 48 | 48 | return 'TO_DATE('.$ds.",'RRRR-MM-DD, HH:MI:SS AM')"; |
| 49 | 49 | } |
| 50 | 50 | |
@@ -52,17 +52,17 @@ discard block |
||
| 52 | 52 | function BindDate($d) |
| 53 | 53 | { |
| 54 | 54 | $d = ADOConnection::DBDate($d); |
| 55 | - if (strncmp($d,"'",1)) return $d; |
|
| 55 | + if (strncmp($d, "'", 1)) return $d; |
|
| 56 | 56 | |
| 57 | - return substr($d,1,strlen($d)-2); |
|
| 57 | + return substr($d, 1, strlen($d) - 2); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | function BindTimeStamp($d) |
| 61 | 61 | { |
| 62 | 62 | $d = ADOConnection::DBTimeStamp($d); |
| 63 | - if (strncmp($d,"'",1)) return $d; |
|
| 63 | + if (strncmp($d, "'", 1)) return $d; |
|
| 64 | 64 | |
| 65 | - return substr($d,1,strlen($d)-2); |
|
| 65 | + return substr($d, 1, strlen($d) - 2); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | |
| 78 | - function CommitTrans($ok=true) |
|
| 78 | + function CommitTrans($ok = true) |
|
| 79 | 79 | { |
| 80 | 80 | if (!$ok) return $this->RollbackTrans(); |
| 81 | 81 | $ret = ora_commit($this->_connectionID); |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | |
| 116 | 116 | |
| 117 | 117 | // returns true or false |
| 118 | - function _connect($argHostname, $argUsername, $argPassword, $argDatabasename, $mode=0) |
|
| 118 | + function _connect($argHostname, $argUsername, $argPassword, $argDatabasename, $mode = 0) |
|
| 119 | 119 | { |
| 120 | 120 | if (!function_exists('ora_plogon')) return null; |
| 121 | 121 | |
@@ -127,23 +127,23 @@ discard block |
||
| 127 | 127 | // the oracle home to the host name of remote DB? |
| 128 | 128 | // if ($argHostname) putenv("ORACLE_HOME=$argHostname"); |
| 129 | 129 | |
| 130 | - if($argHostname) { // code copied from version submitted for oci8 by Jorma Tuomainen <[email protected]> |
|
| 130 | + if ($argHostname) { // code copied from version submitted for oci8 by Jorma Tuomainen <[email protected]> |
|
| 131 | 131 | if (empty($argDatabasename)) $argDatabasename = $argHostname; |
| 132 | 132 | else { |
| 133 | - if(strpos($argHostname,":")) { |
|
| 134 | - $argHostinfo=explode(":",$argHostname); |
|
| 135 | - $argHostname=$argHostinfo[0]; |
|
| 136 | - $argHostport=$argHostinfo[1]; |
|
| 133 | + if (strpos($argHostname, ":")) { |
|
| 134 | + $argHostinfo = explode(":", $argHostname); |
|
| 135 | + $argHostname = $argHostinfo[0]; |
|
| 136 | + $argHostport = $argHostinfo[1]; |
|
| 137 | 137 | } else { |
| 138 | - $argHostport="1521"; |
|
| 138 | + $argHostport = "1521"; |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | |
| 142 | 142 | if ($this->connectSID) { |
| 143 | - $argDatabasename="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=".$argHostname |
|
| 143 | + $argDatabasename = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=".$argHostname |
|
| 144 | 144 | .")(PORT=$argHostport))(CONNECT_DATA=(SID=$argDatabasename)))"; |
| 145 | 145 | } else |
| 146 | - $argDatabasename="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=".$argHostname |
|
| 146 | + $argDatabasename = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=".$argHostname |
|
| 147 | 147 | .")(PORT=$argHostport))(CONNECT_DATA=(SERVICE_NAME=$argDatabasename)))"; |
| 148 | 148 | } |
| 149 | 149 | |
@@ -153,9 +153,9 @@ discard block |
||
| 153 | 153 | |
| 154 | 154 | //if ($argHostname) print "<p>Connect: 1st argument should be left blank for $this->databaseType</p>"; |
| 155 | 155 | if ($mode == 1) |
| 156 | - $this->_connectionID = ora_plogon($argUsername,$argPassword); |
|
| 156 | + $this->_connectionID = ora_plogon($argUsername, $argPassword); |
|
| 157 | 157 | else |
| 158 | - $this->_connectionID = ora_logon($argUsername,$argPassword); |
|
| 158 | + $this->_connectionID = ora_logon($argUsername, $argPassword); |
|
| 159 | 159 | if ($this->_connectionID === false) return false; |
| 160 | 160 | if ($this->autoCommit) ora_commiton($this->_connectionID); |
| 161 | 161 | if ($this->_initdate) { |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | |
| 176 | 176 | |
| 177 | 177 | // returns query ID if successful, otherwise false |
| 178 | - function _query($sql,$inputarr=false) |
|
| 178 | + function _query($sql, $inputarr = false) |
|
| 179 | 179 | { |
| 180 | 180 | // <G. Giunta 2003/03/03/> Reset error messages before executing |
| 181 | 181 | $this->_errorMsg = false; |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | |
| 186 | 186 | if ($curs === false) return false; |
| 187 | 187 | $this->_curs = $curs; |
| 188 | - if (!ora_parse($curs,$sql)) return false; |
|
| 188 | + if (!ora_parse($curs, $sql)) return false; |
|
| 189 | 189 | if (ora_exec($curs)) return $curs; |
| 190 | 190 | // <G. Giunta 2004/03/03> before we close the cursor, we have to store the error message |
| 191 | 191 | // that we can obtain ONLY from the cursor (and not from the connection) |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | var $databaseType = "oracle"; |
| 218 | 218 | var $bind = false; |
| 219 | 219 | |
| 220 | - function __construct($queryID,$mode=false) |
|
| 220 | + function __construct($queryID, $mode = false) |
|
| 221 | 221 | { |
| 222 | 222 | |
| 223 | 223 | if ($mode === false) { |
@@ -264,7 +264,7 @@ discard block |
||
| 264 | 264 | { |
| 265 | 265 | if (!$this->bind) { |
| 266 | 266 | $this->bind = array(); |
| 267 | - for ($i=0; $i < $this->_numOfFields; $i++) { |
|
| 267 | + for ($i = 0; $i < $this->_numOfFields; $i++) { |
|
| 268 | 268 | $o = $this->FetchField($i); |
| 269 | 269 | $this->bind[strtoupper($o->name)] = $i; |
| 270 | 270 | } |
@@ -285,12 +285,12 @@ discard block |
||
| 285 | 285 | return false; |
| 286 | 286 | } |
| 287 | 287 | |
| 288 | - function _fetch($ignore_fields=false) { |
|
| 288 | + function _fetch($ignore_fields = false) { |
|
| 289 | 289 | // should remove call by reference, but ora_fetch_into requires it in 4.0.3pl1 |
| 290 | - if ($this->fetchMode & ADODB_FETCH_ASSOC) |
|
| 291 | - return @ora_fetch_into($this->_queryID,$this->fields,ORA_FETCHINTO_NULLS|ORA_FETCHINTO_ASSOC); |
|
| 290 | + if ($this->fetchMode&ADODB_FETCH_ASSOC) |
|
| 291 | + return @ora_fetch_into($this->_queryID, $this->fields, ORA_FETCHINTO_NULLS|ORA_FETCHINTO_ASSOC); |
|
| 292 | 292 | else |
| 293 | - return @ora_fetch_into($this->_queryID,$this->fields,ORA_FETCHINTO_NULLS); |
|
| 293 | + return @ora_fetch_into($this->_queryID, $this->fields, ORA_FETCHINTO_NULLS); |
|
| 294 | 294 | } |
| 295 | 295 | |
| 296 | 296 | /* close() only needs to be called if you are worried about using too much memory while your script |
@@ -15,9 +15,13 @@ discard block |
||
| 15 | 15 | */ |
| 16 | 16 | |
| 17 | 17 | // security - hide paths |
| 18 | -if (!defined('ADODB_DIR')) die(); |
|
| 18 | +if (!defined('ADODB_DIR')) |
|
| 19 | +{ |
|
| 20 | + die(); |
|
| 21 | +} |
|
| 19 | 22 | |
| 20 | -class ADODB_oracle extends ADOConnection { |
|
| 23 | +class ADODB_oracle extends ADOConnection |
|
| 24 | +{ |
|
| 21 | 25 | var $databaseType = "oracle"; |
| 22 | 26 | var $replaceQuote = "''"; // string to use to replace quotes |
| 23 | 27 | var $concat_operator='||'; |
@@ -32,9 +36,17 @@ discard block |
||
| 32 | 36 | // format and return date string in database date format |
| 33 | 37 | function DBDate($d, $isfld = false) |
| 34 | 38 | { |
| 35 | - if (is_string($d)) $d = ADORecordSet::UnixDate($d); |
|
| 36 | - if (is_object($d)) $ds = $d->format($this->fmtDate); |
|
| 37 | - else $ds = adodb_date($this->fmtDate,$d); |
|
| 39 | + if (is_string($d)) |
|
| 40 | + { |
|
| 41 | + $d = ADORecordSet::UnixDate($d); |
|
| 42 | + } |
|
| 43 | + if (is_object($d)) |
|
| 44 | + { |
|
| 45 | + $ds = $d->format($this->fmtDate); |
|
| 46 | + } |
|
| 47 | + else { |
|
| 48 | + $ds = adodb_date($this->fmtDate,$d); |
|
| 49 | + } |
|
| 38 | 50 | return 'TO_DATE('.$ds.",'YYYY-MM-DD')"; |
| 39 | 51 | } |
| 40 | 52 | |
@@ -42,9 +54,17 @@ discard block |
||
| 42 | 54 | function DBTimeStamp($ts, $isfld = false) |
| 43 | 55 | { |
| 44 | 56 | |
| 45 | - if (is_string($ts)) $ts = ADORecordSet::UnixTimeStamp($ts); |
|
| 46 | - if (is_object($ts)) $ds = $ts->format($this->fmtDate); |
|
| 47 | - else $ds = adodb_date($this->fmtTimeStamp,$ts); |
|
| 57 | + if (is_string($ts)) |
|
| 58 | + { |
|
| 59 | + $ts = ADORecordSet::UnixTimeStamp($ts); |
|
| 60 | + } |
|
| 61 | + if (is_object($ts)) |
|
| 62 | + { |
|
| 63 | + $ds = $ts->format($this->fmtDate); |
|
| 64 | + } |
|
| 65 | + else { |
|
| 66 | + $ds = adodb_date($this->fmtTimeStamp,$ts); |
|
| 67 | + } |
|
| 48 | 68 | return 'TO_DATE('.$ds.",'RRRR-MM-DD, HH:MI:SS AM')"; |
| 49 | 69 | } |
| 50 | 70 | |
@@ -52,7 +72,10 @@ discard block |
||
| 52 | 72 | function BindDate($d) |
| 53 | 73 | { |
| 54 | 74 | $d = ADOConnection::DBDate($d); |
| 55 | - if (strncmp($d,"'",1)) return $d; |
|
| 75 | + if (strncmp($d,"'",1)) |
|
| 76 | + { |
|
| 77 | + return $d; |
|
| 78 | + } |
|
| 56 | 79 | |
| 57 | 80 | return substr($d,1,strlen($d)-2); |
| 58 | 81 | } |
@@ -60,7 +83,10 @@ discard block |
||
| 60 | 83 | function BindTimeStamp($d) |
| 61 | 84 | { |
| 62 | 85 | $d = ADOConnection::DBTimeStamp($d); |
| 63 | - if (strncmp($d,"'",1)) return $d; |
|
| 86 | + if (strncmp($d,"'",1)) |
|
| 87 | + { |
|
| 88 | + return $d; |
|
| 89 | + } |
|
| 64 | 90 | |
| 65 | 91 | return substr($d,1,strlen($d)-2); |
| 66 | 92 | } |
@@ -77,7 +103,10 @@ discard block |
||
| 77 | 103 | |
| 78 | 104 | function CommitTrans($ok=true) |
| 79 | 105 | { |
| 80 | - if (!$ok) return $this->RollbackTrans(); |
|
| 106 | + if (!$ok) |
|
| 107 | + { |
|
| 108 | + return $this->RollbackTrans(); |
|
| 109 | + } |
|
| 81 | 110 | $ret = ora_commit($this->_connectionID); |
| 82 | 111 | ora_commiton($this->_connectionID); |
| 83 | 112 | return $ret; |
@@ -94,21 +123,39 @@ discard block |
||
| 94 | 123 | |
| 95 | 124 | /* there seems to be a bug in the oracle extension -- always returns ORA-00000 - no error */ |
| 96 | 125 | function ErrorMsg() |
| 97 | - { |
|
| 98 | - if ($this->_errorMsg !== false) return $this->_errorMsg; |
|
| 99 | - |
|
| 100 | - if (is_resource($this->_curs)) $this->_errorMsg = @ora_error($this->_curs); |
|
| 101 | - if (empty($this->_errorMsg)) $this->_errorMsg = @ora_error($this->_connectionID); |
|
| 126 | + { |
|
| 127 | + if ($this->_errorMsg !== false) |
|
| 128 | + { |
|
| 129 | + return $this->_errorMsg; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + if (is_resource($this->_curs)) |
|
| 133 | + { |
|
| 134 | + $this->_errorMsg = @ora_error($this->_curs); |
|
| 135 | + } |
|
| 136 | + if (empty($this->_errorMsg)) |
|
| 137 | + { |
|
| 138 | + $this->_errorMsg = @ora_error($this->_connectionID); |
|
| 139 | + } |
|
| 102 | 140 | return $this->_errorMsg; |
| 103 | 141 | } |
| 104 | 142 | |
| 105 | 143 | |
| 106 | 144 | function ErrorNo() |
| 107 | 145 | { |
| 108 | - if ($this->_errorCode !== false) return $this->_errorCode; |
|
| 146 | + if ($this->_errorCode !== false) |
|
| 147 | + { |
|
| 148 | + return $this->_errorCode; |
|
| 149 | + } |
|
| 109 | 150 | |
| 110 | - if (is_resource($this->_curs)) $this->_errorCode = @ora_errorcode($this->_curs); |
|
| 111 | - if (empty($this->_errorCode)) $this->_errorCode = @ora_errorcode($this->_connectionID); |
|
| 151 | + if (is_resource($this->_curs)) |
|
| 152 | + { |
|
| 153 | + $this->_errorCode = @ora_errorcode($this->_curs); |
|
| 154 | + } |
|
| 155 | + if (empty($this->_errorCode)) |
|
| 156 | + { |
|
| 157 | + $this->_errorCode = @ora_errorcode($this->_connectionID); |
|
| 158 | + } |
|
| 112 | 159 | return $this->_errorCode; |
| 113 | 160 | } |
| 114 | 161 | |
@@ -117,7 +164,10 @@ discard block |
||
| 117 | 164 | // returns true or false |
| 118 | 165 | function _connect($argHostname, $argUsername, $argPassword, $argDatabasename, $mode=0) |
| 119 | 166 | { |
| 120 | - if (!function_exists('ora_plogon')) return null; |
|
| 167 | + if (!function_exists('ora_plogon')) |
|
| 168 | + { |
|
| 169 | + return null; |
|
| 170 | + } |
|
| 121 | 171 | |
| 122 | 172 | // <G. Giunta 2003/03/03/> Reset error messages before connecting |
| 123 | 173 | $this->_errorMsg = false; |
@@ -127,40 +177,68 @@ discard block |
||
| 127 | 177 | // the oracle home to the host name of remote DB? |
| 128 | 178 | // if ($argHostname) putenv("ORACLE_HOME=$argHostname"); |
| 129 | 179 | |
| 130 | - if($argHostname) { // code copied from version submitted for oci8 by Jorma Tuomainen <[email protected]> |
|
| 131 | - if (empty($argDatabasename)) $argDatabasename = $argHostname; |
|
| 132 | - else { |
|
| 133 | - if(strpos($argHostname,":")) { |
|
| 180 | + if($argHostname) |
|
| 181 | + { |
|
| 182 | +// code copied from version submitted for oci8 by Jorma Tuomainen <[email protected]> |
|
| 183 | + if (empty($argDatabasename)) |
|
| 184 | + { |
|
| 185 | + $argDatabasename = $argHostname; |
|
| 186 | + } |
|
| 187 | + else |
|
| 188 | + { |
|
| 189 | + if(strpos($argHostname,":")) |
|
| 190 | + { |
|
| 134 | 191 | $argHostinfo=explode(":",$argHostname); |
| 135 | 192 | $argHostname=$argHostinfo[0]; |
| 136 | 193 | $argHostport=$argHostinfo[1]; |
| 137 | - } else { |
|
| 194 | + } |
|
| 195 | + else |
|
| 196 | + { |
|
| 138 | 197 | $argHostport="1521"; |
| 139 | 198 | } |
| 140 | 199 | |
| 141 | 200 | |
| 142 | - if ($this->connectSID) { |
|
| 201 | + if ($this->connectSID) |
|
| 202 | + { |
|
| 143 | 203 | $argDatabasename="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=".$argHostname |
| 144 | 204 | .")(PORT=$argHostport))(CONNECT_DATA=(SID=$argDatabasename)))"; |
| 145 | - } else |
|
| 146 | - $argDatabasename="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=".$argHostname |
|
| 205 | + } |
|
| 206 | + else { |
|
| 207 | + $argDatabasename="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=".$argHostname |
|
| 147 | 208 | .")(PORT=$argHostport))(CONNECT_DATA=(SERVICE_NAME=$argDatabasename)))"; |
| 209 | + } |
|
| 148 | 210 | } |
| 149 | 211 | |
| 150 | 212 | } |
| 151 | 213 | |
| 152 | - if ($argDatabasename) $argUsername .= "@$argDatabasename"; |
|
| 214 | + if ($argDatabasename) |
|
| 215 | + { |
|
| 216 | + $argUsername .= "@$argDatabasename"; |
|
| 217 | + } |
|
| 153 | 218 | |
| 154 | 219 | //if ($argHostname) print "<p>Connect: 1st argument should be left blank for $this->databaseType</p>"; |
| 155 | 220 | if ($mode == 1) |
| 156 | - $this->_connectionID = ora_plogon($argUsername,$argPassword); |
|
| 157 | - else |
|
| 158 | - $this->_connectionID = ora_logon($argUsername,$argPassword); |
|
| 159 | - if ($this->_connectionID === false) return false; |
|
| 160 | - if ($this->autoCommit) ora_commiton($this->_connectionID); |
|
| 161 | - if ($this->_initdate) { |
|
| 221 | + { |
|
| 222 | + $this->_connectionID = ora_plogon($argUsername,$argPassword); |
|
| 223 | + } |
|
| 224 | + else { |
|
| 225 | + $this->_connectionID = ora_logon($argUsername,$argPassword); |
|
| 226 | + } |
|
| 227 | + if ($this->_connectionID === false) |
|
| 228 | + { |
|
| 229 | + return false; |
|
| 230 | + } |
|
| 231 | + if ($this->autoCommit) |
|
| 232 | + { |
|
| 233 | + ora_commiton($this->_connectionID); |
|
| 234 | + } |
|
| 235 | + if ($this->_initdate) |
|
| 236 | + { |
|
| 162 | 237 | $rs = $this->_query("ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD'"); |
| 163 | - if ($rs) ora_close($rs); |
|
| 238 | + if ($rs) |
|
| 239 | + { |
|
| 240 | + ora_close($rs); |
|
| 241 | + } |
|
| 164 | 242 | } |
| 165 | 243 | |
| 166 | 244 | return true; |
@@ -183,10 +261,19 @@ discard block |
||
| 183 | 261 | |
| 184 | 262 | $curs = ora_open($this->_connectionID); |
| 185 | 263 | |
| 186 | - if ($curs === false) return false; |
|
| 264 | + if ($curs === false) |
|
| 265 | + { |
|
| 266 | + return false; |
|
| 267 | + } |
|
| 187 | 268 | $this->_curs = $curs; |
| 188 | - if (!ora_parse($curs,$sql)) return false; |
|
| 189 | - if (ora_exec($curs)) return $curs; |
|
| 269 | + if (!ora_parse($curs,$sql)) |
|
| 270 | + { |
|
| 271 | + return false; |
|
| 272 | + } |
|
| 273 | + if (ora_exec($curs)) |
|
| 274 | + { |
|
| 275 | + return $curs; |
|
| 276 | + } |
|
| 190 | 277 | // <G. Giunta 2004/03/03> before we close the cursor, we have to store the error message |
| 191 | 278 | // that we can obtain ONLY from the cursor (and not from the connection) |
| 192 | 279 | $this->_errorCode = @ora_errorcode($curs); |
@@ -212,7 +299,8 @@ discard block |
||
| 212 | 299 | Class Name: Recordset |
| 213 | 300 | --------------------------------------------------------------------------------------*/ |
| 214 | 301 | |
| 215 | -class ADORecordset_oracle extends ADORecordSet { |
|
| 302 | +class ADORecordset_oracle extends ADORecordSet |
|
| 303 | +{ |
|
| 216 | 304 | |
| 217 | 305 | var $databaseType = "oracle"; |
| 218 | 306 | var $bind = false; |
@@ -220,7 +308,8 @@ discard block |
||
| 220 | 308 | function __construct($queryID,$mode=false) |
| 221 | 309 | { |
| 222 | 310 | |
| 223 | - if ($mode === false) { |
|
| 311 | + if ($mode === false) |
|
| 312 | + { |
|
| 224 | 313 | global $ADODB_FETCH_MODE; |
| 225 | 314 | $mode = $ADODB_FETCH_MODE; |
| 226 | 315 | } |
@@ -230,11 +319,14 @@ discard block |
||
| 230 | 319 | |
| 231 | 320 | $this->_inited = true; |
| 232 | 321 | $this->fields = array(); |
| 233 | - if ($queryID) { |
|
| 322 | + if ($queryID) |
|
| 323 | + { |
|
| 234 | 324 | $this->_currentRow = 0; |
| 235 | 325 | $this->EOF = !$this->_fetch(); |
| 236 | 326 | @$this->_initrs(); |
| 237 | - } else { |
|
| 327 | + } |
|
| 328 | + else |
|
| 329 | + { |
|
| 238 | 330 | $this->_numOfRows = 0; |
| 239 | 331 | $this->_numOfFields = 0; |
| 240 | 332 | $this->EOF = true; |
@@ -262,9 +354,11 @@ discard block |
||
| 262 | 354 | /* Use associative array to get fields array */ |
| 263 | 355 | function Fields($colname) |
| 264 | 356 | { |
| 265 | - if (!$this->bind) { |
|
| 357 | + if (!$this->bind) |
|
| 358 | + { |
|
| 266 | 359 | $this->bind = array(); |
| 267 | - for ($i=0; $i < $this->_numOfFields; $i++) { |
|
| 360 | + for ($i=0; $i < $this->_numOfFields; $i++) |
|
| 361 | + { |
|
| 268 | 362 | $o = $this->FetchField($i); |
| 269 | 363 | $this->bind[strtoupper($o->name)] = $i; |
| 270 | 364 | } |
@@ -285,37 +379,46 @@ discard block |
||
| 285 | 379 | return false; |
| 286 | 380 | } |
| 287 | 381 | |
| 288 | - function _fetch($ignore_fields=false) { |
|
| 382 | + function _fetch($ignore_fields=false) |
|
| 383 | + { |
|
| 289 | 384 | // should remove call by reference, but ora_fetch_into requires it in 4.0.3pl1 |
| 290 | 385 | if ($this->fetchMode & ADODB_FETCH_ASSOC) |
| 291 | - return @ora_fetch_into($this->_queryID,$this->fields,ORA_FETCHINTO_NULLS|ORA_FETCHINTO_ASSOC); |
|
| 292 | - else |
|
| 293 | - return @ora_fetch_into($this->_queryID,$this->fields,ORA_FETCHINTO_NULLS); |
|
| 386 | + { |
|
| 387 | + return @ora_fetch_into($this->_queryID,$this->fields,ORA_FETCHINTO_NULLS|ORA_FETCHINTO_ASSOC); |
|
| 388 | + } |
|
| 389 | + else { |
|
| 390 | + return @ora_fetch_into($this->_queryID,$this->fields,ORA_FETCHINTO_NULLS); |
|
| 391 | + } |
|
| 294 | 392 | } |
| 295 | 393 | |
| 296 | 394 | /* close() only needs to be called if you are worried about using too much memory while your script |
| 297 | 395 | is running. All associated result memory for the specified result identifier will automatically be freed. */ |
| 298 | 396 | |
| 299 | 397 | function _close() |
| 300 | -{ |
|
| 398 | + { |
|
| 301 | 399 | return @ora_close($this->_queryID); |
| 302 | 400 | } |
| 303 | 401 | |
| 304 | 402 | function MetaType($t, $len = -1, $fieldobj = false) |
| 305 | 403 | { |
| 306 | - if (is_object($t)) { |
|
| 404 | + if (is_object($t)) |
|
| 405 | + { |
|
| 307 | 406 | $fieldobj = $t; |
| 308 | 407 | $t = $fieldobj->type; |
| 309 | 408 | $len = $fieldobj->max_length; |
| 310 | 409 | } |
| 311 | 410 | |
| 312 | - switch (strtoupper($t)) { |
|
| 411 | + switch (strtoupper($t)) |
|
| 412 | + { |
|
| 313 | 413 | case 'VARCHAR': |
| 314 | 414 | case 'VARCHAR2': |
| 315 | 415 | case 'CHAR': |
| 316 | 416 | case 'VARBINARY': |
| 317 | 417 | case 'BINARY': |
| 318 | - if ($len <= $this->blobSize) return 'C'; |
|
| 418 | + if ($len <= $this->blobSize) |
|
| 419 | + { |
|
| 420 | + return 'C'; |
|
| 421 | + } |
|
| 319 | 422 | case 'LONG': |
| 320 | 423 | case 'LONG VARCHAR': |
| 321 | 424 | case 'CLOB': |