Vely logo Empower C
install  tutorials  examples
documentation  license  about

12.1.0 released on Sep 19, 2022

Example create table



PURPOSE:


Create table example.

SYNTAX:


See code below.

DESCRIPTION:


Example of manipulating tables via SQL. Table is

This example is included in Vely installation. Here is how to compile and run it.

By default, Vely will automatically restart your application when a new executable is produced.

FILES:


The following are the source files for this project.

setup.sql:
create table if not exists my_table (col1 bigint)

create_table.v:
// SPDX-License-Identifier: Apache-2.0
// Copyright 2018 DaSoftver LLC.

#include "vely.h"

void create_table()
{

    out-header default

    // Drop existing table
    run-query @db = "drop table if exists my_table"  error define err error-text define err_text no-loop
    if (strcmp (err, "0")) {
        report-error "Trouble dropping table, error [%s], error text [%s]", err, err_text
    }
    @Table dropped!<br/>

    // Create table
    run-query @db =  "create table if not exists my_table (my_number bigint)"  error err error-text err_text no-loop
    if (strcmp (err, "0")) {
        report-error "Trouble creating table, error [%s], error text [%s]", err, err_text
    }
    @Table created!<br/>

    // Insert data into table
    run-query @db="insert into my_table (my_number) values ('%s'), ('%s'), ('%s')" : "100", "200", "400" affected-rows define nrows
    end-query
    @Added <<pf-out "%lld", nrows>> rows!<br/>

    // Select data we just inserted
    @Getting data we inserted:<br/>
    run-query @db="select my_number from my_table" output my_number
        @I got number <<query-result my_number>>!<br/>
    end-query

    // Drop the table again
    run-query @db =  "drop table if exists my_table" error err error-text err_text no-loop
    if (strcmp (err, "0")) {
        report-error "Trouble creating table, error [%s], error text [%s]", err, err_text
    }
    @Table dropped!<br/>

}


SEE ALSO:


Examples ( example_cookies   example_create_table   example_docker   example_form   example_hello_world   examples   example_sendmail   example_stock   example_upload_file   example_write_report  )  SEE ALL (documentation)



Copyright (c) 2022 DaSoftver LLC. Vely is a trademark of Dasoftver LLC. The software and information herein are provided "AS IS" and without any warranties or guarantees of any kind. Icons copyright PaweĊ‚ Kuna licensed under MIT. This web page is licensed under CC-BY-SA-4.0.