On install how can I insert a default record

On install how can I insert a default record

by Stuart Buck -
Number of replies: 4
I have a block that installs fine and creates its own db table but I would like to add a default single record.

Can anyone tell me what is the best way of doing this is please.

Average of ratings: -
In reply to Stuart Buck

Re: On install how can I insert a default record

by tony chesney -

In your install.xml file that creates the table(s) for the block when someone installs the block, the XMLDB schema allows for  a <STATEMENTS> container where you put <SENTENCE> 's that define records you want to go into the table(s). 

The XMLDB editor will create the XML for you although I don't find it that intuitive to use.  There's some documentation here.

Average of ratings: Useful (1)
In reply to tony chesney

Re: On install how can I insert a default record

by Stuart Buck -
Superb,

That's just what i was after

cheers.
In reply to Stuart Buck

Re: On install how can I insert a default record

by Samuel Kelemen -

I try to add row into database but no effect. 

My code:

<xmldb>

<tables>

//some tables

</tables>

<STATEMENTS>
<STATEMENT NAME="insert citaty_druh_media" TYPE="insert" TABLE="citaty_druh_media" COMMENT="Initial insert of records on table log_display">
<SENTENCES>
<SENTENCE TEXT="(id, druh_media) VALUES (1, '[online]')" />
</SENTENCES>
</STATEMENT>

<STATEMENT NAME="insert log_display" TYPE="insert" TABLE="log_display" COMMENT="Initial insert of records on table log_display">
<SENTENCES>
<SENTENCE TEXT="(module, action, mtable, field) VALUES ('guidedquiz', 'add', 'guidedquiz', 'name')" />
</SENTENCES>
</STATEMENT>
 </STATEMENTS>

</xmldb>

 

What doing i wrong please ?

In reply to Samuel Kelemen

Re: On install how can I insert a default record

by Helder Nascimento -

Hi!

I found out that STATEMENTS are no longer supported (my version is 2.4).

You must use  db/install.php for your insert statements.