From 01c102f66a70927b7affb79c10e399851411ff3f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 8 Mar 2011 10:33:43 +0000 Subject: [PATCH] Add function DDLUpdateField --- htdocs/lib/databases/mssql.lib.php | 19 +++++++++++++++++++ htdocs/lib/databases/mysql.lib.php | 20 ++++++++++++++++++++ htdocs/lib/databases/mysqli.lib.php | 19 +++++++++++++++++++ htdocs/lib/databases/pgsql.lib.php | 20 ++++++++++++++++++++ 4 files changed, 78 insertions(+) diff --git a/htdocs/lib/databases/mssql.lib.php b/htdocs/lib/databases/mssql.lib.php index caf70c9f474..75cfc56bf7f 100644 --- a/htdocs/lib/databases/mssql.lib.php +++ b/htdocs/lib/databases/mssql.lib.php @@ -911,7 +911,26 @@ class DoliDb return 1; } + /** + * Update format of a field into a table + * @param table Name of table + * @param field_name Name of field to modify + * @param field_desc Array with description of field format + * @return int <0 if KO, >0 if OK + */ + function DDLUpdateField($table,$field_name,$field_desc) + { + $sql = "ALTER TABLE ".MAIN_DB_PREFIX.$table; + $sql .= " MODIFY COLUMN ".$field_name." ".$field_desc['type']; + if ($field_desc['type'] == 'int' || $field_desc['type'] == 'varchar') $sql.="(".$field_desc['value'].")"; + dol_syslog($sql,LOG_DEBUG); + if (! $this->query($sql)) + return -1; + else + return 1; + } + /** * \brief Drop a field in table * \param table Nom de la table diff --git a/htdocs/lib/databases/mysql.lib.php b/htdocs/lib/databases/mysql.lib.php index bbfe0ae9c1e..13270452c79 100644 --- a/htdocs/lib/databases/mysql.lib.php +++ b/htdocs/lib/databases/mysql.lib.php @@ -974,6 +974,26 @@ class DoliDb return 1; } + /** + * Update format of a field into a table + * @param table Name of table + * @param field_name Name of field to modify + * @param field_desc Array with description of field format + * @return int <0 if KO, >0 if OK + */ + function DDLUpdateField($table,$field_name,$field_desc) + { + $sql = "ALTER TABLE ".MAIN_DB_PREFIX.$table; + $sql .= " MODIFY COLUMN ".$field_name." ".$field_desc['type']; + if ($field_desc['type'] == 'int' || $field_desc['type'] == 'varchar') $sql.="(".$field_desc['value'].")"; + + dol_syslog($sql,LOG_DEBUG); + if (! $this->query($sql)) + return -1; + else + return 1; + } + /** * \brief Drop a field in table * \param table Nom de la table diff --git a/htdocs/lib/databases/mysqli.lib.php b/htdocs/lib/databases/mysqli.lib.php index bec39976c52..c13d6b510c8 100644 --- a/htdocs/lib/databases/mysqli.lib.php +++ b/htdocs/lib/databases/mysqli.lib.php @@ -986,7 +986,26 @@ class DoliDb return 1; } + /** + * Update format of a field into a table + * @param table Name of table + * @param field_name Name of field to modify + * @param field_desc Array with description of field format + * @return int <0 if KO, >0 if OK + */ + function DDLUpdateField($table,$field_name,$field_desc) + { + $sql = "ALTER TABLE ".MAIN_DB_PREFIX.$table; + $sql .= " MODIFY COLUMN ".$field_name." ".$field_desc['type']; + if ($field_desc['type'] == 'int' || $field_desc['type'] == 'varchar') $sql.="(".$field_desc['value'].")"; + dol_syslog($sql,LOG_DEBUG); + if (! $this->query($sql)) + return -1; + else + return 1; + } + /** * \brief Drop a field in table * \param table Nom de la table diff --git a/htdocs/lib/databases/pgsql.lib.php b/htdocs/lib/databases/pgsql.lib.php index f0906c17822..d7038545aa1 100644 --- a/htdocs/lib/databases/pgsql.lib.php +++ b/htdocs/lib/databases/pgsql.lib.php @@ -1116,6 +1116,26 @@ class DoliDb return 1; } + /** + * Update format of a field into a table + * @param table Name of table + * @param field_name Name of field to modify + * @param field_desc Array with description of field format + * @return int <0 if KO, >0 if OK + */ + function DDLUpdateField($table,$field_name,$field_desc) + { + $sql = "ALTER TABLE ".MAIN_DB_PREFIX.$table; + $sql .= " MODIFY COLUMN ".$field_name." ".$field_desc['type']; + if ($field_desc['type'] == 'int' || $field_desc['type'] == 'varchar') $sql.="(".$field_desc['value'].")"; + + dol_syslog($sql,LOG_DEBUG); + if (! $this->query($sql)) + return -1; + else + return 1; + } + /** * \brief Drop a field in table * \param table Nom de la table