News:

SMF 2.1.6 has been released! Take it for a spin! Read more.

Main Menu

[SOLVED] Question concerning the creation of a table

Started by slinouille, November 22, 2008, 03:31:24 AM

Previous topic - Next topic

slinouille

Hello,

It's the first time I create a mod that uses a specific table.
I've tried hard to write the creation script (during installation mod) but all tries were unsuccessfull  ::)
So I'm wondering if I put a simple sql file in my package, will it be executed during installation using such instruction :
<code>installDatabase.sql</code>

For information, here the sql code :
QuoteCREATE TABLE IF NOT EXISTS `smf_glossary` (
  `id` int(11) NOT NULL auto_increment,
  `word` varchar(30) collate latin1_german1_ci NOT NULL default '0',
  `definition` text collate latin1_german1_ci NOT NULL,
  `member_id` int(11) NOT NULL default '0',
  `date` int(11) NOT NULL default '0',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=0 ;

Here is the code I've written but that don't work (no error during installation but nothing is created):
Quote<?
global $modSettings, $smcFunc;

//This is a way to install the mod without the package parser!
$SSI_INSTALL = false;
if (!defined('SMF')) {
    require('SSI.php');
    $SSI_INSTALL = true;
}

//HELLLOOOOOOOOOO SHOULD THIS NOT DONE BY SMF!!!!!!!!!
db_extend('Packages');

$columns = array(
    'id' => array(
        'name' => 'id',
        'type' => 'int',
        'size' => '12',
        'default' => 0,
        'null' => false,
        'auto' => true,
    ),
    'word' => array(
        'name' => 'word',
        'type' => 'varchar',
        'size' => '50',
        'default' => 0,
        'null' => false,
    ),
    'definition' => array(
        'name' => 'definition',
        'type' => 'text',
        'size' => '',
        'default' => 0,
        'null' => false,
    ),
    'member_id' => array(
        'name' => 'member_id',
        'type' => 'int',
        'size' => '13',
        'default' => 0,
        'null' => false,
    ),
    'date' => array(
        'name' => 'date',
        'type' => 'varchar',
        'size' => '30',
        'default' => 0,
        'null' => false,
    ),
);

$indexes = array(
    'id' => array(
        'name' => 'id',
        'type' => 'primary',
        'columns' => array(
            'id' => 'id'
        ),
    ),
);

$smcFunc['db_create_table']('glossary', $columns, $indexes);


//Give a proper answer on ssi install ;)
if($SSI_INSTALL)
    echo 'DB Changes should be made now...';
?>

Thanks for any help  ;D

SliN
Visit VAG-Technique.fr
Take a look to my mods

[SiNaN]

Packages does not support .sql, it should be .php. Are you sure that you have coded the package_info.xml correctly, when you tried using the codes above?
Former SMF Core Developer | My Mods | SimplePortal

slinouille

Hello
Thank you for taking some minutes helping me, noce  :)

QuoteAre you sure that you have coded the package_info.xml correctly, when you tried using the codes above?

Yes because in my package_info.xml file, I've tried this:
<code>installDatabase.php</code>

And why I sure it's taken into account is that at first try an error message has been rised indicating me that $smcFunc was not a declared as global.

So for you, my installDatabase.php semms ok?


Visit VAG-Technique.fr
Take a look to my mods

[SiNaN]

Try removing these two index from $columns['definition']:

'size' => '',
'default' => 0,
Former SMF Core Developer | My Mods | SimplePortal

slinouille

 :D
Thank you Blue Dream, your suggestion was very good!
Now the table is created during installation ... I'm a happy guy now  8)

Greetings

SliN
Visit VAG-Technique.fr
Take a look to my mods

[SiNaN]

Just to note; text fields cannot have a default value and/or size. You're welcome. ;)
Former SMF Core Developer | My Mods | SimplePortal

swtdivalove

Actually, I believe this may have helped me on my project, as I do not necessarily need to create a mod, but it does help me in the area of being able to create a standard set of categories/boards/first post on the sites that I'm setting up.

I believe that I can rewrite this to fit my needs... Will have to test it on a test site.

[SiNaN]

Something like this would probably work if you are planning to put in a package:

<?php

global $sourcedir;

$msgOptions = array(
 
'id' => 0,
 
'subject' => 'Test',
 
'body' => 'Message',
 
'icon' => 'xx',
 
'smileys_enabled' => 1,
 
'attachments' => array(),
);
$topicOptions = array(
 
'id' => 0,
 
'board' => 1,
 
'mark_as_read' => true,
);
$posterOptions = array(
 
'id' => 0,
 
'name' => 'User',
 
'username' => 'User',
 
'update_post_count' => false,
);

require_once(
$sourcedir . '/Subs-Post.php');
createPost($msgOptions, $topicOptions, $posterOptions);

?>
Former SMF Core Developer | My Mods | SimplePortal

Advertisement: