00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 include_once( "lib/ezutils/classes/ezdebug.php" );
00042 include_once( "lib/ezutils/classes/ezini.php" );
00043
00044 define( 'EZ_DB_BINDING_NO', 0 );
00045 define( 'EZ_DB_BINDING_NAME', 1 );
00046 define( 'EZ_DB_BINDING_ORDERED', 2 );
00047
00048 define( 'EZ_DB_RELATION_TABLE', 0 );
00049 define( 'EZ_DB_RELATION_SEQUENCE', 1 );
00050 define( 'EZ_DB_RELATION_TRIGGER', 2 );
00051 define( 'EZ_DB_RELATION_VIEW', 3 );
00052 define( 'EZ_DB_RELATION_INDEX', 4 );
00053
00054 define( 'EZ_DB_RELATION_TABLE_BIT', (1 << EZ_DB_RELATION_TABLE) );
00055 define( 'EZ_DB_RELATION_SEQUENCE_BIT', (1 << EZ_DB_RELATION_SEQUENCE) );
00056 define( 'EZ_DB_RELATION_TRIGGER_BIT', (1 << EZ_DB_RELATION_TRIGGER) );
00057 define( 'EZ_DB_RELATION_VIEW_BIT', (1 << EZ_DB_RELATION_VIEW) );
00058 define( 'EZ_DB_RELATION_INDEX_BIT', (1 << EZ_DB_RELATION_INDEX) );
00059
00060 define( 'EZ_DB_RELATION_NONE', 0 );
00061 define( 'EZ_DB_RELATION_MASK', ( EZ_DB_RELATION_TABLE_BIT |
00062 EZ_DB_RELATION_SEQUENCE_BIT |
00063 EZ_DB_RELATION_TRIGGER_BIT |
00064 EZ_DB_RELATION_VIEW_BIT |
00065 EZ_DB_RELATION_INDEX_BIT ) );
00066
00067 define( 'EZ_DB_ERROR_MISSING_EXTENSION', 1 );
00068
00069 define( 'EZ_DB_SERVER_MASTER', 1 );
00070 define( 'EZ_DB_SERVER_SLAVE', 2 );
00071
00072 class eZDBInterface
00073 {
00074
00075
00076
00077 function eZDBInterface( $parameters )
00078 {
00079 $server = $parameters['server'];
00080 $user = $parameters['user'];
00081 $password = $parameters['password'];
00082 $db = $parameters['database'];
00083 $useSlaveServer = $parameters['use_slave_server'];
00084 $slaveServer = $parameters['slave_server'];
00085 $slaveUser = $parameters['slave_user'];
00086 $slavePassword = $parameters['slave_password'];
00087 $slaveDB = $parameters['slave_database'];
00088 $socketPath = $parameters['socket'];
00089 $charset = $parameters['charset'];
00090 $isInternalCharset = $parameters['is_internal_charset'];
00091 $builtinEncoding = $parameters['builtin_encoding'];
00092 $connectRetries = $parameters['connect_retries'];
00093
00094 if ( $parameters['use_persistent_connection'] == 'enabled' )
00095 {
00096 $this->UsePersistentConnection = true;
00097 }
00098
00099 $this->DB = $db;
00100 $this->Server = $server;
00101 $this->SocketPath = $socketPath;
00102 $this->User = $user;
00103 $this->Password = $password;
00104 $this->UseSlaveServer = $useSlaveServer;
00105 $this->SlaveDB = $slaveDB;
00106 $this->SlaveServer = $slaveServer;
00107 $this->SlaveUser = $slaveUser;
00108 $this->SlavePassword = $slavePassword;
00109 $this->Charset = $charset;
00110 $this->IsInternalCharset = $isInternalCharset;
00111 $this->UseBuiltinEncoding = $builtinEncoding;
00112 $this->ConnectRetries = $connectRetries;
00113 $this->DBConnection = false;
00114 $this->DBWriteConnection = false;
00115 $this->TransactionCounter = 0;
00116 $this->TransactionIsValid = false;
00117 $this->TransactionStackTree = false;
00118
00119 $this->OutputTextCodec = null;
00120 $this->InputTextCodec = null;
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130 {
00131 include_once( "lib/ezi18n/classes/eztextcodec.php" );
00132 $tmpOutputTextCodec =& eZTextCodec::instance( $charset, false, false );
00133 $tmpInputTextCodec =& eZTextCodec::instance( false, $charset, false );
00134 unset( $this->OutputTextCodec );
00135 unset( $this->InputTextCodec );
00136 $this->OutputTextCodec = null;
00137 $this->InputTextCodec = null;
00138
00139 if ( $tmpOutputTextCodec && $tmpInputTextCodec )
00140 {
00141 if ( $tmpOutputTextCodec->conversionRequired() && $tmpInputTextCodec->conversionRequired() )
00142 {
00143 $this->OutputTextCodec =& $tmpOutputTextCodec;
00144 $this->InputTextCodec =& $tmpInputTextCodec;
00145 }
00146 }
00147 }
00148
00149 $this->OutputSQL = false;
00150 $this->SlowSQLTimeout = 0;
00151 $ini =& eZINI::instance();
00152 if ( ( $ini->variable( "DatabaseSettings", "SQLOutput" ) == "enabled" ) and
00153 ( $ini->variable( "DebugSettings", "DebugOutput" ) == "enabled" ) )
00154 {
00155 $this->OutputSQL = true;
00156
00157 $this->SlowSQLTimeout = (int) $ini->variable( "DatabaseSettings", "SlowQueriesOutput" );
00158 }
00159 if ( $ini->variable( "DatabaseSettings", "DebugTransactions" ) == "enabled" )
00160 {
00161
00162 $this->TransactionStackTree = array();
00163 }
00164
00165 $this->QueryAnalysisOutput = false;
00166 if ( $ini->variable( "DatabaseSettings", "QueryAnalysisOutput" ) == "enabled" )
00167 {
00168 $this->QueryAnalysisOutput = true;
00169 }
00170
00171 $this->IsConnected = false;
00172 $this->NumQueries = 0;
00173 $this->StartTime = false;
00174 $this->EndTime = false;
00175 $this->TimeTaken = false;
00176
00177 $this->AttributeVariableMap = array(
00178 'database_name' => 'DB',
00179 'database_server' => 'Server',
00180 'database_socket_path' => 'SocketPath',
00181 'database_user' => 'User',
00182 'use_slave_server' => 'UseSlaveServer',
00183 'slave_database_name' => 'SlaveDB',
00184 'slave_database_server' => 'SlaveServer',
00185 'slave_database_user' => 'SlaveUser',
00186 'charset' => 'Charset',
00187 'is_internal_charset' => 'IsInternalCharset',
00188 'use_builting_encoding' => 'UseBuiltinEncoding',
00189 'retry_count' => 'ConnectRetries' );
00190 }
00191
00192
00193
00194
00195 function attributes()
00196 {
00197 return array_keys( $this->AttributeVariableMap );
00198 }
00199
00200
00201
00202
00203 function hasAttribute( $name )
00204 {
00205 if ( isset( $this->AttributeVariableMap[$name] ) )
00206 {
00207 return true;
00208 }
00209 return false;
00210 }
00211
00212
00213
00214
00215 function &attribute( $name )
00216 {
00217 if ( isset( $this->AttributeVariableMap[$name] ) )
00218 {
00219 $memberVariable = $this->AttributeVariableMap[$name];
00220 return $this->$memberVariable;
00221 }
00222 else
00223 {
00224 eZDebug::writeError( "Attribute '$name' does not exist", 'eZDBInterface::attribute' );
00225 $retValue = null;
00226 return $retValue;
00227 }
00228 }
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241 function checkCharset( $charset, &$currentCharset )
00242 {
00243 return true;
00244 }
00245
00246
00247
00248
00249
00250
00251
00252 function prepareSqlQuery( &$fd, &$buffer )
00253 {
00254
00255 $sqlQueryArray = array();
00256 while( count( $sqlQueryArray ) == 0 && !feof( $fd ) )
00257 {
00258 $buffer .= fread( $fd, 4096 );
00259 if ( $buffer )
00260 {
00261
00262 $sqlQuery = preg_replace( array( "/^#.*\n" . "/m",
00263 "#^/\*.*\*/\n" . "#m",
00264 "/^--.*\n" . "/m",
00265 "/\n|\r\n|\r/m" ),
00266 array( "",
00267 "",
00268 "",
00269 "\n" ),
00270 $buffer );
00271
00272 $sqlQueryArray = preg_split( "/;\n/m", $sqlQuery );
00273
00274 if ( preg_match( '/;\n/m', $sqlQueryArray[ count( $sqlQueryArray ) -1 ] ) )
00275 {
00276 $buffer = '';
00277 }
00278 else
00279 {
00280 $buffer = $sqlQueryArray[ count( $sqlQueryArray ) -1 ];
00281 array_splice( $sqlQueryArray, count( $sqlQueryArray ) -1 , 1 );
00282 }
00283 }
00284 else
00285 {
00286 return $sqlQueryArray;
00287 }
00288 }
00289 return $sqlQueryArray;
00290 }
00291
00292
00293
00294
00295
00296
00297 function insertFile( $path, $sqlFile, $usePathType = true )
00298 {
00299 $type = $this->databaseName();
00300
00301 include_once( 'lib/ezfile/classes/ezdir.php' );
00302 if ( $usePathType )
00303 $sqlFileName = eZDir::path( array( $path, $type, $sqlFile ) );
00304 else
00305 $sqlFileName = eZDir::path( array( $path, $sqlFile ) );
00306 $sqlFileHandler = fopen( $sqlFileName, 'rb' );
00307 $buffer = '';
00308 $done = false;
00309 while ( count( ( $sqlArray = $this->prepareSqlQuery( $sqlFileHandler, $buffer ) ) ) > 0 )
00310 {
00311
00312 $oldOutputSQL = $this->OutputSQL;
00313 $this->OutputSQL = false;
00314 if ( $sqlArray && is_array( $sqlArray ) )
00315 {
00316 $done = true;
00317 foreach( $sqlArray as $singleQuery )
00318 {
00319 $singleQuery = preg_replace( "/\n|\r\n|\r/", " ", $singleQuery );
00320 if ( preg_match( "#^ */(.+)$#", $singleQuery, $matches ) )
00321 {
00322 $singleQuery = $matches[1];
00323 }
00324 if ( trim( $singleQuery ) != "" )
00325 {
00326 $this->query( trim( $singleQuery ) );
00327 if ( $this->errorNumber() )
00328 {
00329 return false;
00330 }
00331 }
00332 }
00333
00334 }
00335 $this->OutputSQL = $oldOutputSQL;
00336 }
00337 return $done;
00338
00339 }
00340
00341
00342
00343
00344
00345 function reportQuery( $class, $sql, $numRows, $timeTaken )
00346 {
00347 $rowText = '';
00348 if ( $numRows !== false )
00349 {
00350 $rowText = "$numRows rows, ";
00351 }
00352
00353 $backgroundClass = ( $this->TransactionCounter > 0 ? "debugtransaction transactionlevel-$this->TransactionCounter" : "" );
00354 eZDebug::writeNotice( "$sql", "$class::query($rowText" . number_format( $timeTaken, 3 ) . " ms) query number per page:" . $this->NumQueries++, $backgroundClass );
00355 }
00356
00357
00358
00359
00360 function setIsSQLOutputEnabled( $enabled )
00361 {
00362 $this->OutputSQL = $enabled;
00363 }
00364
00365
00366
00367
00368
00369
00370 function startTimer()
00371 {
00372 $this->StartTime = microtime();
00373 }
00374
00375
00376
00377
00378
00379
00380 function endTimer()
00381 {
00382 $this->EndTime = microtime();
00383
00384 list($usec, $sec) = explode( " ", $this->StartTime );
00385 $start_val = ((float)$usec + (float)$sec);
00386 list($usec, $sec) = explode( " ", $this->EndTime );
00387 $end_val = ((float)$usec + (float)$sec);
00388 $this->TimeTaken = $end_val - $start_val;
00389 $this->TimeTaken *= 1000.0;
00390 }
00391
00392
00393
00394
00395
00396 function startTime()
00397 {
00398 return $this->StartTime;
00399 }
00400
00401
00402
00403
00404
00405 function endTime()
00406 {
00407 return $this->EndTime;
00408 }
00409
00410
00411
00412
00413
00414 function timeTaken()
00415 {
00416 return $this->TimeTaken;
00417 }
00418
00419
00420
00421
00422
00423
00424 function databaseName()
00425 {
00426 return '';
00427 }
00428
00429
00430
00431
00432 function socketPath()
00433 {
00434 return $this->SocketPath;
00435 }
00436
00437
00438
00439
00440 function connectRetryCount()
00441 {
00442 return $this->ConnectRetries;
00443 }
00444
00445
00446
00447
00448
00449 function connectRetryWaitTime()
00450 {
00451 return 3;
00452 }
00453
00454
00455
00456
00457
00458 function supportedRelationTypeMask()
00459 {
00460 return EZ_DB_RELATION_NONE;
00461 }
00462
00463
00464
00465
00466
00467 function useShortNames()
00468 {
00469 return false;
00470 }
00471
00472
00473
00474
00475
00476 function supportedRelationTypes()
00477 {
00478 return array();
00479 }
00480
00481
00482
00483
00484
00485 function subString( $string, $from, $len = null )
00486 {
00487 return '';
00488 }
00489
00490
00491
00492
00493
00494 function concatString( $strings = array() )
00495 {
00496 return '';
00497 }
00498
00499
00500
00501
00502
00503 function md5( $str )
00504 {
00505 return '';
00506 }
00507
00508
00509
00510
00511
00512 function bitAnd( $arg1, $arg2 )
00513 {
00514 return '(' . $arg1 . ' & ' . $arg2 . ' ) ';
00515 }
00516
00517
00518
00519
00520
00521 function bitOr( $arg1, $arg2 )
00522 {
00523 return '( ' . $arg1 . ' | ' . $arg2 . ' ) ';
00524 }
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534 function hasRequiredServerVersion( $minVersion, $name = false )
00535 {
00536 if ( $name !== false and
00537 $name != $this->databaseName() )
00538 return false;
00539
00540 $version = $this->databaseServerVersion();
00541 $version = $version['string'];
00542 return version_compare( $version, $minVersion ) >= 0;
00543 }
00544
00545
00546
00547
00548
00549 function databaseServerVersion()
00550 {
00551 }
00552
00553
00554
00555
00556
00557 function databaseClientVersion()
00558 {
00559 }
00560
00561
00562
00563
00564 function isCharsetSupported( $charset )
00565 {
00566 return false;
00567 }
00568
00569
00570
00571
00572
00573 function charset()
00574 {
00575 return $this->Charset;
00576 }
00577
00578
00579
00580
00581
00582
00583 function usesBuiltinEncoding()
00584 {
00585 return $this->UseBuiltinEncoding;
00586 }
00587
00588
00589
00590
00591
00592 function bindingType( )
00593 {
00594 }
00595
00596
00597
00598
00599
00600 function bindVariable( $value, $fieldDef = false )
00601 {
00602 }
00603
00604
00605
00606
00607
00608
00609
00610
00611 function query( $sql, $server = false )
00612 {
00613 }
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631 function arrayQuery( $sql, $params = array(), $server = false )
00632 {
00633 }
00634
00635
00636
00637
00638
00639 function lock( $table )
00640 {
00641 }
00642
00643
00644
00645
00646
00647 function unlock()
00648 {
00649 }
00650
00651
00652
00653
00654
00655 function begin()
00656 {
00657 $ini =& eZINI::instance();
00658 if ( $ini->variable( "DatabaseSettings", "Transactions" ) == "enabled" )
00659 {
00660 if ( $this->TransactionCounter > 0 )
00661 {
00662 if ( is_array( $this->TransactionStackTree ) )
00663 {
00664
00665 $bt = debug_backtrace();
00666 $subLevels =& $this->TransactionStackTree['sub_levels'];
00667 for ( $i = 1; $i < $this->TransactionCounter; ++$i )
00668 {
00669 $subLevels =& $subLevels[count( $subLevels ) - 1]['sub_levels'];
00670 }
00671
00672 $subLevels[count( $subLevels )] = array( 'level' => $this->TransactionCounter,
00673 'trace' => $bt,
00674 'sub_levels' => array() );
00675 }
00676 ++$this->TransactionCounter;
00677 return false;
00678 }
00679 else
00680 {
00681 if ( is_array( $this->TransactionStackTree ) )
00682 {
00683
00684 $bt = debug_backtrace();
00685 $this->TransactionStackTree = array( 'level' => $this->TransactionCounter,
00686 'trace' => $bt,
00687 'sub_levels' => array() );
00688 }
00689 }
00690 $this->TransactionIsValid = true;
00691
00692 if ( $this->isConnected() )
00693 {
00694 $oldRecordError = $this->RecordError;
00695
00696 $this->RecordError = false;
00697 $this->beginQuery();
00698 $this->RecordError = $oldRecordError;
00699
00700
00701
00702 ++$this->TransactionCounter;
00703 }
00704 }
00705 return true;
00706 }
00707
00708
00709
00710
00711
00712
00713 function beginQuery()
00714 {
00715 return false;
00716 }
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728 function commit()
00729 {
00730 $ini =& eZINI::instance();
00731 if ( $ini->variable( "DatabaseSettings", "Transactions" ) == "enabled" )
00732 {
00733 if ( $this->TransactionCounter <= 0 )
00734 {
00735 eZDebug::writeError( 'No transaction in progress, cannot commit', 'eZDBInterface::commit' );
00736 return false;
00737 }
00738
00739 --$this->TransactionCounter;
00740 if ( $this->TransactionCounter == 0 )
00741 {
00742 if ( is_array( $this->TransactionStackTree ) )
00743 {
00744
00745 $this->TransactionStackTree = array();
00746 }
00747 if ( $this->isConnected() )
00748 {
00749
00750 if ( !$this->TransactionIsValid )
00751 {
00752 $oldRecordError = $this->RecordError;
00753
00754 $this->RecordError = false;
00755 $this->rollbackQuery();
00756 $this->RecordError = $oldRecordError;
00757
00758 return false;
00759 }
00760 else
00761 {
00762 $oldRecordError = $this->RecordError;
00763
00764 $this->RecordError = false;
00765 $this->commitQuery();
00766 $this->RecordError = $oldRecordError;
00767 }
00768 }
00769 }
00770 else
00771 {
00772 if ( is_array( $this->TransactionStackTree ) )
00773 {
00774
00775 $bt = debug_backtrace();
00776
00777 $subLevels =& $this->TransactionStackTree['sub_levels'];
00778 for ( $i = 1; $i < $this->TransactionCounter; ++$i )
00779 {
00780 $subLevels =& $subLevels[count( $subLevels ) - 1]['sub_levels'];
00781 }
00782
00783 $subLevels[count( $subLevels ) - 1]['commit_trace'] = $bt;
00784 }
00785 }
00786 }
00787 return true;
00788 }
00789
00790
00791
00792
00793
00794
00795 function commitQuery()
00796 {
00797 return false;
00798 }
00799
00800
00801
00802
00803 function rollback()
00804 {
00805 if ( is_array( $this->TransactionStackTree ) )
00806 {
00807
00808 $this->TransactionStackTree = array();
00809 }
00810 $ini =& eZINI::instance();
00811 if ( $ini->variable( "DatabaseSettings", "Transactions" ) == "enabled" )
00812 {
00813 if ( $this->TransactionCounter <= 0 )
00814 {
00815 eZDebug::writeError( 'No transaction in progress, cannot rollback', 'eZDBInterface::rollback' );
00816 return false;
00817 }
00818
00819 $this->TransactionCounter = 0;
00820 if ( $this->isConnected() )
00821 {
00822 $oldRecordError = $this->RecordError;
00823
00824 $this->RecordError = false;
00825 $this->rollbackQuery();
00826 $this->RecordError = $oldRecordError;
00827 }
00828 }
00829 return true;
00830 }
00831
00832
00833
00834
00835
00836
00837 function generateFailedTransactionStack()
00838 {
00839 if ( !$this->TransactionStackTree )
00840 {
00841 return false;
00842 }
00843 return $this->generateFailedTransactionStackEntry( $this->TransactionStackTree, 0 );
00844 }
00845
00846
00847
00848
00849
00850
00851 function generateFailedTransactionStackEntry( $stack, $indentCount )
00852 {
00853 $stackText = '';
00854 $indent = '';
00855 if ( $indentCount > 0 )
00856 {
00857 $indent = str_repeat( " ", $indentCount*4 );
00858 }
00859 $stackText .= $indent . "Level " . $stack['level'] . "\n" . $indent . "{" . $indent . "\n";
00860 $stackText .= $indent . " Began at:\n";
00861 for ( $i = 0; $i < 2 && $i < count( $stack['trace'] ); ++$i )
00862 {
00863 $indent2 = str_repeat( " ", $i + 1 );
00864 if ( $i > 0 )
00865 {
00866 $indent2 .= "->";
00867 }
00868 $stackText .= $indent . $indent2 . $this->generateTraceEntry( $stack['trace'][$i] );
00869 $stackText .= "\n";
00870 }
00871 foreach ( $stack['sub_levels'] as $subStack )
00872 {
00873 $stackText .= $this->generateFailedTransactionStackEntry( $subStack, $indentCount + 1 );
00874 }
00875 if ( isset( $stack['commit_trace'] ) )
00876 {
00877 $stackText .= $indent . " And commited at:\n";
00878 for ( $i = 0; $i < 2 && $i < count( $stack['commit_trace'] ); ++$i )
00879 {
00880 $indent2 = str_repeat( " ", $i + 1 );
00881 if ( $i > 0 )
00882 {
00883 $indent2 .= "->";
00884 }
00885 $stackText .= $indent . $indent2 . $this->generateTraceEntry( $stack['commit_trace'][$i] );
00886 $stackText .= "\n";
00887 }
00888 }
00889 $stackText .= $indent . "}" . "\n";
00890 return $stackText;
00891 }
00892
00893
00894
00895
00896
00897
00898 function generateTraceEntry( $entry )
00899 {
00900 if ( isset( $entry['file'] ) )
00901 {
00902 $stackText = $entry['file'];
00903 }
00904 else
00905 {
00906 $stackText = "???";
00907 }
00908 $stackText .= ":";
00909 if ( isset( $entry['line'] ) )
00910 {
00911 $stackText .= $entry['line'];
00912 }
00913 else
00914 {
00915 $stackText .= "???";
00916 }
00917 $stackText .= " ";
00918 if ( isset( $entry['class'] ) )
00919 {
00920 $stackText .= $entry['class'];
00921 }
00922 else
00923 {
00924 $stackText .= "???";
00925 }
00926 $stackText .= "::";
00927 if ( isset( $entry['function'] ) )
00928 {
00929 $stackText .= $entry['function'];
00930 }
00931 else
00932 {
00933 $stackText .= "???";
00934 }
00935 return $stackText;
00936 }
00937
00938
00939
00940
00941
00942
00943 function rollbackQuery()
00944 {
00945 return false;
00946 }
00947
00948
00949
00950
00951
00952
00953
00954 function invalidateTransaction()
00955 {
00956 if ( $this->TransactionCounter <= 0 )
00957 return false;
00958 $this->TransactionIsValid = false;
00959 return true;
00960 }
00961
00962
00963
00964
00965
00966
00967 function reportError()
00968 {
00969
00970
00971 if ( $this->TransactionCounter > 0 )
00972 {
00973 $this->invalidateTransaction();
00974
00975
00976 $transID = 'TRANSID-' . md5( mktime() . mt_rand() );
00977
00978 eZDebug::writeError( 'Transaction in progress failed due to DB error, transaction was rollbacked. Transaction ID is ' . $transID . '.', 'eZDBInterface::commit ' . $transID );
00979
00980 $oldRecordError = $this->RecordError;
00981
00982 $this->RecordError = false;
00983 $this->rollbackQuery();
00984 $this->RecordError = $oldRecordError;
00985
00986
00987 include_once( 'lib/ezutils/classes/ezexecution.php' );
00988 eZExecution::cleanup();
00989 eZExecution::setCleanExit();
00990
00991
00992 eZDebug::setHandleType( EZ_HANDLE_NONE );
00993
00994 $ini =& eZINI::instance();
00995 $adminEmail = $ini->variable( 'MailSettings', 'AdminEmail' );
00996 include_once( 'lib/ezutils/classes/ezsys.php' );
00997
00998 if ( !eZSys::isShellExecution() )
00999 {
01000 $site = eZSys::serverVariable( 'HTTP_HOST' );
01001 $uri = eZSys::serverVariable( 'REQUEST_URI' );
01002
01003 print( "<div class=\"fatal-error\" style=\"" );
01004 print( 'margin: 0.5em 0 1em 0; ' .
01005 'padding: 0.25em 1em 0.75em 1em;' .
01006 'border: 4px solid #000000;' .
01007 'background-color: #f8f8f4;' .
01008 'border-color: #f95038;" >' );
01009 print( "<b>Fatal error</b>: A database transaction in eZ publish failed.<br/>" );
01010 print( "<p>" );
01011 print( "The current execution was stopped to prevent further problems.<br/>\n" .
01012 "You should contact the <a href=\"mailto:$adminEmail?subject=Transaction failed on $site and URI $uri with ID $transID\">System Administrator</a> of this site with the information on this page.<br/>\n" .
01013 "The current transaction ID is <b>$transID</b> and has been logged.<br/>\n" .
01014 "Please include the transaction ID and the current URL when contacting the system administrator.<br/>\n" );
01015 print( "</p>" );
01016 print( "</div>" );
01017
01018 $templateResult = null;
01019 if ( function_exists( 'eZDisplayResult' ) )
01020 {
01021 eZDisplayResult( $templateResult );
01022 }
01023 }
01024 else
01025 {
01026 fputs( STDERR,"Fatal error: A database transaction in eZ publish failed.\n" );
01027 fputs( STDERR, "\n" );
01028 fputs( STDERR, "The current execution was stopped to prevent further problems.\n" .
01029 "You should contact the System Administrator ($adminEmail) of this site.\n" .
01030 "The current transaction ID is $transID and has been logged.\n" .
01031 "Please include the transaction ID and the name of the current script when contacting the system administrator.\n" );
01032 fputs( STDERR, "\n" );
01033
01034 fputs( STDERR, eZDebug::printReport( false, false, true ) );
01035 }
01036
01037
01038 exit( 1 );
01039 }
01040 }
01041
01042
01043
01044
01045
01046
01047 function isTransactionValid()
01048 {
01049 return $this->TransactionIsValid;
01050 }
01051
01052
01053
01054
01055
01056
01057
01058 function transactionCounter()
01059 {
01060 return $this->TransactionCounter;
01061 }
01062
01063
01064
01065
01066
01067 function relationCounts( $relationMask )
01068 {
01069 }
01070
01071
01072
01073
01074
01075 function relationCount( $relationType = EZ_DB_RELATION_TABLE )
01076 {
01077 }
01078
01079
01080
01081
01082
01083 function eZTableList( $server = EZ_DB_SERVER_MASTER )
01084 {
01085 }
01086
01087
01088
01089
01090
01091 function relationList( $relationType = EZ_DB_RELATION_TABLE )
01092 {
01093 }
01094
01095
01096
01097
01098
01099
01100 function removeRelation( $relationName, $relationType )
01101 {
01102 return false;
01103 }
01104
01105
01106
01107
01108
01109
01110 function relationName( $relationType )
01111 {
01112 $names = array( EZ_DB_RELATION_TABLE => 'TABLE',
01113 EZ_DB_RELATION_SEQUENCE => 'SEQUENCE',
01114 EZ_DB_RELATION_TRIGGER => 'TRIGGER',
01115 EZ_DB_RELATION_VIEW => 'VIEW',
01116 EZ_DB_RELATION_INDEX => 'INDEX' );
01117 if ( !isset( $names[$relationType] ) )
01118 return false;
01119 return $names[$relationType];
01120 }
01121
01122
01123
01124
01125
01126
01127
01128
01129
01130
01131
01132
01133
01134
01135
01136 function relationMatchRegexp( $relationType )
01137 {
01138 return false;
01139 }
01140
01141
01142
01143
01144
01145
01146
01147
01148
01149
01150
01151
01152
01153
01154 function implodeWithTypeCast( $glue, &$pieces, $type )
01155 {
01156 $str = '';
01157 if ( !is_array( $pieces ) )
01158 return $str;
01159
01160 foreach( $pieces as $piece )
01161 {
01162 settype( $piece, $type );
01163 $str .= $piece.$glue;
01164 }
01165 $str = rtrim( $str, $glue );
01166 return $str;
01167 }
01168
01169
01170
01171
01172
01173 function lastSerialID( $table, $column )
01174 {
01175 }
01176
01177
01178
01179
01180
01181 function escapeString( $str )
01182 {
01183 return $str;
01184 }
01185
01186
01187
01188
01189
01190 function close()
01191 {
01192 }
01193
01194
01195
01196
01197
01198 function isConnected()
01199 {
01200 return $this->IsConnected;
01201 }
01202
01203
01204
01205
01206
01207 function createDatabase()
01208 {
01209 }
01210
01211
01212
01213
01214 function createTempTable( $createTableQuery = '', $server = EZ_DB_SERVER_SLAVE )
01215 {
01216 $this->query( $createTableQuery, $server );
01217 }
01218
01219
01220
01221
01222 function dropTempTable( $dropTableQuery = '', $server = EZ_DB_SERVER_SLAVE )
01223 {
01224 $this->query( $dropTableQuery, $server );
01225 }
01226
01227
01228
01229
01230 function dropTempTableList( $tableList, $server = EZ_DB_SERVER_SLAVE )
01231 {
01232 foreach( $tableList as $tableName )
01233 $this->dropTempTable( "DROP TABLE $tableName", $server );
01234 }
01235
01236
01237
01238
01239
01240 function setError()
01241 {
01242 }
01243
01244
01245
01246
01247 function errorMessage()
01248 {
01249 return $this->ErrorMessage;
01250 }
01251
01252
01253
01254
01255 function errorNumber()
01256 {
01257 return $this->ErrorNumber;
01258 }
01259
01260
01261
01262
01263
01264
01265
01266
01267 function availableDatabases()
01268 {
01269 return false;
01270 }
01271
01272
01273
01274
01275
01276
01277 function generateUniqueTempTableName( $pattern, $randomizeIndex = false, $server = EZ_DB_SERVER_SLAVE )
01278 {
01279 $tableList = array_keys( $this->eZTableList( $server ) );
01280 if ( $randomizeIndex === false )
01281 {
01282 $randomizeIndex = rand( 10, 1000 );
01283 }
01284 do
01285 {
01286 $uniqueTempTableName = str_replace( '%', $randomizeIndex, $pattern );
01287 $randomizeIndex++;
01288 }
01289 while ( in_array( $uniqueTempTableName, $tableList ) );
01290
01291 return $uniqueTempTableName;
01292 }
01293
01294
01295
01296
01297
01298
01299
01300 function version()
01301 {
01302 return false;
01303 }
01304
01305
01306
01307 var $Server;
01308
01309 var $SocketPath;
01310
01311 var $DB;
01312
01313 var $DBConnection;
01314
01315 var $DBWriteConnection;
01316
01317 var $User;
01318
01319 var $Password;
01320
01321 var $Charset;
01322
01323 var $ConnectRetries;
01324
01325 var $OutputTextCodec;
01326 var $InputTextCodec;
01327
01328
01329 var $UseBuiltinEncoding;
01330
01331 var $OutputSQL;
01332
01333 var $IsConnected = false;
01334
01335 var $NumQueries = 0;
01336
01337 var $StartTime;
01338
01339 var $EndTime;
01340
01341 var $TimeTaken;
01342
01343 var $ErrorMessage;
01344
01345 var $ErrorNumber = 0;
01346
01347 var $RecordError = true;
01348
01349 var $UsePersistentConnection = false;
01350
01351 var $UserSlaveServer;
01352
01353 var $SlaveDB;
01354
01355 var $SlaveServer;
01356
01357 var $SlaveUser;
01358
01359 var $SlavePassword;
01360
01361 var $TransactionCounter;
01362
01363
01364 var $TransactionIsValid;
01365 }
01366
01367 ?>