Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 508... Línea 508...
508
	/**
508
	/**
509
	 * Change the definition of one column
509
	 * Change the definition of one column
510
	 *
510
	 *
511
	 * As some DBMs can't do that on their own, you need to supply the complete definition of the new table,
511
	 * As some DBMs can't do that on their own, you need to supply the complete definition of the new table,
512
	 * to allow recreating the table and copying the content over to the new table
512
	 * to allow recreating the table and copying the content over to the new table
-
 
513
	 *
513
	 * @param string $tabname table-name
514
	 * @param string       $tabname table-name
514
	 * @param string $flds column-name and type for the changed column
515
	 * @param array|string $flds column-name and type for the changed column
515
	 * @param string $tableflds='' complete definition of the new table, eg. for postgres, default ''
516
	 * @param string       $tableflds='' complete definition of the new table, eg. for postgres, default ''
516
	 * @param array|string $tableoptions='' options for the new table see createTableSQL, default ''
517
	 * @param array|string $tableoptions='' options for the new table see createTableSQL, default ''
-
 
518
	 *
517
	 * @return array with SQL strings
519
	 * @return array with SQL strings
518
	 */
520
	 */
519
	function alterColumnSQL($tabname, $flds, $tableflds='',$tableoptions='')
521
	function alterColumnSQL($tabname, $flds, $tableflds='',$tableoptions='')
520
	{
522
	{
521
		$tabname = $this->tableName($tabname);
523
		$tabname = $this->tableName($tabname);
Línea 1025... Línea 1027...
1025
	 * @return string[] Array of SQL Commands
1027
	 * @return string[] Array of SQL Commands
1026
	 */
1028
	 */
1027
	function changeTableSQL($tablename, $flds, $tableoptions = false, $dropOldFlds=false)
1029
	function changeTableSQL($tablename, $flds, $tableoptions = false, $dropOldFlds=false)
1028
	{
1030
	{
1029
	global $ADODB_FETCH_MODE;
1031
	global $ADODB_FETCH_MODE;
1030
 
-
 
1031
		$save = $ADODB_FETCH_MODE;
1032
		$save = $ADODB_FETCH_MODE;
1032
		$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
1033
		$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
1033
		if ($this->connection->fetchMode !== false) $savem = $this->connection->setFetchMode(false);
1034
		if ($this->connection->fetchMode !== false) $savem = $this->connection->setFetchMode(false);
Línea 1034... Línea 1035...
1034
 
1035
 
Línea 1043... Línea 1044...
1043
 
1044
 
1044
		if ( empty($cols)) {
1045
		if ( empty($cols)) {
1045
			return $this->createTableSQL($tablename, $flds, $tableoptions);
1046
			return $this->createTableSQL($tablename, $flds, $tableoptions);
Línea -... Línea 1047...
-
 
1047
		}
1046
		}
1048
 
1047
 
1049
		$sql = [];
1048
		if (is_array($flds)) {
1050
		if (is_array($flds)) {
1049
		// Cycle through the update fields, comparing
1051
		// Cycle through the update fields, comparing
1050
		// existing fields to fields to update.
1052
		// existing fields to fields to update.
1051
		// if the Metatype and size is exactly the
1053
		// if the Metatype and size is exactly the
-
 
1054
		// same, ignore - by Mark Newham
-
 
1055
			$holdflds = array();
1052
		// same, ignore - by Mark Newham
1056
			$fields_to_add = [];
1053
			$holdflds = array();
1057
			$fields_to_alter = [];
1054
			foreach($flds as $k=>$v) {
1058
			foreach($flds as $k=>$v) {
1055
				if ( isset($cols[$k]) && is_object($cols[$k]) ) {
1059
				if ( isset($cols[$k]) && is_object($cols[$k]) ) {
1056
					// If already not allowing nulls, then don't change
1060
					// If already not allowing nulls, then don't change
Línea 1072... Línea 1076...
1072
 
1076
 
1073
					if ($ml == -1) $ml = '';
1077
					if ($ml == -1) $ml = '';
1074
					if ($mt == 'X') $ml = $v['SIZE'];
1078
					if ($mt == 'X') $ml = $v['SIZE'];
1075
					if (($mt != $v['TYPE']) || ($ml != $fsize || $sc != $fprec) || (isset($v['AUTOINCREMENT']) && $v['AUTOINCREMENT'] != $obj->auto_increment)) {
1079
					if (($mt != $v['TYPE']) || ($ml != $fsize || $sc != $fprec) || (isset($v['AUTOINCREMENT']) && $v['AUTOINCREMENT'] != $obj->auto_increment)) {
-
 
1080
						$holdflds[$k] = $v;
1076
						$holdflds[$k] = $v;
1081
						$fields_to_alter[$k] = $v;
1077
					}
1082
					}
-
 
1083
				} else {
1078
				} else {
1084
					$fields_to_add[$k] = $v;
1079
					$holdflds[$k] = $v;
1085
					$holdflds[$k] = $v;
1080
				}
1086
				}
1081
			}
1087
			}
1082
			$flds = $holdflds;
-
 
Línea -... Línea 1088...
-
 
1088
			$flds = $holdflds;
-
 
1089
 
1083
		}
1090
			$sql = array_merge(
-
 
1091
				$this->addColumnSQL($tablename, $fields_to_add),
-
 
1092
				$this->alterColumnSql($tablename, $fields_to_alter)
Línea 1084... Línea 1093...
1084
 
1093
			);
1085
		$sql = $this->alterColumnSql($tablename, $flds);
1094
		}
1086
 
1095
 
1087
		if ($dropOldFlds) {
1096
		if ($dropOldFlds) {