1
4dept
Creating MySQL tables during module installation
  • 2005/11/18 8:20

  • 4dept

  • Just popping in

  • Posts: 4

  • Since: 2005/11/13


I've created simple module, which uses MySQL bases.
During module installation some sql tables should be created, if not exists.

module's xoops_version.php (sql part)
$modversion['sqlfile']['mysql'] = "sql/mysql.sql";

mysql.sql code:
CREATE TABLE IF NOT EXISTS Actions ( actions_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, actions_desc TEXT NOT NULL, PRIMARY KEY(actions_id) );

Error during installation: SQL script error (IF NOT EXISTS).
If remove, the module can not be installed if tables already exist.

How can i create tables, if they don't exist only?

2
davidthomas1
Re: Creating MySQL tables during module installation

Try running a DROP TABLE query first.

i.e

DROP TABLE IF EXISTS Actions;


and then your CREATE TABLE query:

CREATE TABLE Actions actions_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENTactions_desc TEXT NOT NULLPRIMARY KEY(actions_id) );


HIH
みんなちがってみんないい。

XOOPS 2.0.13.2

3
4dept
Re: Creating MySQL tables during module installation
  • 2005/11/18 10:26

  • 4dept

  • Just popping in

  • Posts: 4

  • Since: 2005/11/13


Quote:

davidthomas1 wrote:
Try running a DROP TABLE query first.

i.e

DROP TABLE IF EXISTS Actions;


and then your CREATE TABLE query:

CREATE TABLE Actions actions_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENTactions_desc TEXT NOT NULLPRIMARY KEY(actions_id) );


HIH


Tables may contain important data from previous module version or friendly module.

4
LazyBadger
Re: Creating MySQL tables during module installation

Try read data, which must exist in table before "create..." and check result... but your syntax must work
Quis custodiet ipsos custodes?

Webmaster of
XOOPS2.RU
XOOPS Modules Proving Ground
XOOPS Themes Exhibition

Login

Who's Online

463 user(s) are online (94 user(s) are browsing Support Forums)


Members: 0


Guests: 463


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Oct 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits