Insertion of registers in tables. Returns the number of registers inserted.

1 insert

<insert
    table='table'
    columns='columns'
    prefix='prefix'
    preserve-serial='true|false'
    intotemp='intotemp'
    prepare-cache='true|false'
    preserve-serial='true|false'
    struct='struct'
>
    <column /> *
    <select /> ?
</insert>

Exceptions

database required

You need to specify the database

The specified table is not in the database

The table does not exist

required attribute [...]

A required attribute has not been informed

column [...] not found in table [...]

Column not found

insert with prefix attribute is incompatible with column elements

The attribute column and the attribute prefix are excluding.

Remarks

To insert registers, it is necessary which the user is identified and which a database is selected. This is informed through the options -user and -dbms of the command ws-dbscript.

Example

Insert registers in a table.

Copy
<xsql-script name='insert_sample1'>
    <body>
        <set name='m_linid'>'abc'</set>
        <set name='m_cabid'>'product'</set>
        <set name='m_codean'>1</set>
        <set name='m_codart'>002</set>
        <set name='varstk'>N</set>

        <insert table='geanmovl'>
            <column name='linid'><m_linid /></column>
            <column name='cabid'><m_cabid /></column>
            <column name='codean'><m_codean /></column>
            <column name='codart'><m_codart /></column>
            <column name='varstk'><m_varstk /></column>
        </insert>
    </body>
</xsql-script>

The content of the variables m_linid, m_cabid, m_codean, m_codart y m_varstk is inserted in the columns linid, cabid, codean, codart y varstk de la tabla geanmovl.

Example

Insert registers in the table using the attribute prefix.

Copy
<xsql-script name='insert_sample2'>
    <body>
        <set name='ccospool_order'>123</set>
        <set name='ccospool_projec'><captpool_projec/></set>
        <set name='ccospool_sectio'><captpool_sectio/></set>
        <set name='ccospool_jusser'><captpool_jusser/></set>
        <set name='ccospool_docser'><captpool_docser/></set>
        <set name='ccospool_accoun'><captpool_accoun/></set>
        <set name='ccospool_ctaexp'><captplag_ctaexp/></set>
        <set name='ccospool_center'><captplag_center/></set>
        <!-- Insertion of the note -->
        <insert table='ccospool' prefix='ccospool_' />
    </body>
</xsql-script>

The order column is of serial type. You can observe that in this case, its value will not be preserved so, the inserted register will be serialized with the new value.

Example

Insert registers in a table using the attributes prefix and preserve-serial.

Copy
<xsql-script name='insert_sample2'>
    <body>
        <set name='ccospool_order'>123</set>
        <set name='ccospool_projec'><captpool_projec/></set>
        <set name='ccospool_sectio'><captpool_sectio/></set>
        <set name='ccospool_jusser'><captpool_jusser/></set>
        <set name='ccospool_docser'><captpool_docser/></set>
        <set name='ccospool_accoun'><captpool_accoun/></set>
        <set name='ccospool_ctaexp'><captplag_ctaexp/></set>
        <set name='ccospool_center'><captplag_center/></set>
        <!-- Insertion of the note -->
        <insert table='ccospool' prefix='ccospool_' preserve-serial='true' />
    </body>
</xsql-script>

The order column is of serial type. You can observe that in this case, its value will be preserved so, the inserted register will be registered with the proposed value.

Example

Insert registers in a table using a structure.

Copy
<xsql-script name='insert_sample2'>
    <body>
        <set name='ccospool_order'>123</set>
        <set name='ccospool_projec'><captpool_projec/></set>
        <set name='ccospool_sectio'><captpool_sectio/></set>
        <set name='ccospool_jusser'><captpool_jusser/></set>
        <set name='ccospool_docser'><captpool_docser/></set>
        <set name='ccospool_accoun'><captpool_accoun/></set>
        <set name='ccospool_ctaexp'><captplag_ctaexp/></set>
        <set name='ccospool_center'><captplag_center/></set>
        <!-- Inserción del apunte -->
        <insert table='ccospool' prefix='ccospool_' preserve-serial='true' />
    </body>
</xsql-script><xsql-script name='insert_sample4'>
    <body>       
        <drop table='@tmp_test_users_temp' onexception='ignore' />
        
        <table name='@tmp_test_users_temp' temp='yes'>
           <column name='dni'        type='serial'         required='y' />
           <column name='name'       type='char' size='20' required='y' />
           <column name='surname'    type='char' size='30' required='y' />
           <column name='adress'     type='char' size='35' required='y' />
           <column name='age'        type='integer'        required='y' />
        </table>
        
        <struct.declare type='std_test'>
		    <field name='dni'  type='integer' />
		    <field name='name' type='string'  />
		    <field name='surname' type='string'  />
		    <field name='adress' type='string'  />
		    <field name='age' type='integer' />
		</struct.declare>

		<set name='s'>
		    <struct type='std_test' />
		</set>

		<struct.set name='s'>
		    <field name='dni'>0</field>
		    <field name='name'>John</field>
		    <field name='surname'>Matthew</field>
		    <field name='adress'>35 cross road</field>
		    <field name='age'>48</field>
	    </struct.set>        
                
        <!-- Insertion of the note -->        
        <insert table='@tmp_test_user_temp' struct='s' />

        <print.sql head='true'>
            <select>
                <columns>
                    *
                </columns>
                <from table='@tmp_test_user_temp' />
            </select>        
        </print.sql> 
	</body>
</xsql-script>

Once the structure is generated, the registers in the table are inserted.

The insertions in XSQL-Script also offers the advantage of the attribute use prefix. When the values which you pretend to introduce in the table, are asigned to variables which has been generated automatically by a <select> sentence, it is not necessary to indicate the differents columns nor the differents values when inserting. It is possible to insert the registers indicating each column with the argument column or inserting a select query. You can see the following example of prefix attribute use: <example>.

Copy
<insert table='cacajamov' prefix='ccajamov_'>

info

The attributes prefix and preserve-serial and the columns argument are excluding.

The columns of serial type should not be related in the lists of the column or select arguments, the database managers will be in charge of the serialization.