⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 adodb-lib.inc.php

📁 Typo3, 开源里边最强大的
💻 PHP
📖 第 1 页 / 共 3 页
字号:
		} else {			for ($i=0, $max=$rs->FieldCount(); $i < $max; $i++) 				$columns[] = $rs->FetchField($i);			$cacheRS = $cacheSig;			$cacheCols = $columns;			$rs->insertSig = $cacheSig++;		}		$recordSet =& $rs;		} else {		printf(ADODB_BAD_RS,'GetInsertSQL');		return false;	}	// Loop through all of the fields in the recordset	foreach( $columns as $field ) { 		$upperfname = strtoupper($field->name);		if (adodb_key_exists($upperfname,$arrFields,$force)) {			$bad = false;			if (strpos($upperfname,' ') !== false)				$fnameq = $zthis->nameQuote.$upperfname.$zthis->nameQuote;			else				$fnameq = $upperfname;						$type = $recordSet->MetaType($field->type);			            /********************************************************/            if (is_null($arrFields[$upperfname])                || (empty($arrFields[$upperfname]) && strlen($arrFields[$upperfname]) == 0)                || $arrFields[$upperfname] === $zthis->null2null				)               {                    switch ($force) {                        case 0: // we must always set null if missing							$bad = true;							break;							                        case 1:                            $values  .= "null, ";                        break;		                        case 2:                            //Set empty                            $arrFields[$upperfname] = "";                            $values .= _adodb_column_sql($zthis, 'I', $type, $upperfname, $fnameq,$arrFields, $magicq);                        break;						default:                        case 3:                            //Set the value that was given in array, so you can give both null and empty values							if (is_null($arrFields[$upperfname]) || $arrFields[$upperfname] === $zthis->null2null) { 								$values  .= "null, ";							} else {                        		$values .= _adodb_column_sql($zthis, 'I', $type, $upperfname, $fnameq, $arrFields, $magicq);             				}              			break;             		} // switch            /*********************************************************/			} else {				//we do this so each driver can customize the sql for				//DB specific column types. 				//Oracle needs BLOB types to be handled with a returning clause				//postgres has special needs as well				$values .= _adodb_column_sql($zthis, 'I', $type, $upperfname, $fnameq,											   $arrFields, $magicq);			}						if ($bad) continue;			// Set the counter for the number of fields that will be inserted.			$fieldInsertedCount++;									// Get the name of the fields to insert			$fields .= $fnameq . ", ";		}	}	// If there were any inserted fields then build the rest of the insert query.	if ($fieldInsertedCount <= 0)  return false;		// Get the table name from the existing query.	if (!$tableName) {		if (!empty($rs->tableName)) $tableName = $rs->tableName;		else if (preg_match("/FROM\s+".ADODB_TABLE_REGEX."/is", $rs->sql, $tableName))			$tableName = $tableName[1];		else 			return false;	}			// Strip off the comma and space on the end of both the fields	// and their values.	$fields = substr($fields, 0, -2);	$values = substr($values, 0, -2);	// Append the fields and their values to the insert query.	return 'INSERT INTO '.$zthis->nameQuote.$tableName.$zthis->nameQuote.' ( '.$fields.' ) VALUES ( '.$values.' )';}/** * This private method is used to help construct * the update/sql which is generated by GetInsertSQL and GetUpdateSQL. * It handles the string construction of 1 column -> sql string based on * the column type.  We want to do 'safe' handling of BLOBs *  * @param string the type of sql we are trying to create *                'I' or 'U'.  * @param string column data type from the db::MetaType() method   * @param string the column name * @param array the column value *  * @return string *  */function _adodb_column_sql_oci8(&$zthis,$action, $type, $fname, $fnameq, $arrFields, $magicq) {    $sql = '';        // Based on the datatype of the field    // Format the value properly for the database    switch($type) {    case 'B':        //in order to handle Blobs correctly, we need        //to do some magic for Oracle        //we need to create a new descriptor to handle         //this properly        if (!empty($zthis->hasReturningInto)) {            if ($action == 'I') {                $sql = 'empty_blob(), ';            } else {                $sql = $fnameq. '=empty_blob(), ';            }            //add the variable to the returning clause array            //so the user can build this later in            //case they want to add more to it            $zthis->_returningArray[$fname] = ':xx'.$fname.'xx';        } else if (empty($arrFields[$fname])){            if ($action == 'I') {                $sql = 'empty_blob(), ';            } else {                $sql = $fnameq. '=empty_blob(), ';            }                    } else {            //this is to maintain compatibility            //with older adodb versions.            $sql = _adodb_column_sql($zthis, $action, $type, $fname, $fnameq, $arrFields, $magicq,false);        }        break;    case "X":        //we need to do some more magic here for long variables        //to handle these correctly in oracle.        //create a safe bind var name        //to avoid conflicts w/ dupes.       if (!empty($zthis->hasReturningInto)) {            if ($action == 'I') {                $sql = ':xx'.$fname.'xx, ';                            } else {                $sql = $fnameq.'=:xx'.$fname.'xx, ';            }            //add the variable to the returning clause array            //so the user can build this later in            //case they want to add more to it            $zthis->_returningArray[$fname] = ':xx'.$fname.'xx';        } else {            //this is to maintain compatibility            //with older adodb versions.            $sql = _adodb_column_sql($zthis, $action, $type, $fname, $fnameq, $arrFields, $magicq,false);        }                    break;            default:        $sql = _adodb_column_sql($zthis, $action, $type, $fname, $fnameq,  $arrFields, $magicq,false);        break;    }        return $sql;}    	function _adodb_column_sql(&$zthis, $action, $type, $fname, $fnameq, $arrFields, $magicq, $recurse=true) {	if ($recurse) {		switch($zthis->dataProvider)  {		case 'postgres':			if ($type == 'L') $type = 'C';			break;		case 'oci8':			return _adodb_column_sql_oci8($zthis, $action, $type, $fname, $fnameq, $arrFields, $magicq);					}	}			switch($type) {		case "C":		case "X":		case 'B':			$val = $zthis->qstr($arrFields[$fname],$magicq);			break;		case "D":			$val = $zthis->DBDate($arrFields[$fname]);			break;		case "T":			$val = $zthis->DBTimeStamp($arrFields[$fname]);			break;		default:			$val = $arrFields[$fname];			if (empty($val)) $val = '0';			break;	}	if ($action == 'I') return $val . ", ";			return $fnameq . "=" . $val  . ", ";	}function _adodb_debug_execute(&$zthis, $sql, $inputarr){	$ss = '';	if ($inputarr) {		foreach($inputarr as $kk=>$vv) {			if (is_string($vv) && strlen($vv)>64) $vv = substr($vv,0,64).'...';			$ss .= "($kk=>'$vv') ";		}		$ss = "[ $ss ]";	}	$sqlTxt = is_array($sql) ? $sql[0] : $sql;	/*str_replace(', ','##1#__^LF',is_array($sql) ? $sql[0] : $sql);	$sqlTxt = str_replace(',',', ',$sqlTxt);	$sqlTxt = str_replace('##1#__^LF', ', ' ,$sqlTxt);	*/	// check if running from browser or command-line	$inBrowser = isset($_SERVER['HTTP_USER_AGENT']);		$dbt = $zthis->databaseType;	if (isset($zthis->dsnType)) $dbt .= '-'.$zthis->dsnType;	if ($inBrowser) {		if ($ss) {			$ss = '<code>'.htmlspecialchars($ss).'</code>';		}		if ($zthis->debug === -1)			ADOConnection::outp( "<br />\n($dbt): ".htmlspecialchars($sqlTxt)." &nbsp; $ss\n<br />\n",false);		else 			ADOConnection::outp( "<hr />\n($dbt): ".htmlspecialchars($sqlTxt)." &nbsp; $ss\n<hr />\n",false);	} else {		ADOConnection::outp("-----\n($dbt): ".$sqlTxt."\n-----\n",false);	}	$qID = $zthis->_query($sql,$inputarr);		/* 		Alexios Fakios notes that ErrorMsg() must be called before ErrorNo() for mssql		because ErrorNo() calls Execute('SELECT @ERROR'), causing recursion	*/	if ($zthis->databaseType == 'mssql') { 	// ErrorNo is a slow function call in mssql, and not reliable in PHP 4.0.6		if($emsg = $zthis->ErrorMsg()) {			if ($err = $zthis->ErrorNo()) ADOConnection::outp($err.': '.$emsg);		}	} else if (!$qID) {		ADOConnection::outp($zthis->ErrorNo() .': '. $zthis->ErrorMsg());	}		if ($zthis->debug === 99) _adodb_backtrace(true,9999,2);	return $qID;}# pretty print the debug_backtrace functionfunction _adodb_backtrace($printOrArr=true,$levels=9999,$skippy=0){	if (!function_exists('debug_backtrace')) return '';	 	$html =  (isset($_SERVER['HTTP_USER_AGENT']));	$fmt =  ($html) ? "</font><font color=#808080 size=-1> %% line %4d, file: <a href=\"file:/%s\">%s</a></font>" : "%% line %4d, file: %s";	$MAXSTRLEN = 128;	$s = ($html) ? '<pre align=left>' : '';		if (is_array($printOrArr)) $traceArr = $printOrArr;	else $traceArr = debug_backtrace();	array_shift($traceArr);	array_shift($traceArr);	$tabs = sizeof($traceArr)-2;		foreach ($traceArr as $arr) {		if ($skippy) {$skippy -= 1; continue;}		$levels -= 1;		if ($levels < 0) break;				$args = array();		for ($i=0; $i < $tabs; $i++) $s .=  ($html) ? ' &nbsp; ' : "\t";		$tabs -= 1;		if ($html) $s .= '<font face="Courier New,Courier">';		if (isset($arr['class'])) $s .= $arr['class'].'.';		if (isset($arr['args']))		 foreach($arr['args'] as $v) {			if (is_null($v)) $args[] = 'null';			else if (is_array($v)) $args[] = 'Array['.sizeof($v).']';			else if (is_object($v)) $args[] = 'Object:'.get_class($v);			else if (is_bool($v)) $args[] = $v ? 'true' : 'false';			else {				$v = (string) @$v;				$str = htmlspecialchars(substr($v,0,$MAXSTRLEN));				if (strlen($v) > $MAXSTRLEN) $str .= '...';				$args[] = $str;			}		}		$s .= $arr['function'].'('.implode(', ',$args).')';						$s .= @sprintf($fmt, $arr['line'],$arr['file'],basename($arr['file']));					$s .= "\n";	}		if ($html) $s .= '</pre>';	if ($printOrArr) print $s;		return $s;}/*function _adodb_find_from($sql) {	$sql = str_replace(array("\n","\r"), ' ', $sql);	$charCount = strlen($sql);		$inString = false;	$quote = '';	$parentheseCount = 0;	$prevChars = '';	$nextChars = '';		for($i = 0; $i < $charCount; $i++) {    	$char = substr($sql,$i,1);	    $prevChars = substr($sql,0,$i);    	$nextChars = substr($sql,$i+1);		if((($char == "'" || $char == '"' || $char == '`') && substr($prevChars,-1,1) != '\\') && $inString === false) {			$quote = $char;			$inString = true;		}		elseif((($char == "'" || $char == '"' || $char == '`') && substr($prevChars,-1,1) != '\\') && $inString === true && $quote == $char) {			$quote = "";			$inString = false;		}		elseif($char == "(" && $inString === false)			$parentheseCount++;		elseif($char == ")" && $inString === false && $parentheseCount > 0)			$parentheseCount--;		elseif($parentheseCount <= 0 && $inString === false && $char == " " && strtoupper(substr($prevChars,-5,5)) == " FROM")			return $i;	}}*/?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -