void add_campaign::on_btn_save_clicked() { // check if we have a campaign name set, otherwise sent warning and abort if ( ui->txt_campaign_name->text() !="" ) { QString app_path = QApplication::applicationDirPath(); QString dbase_path = app_path + "/base.bz"; { QSqlDatabase base = QSqlDatabase::addDatabase("QSQLITE", "create-new-campaign"); base.setDatabaseName(dbase_path); base.open(); if(base.isOpen() != true) { QMessageBox msgbox; msgbox.setText("There was a problem with the database"); msgbox.setInformativeText("Due to unknown reason there was a problem with opening the database.\nThe problem accured during initial opening of the database."); msgbox.exec(); } else { // the database is open // scroll through profiles to determinate if this is really new profile or not QSqlQuery sql_check(base); sql_check.prepare("SELECT * FROM campaign WHERE user LIKE '" + vApp->id_user() + "' AND profile LIKE '" + vApp->id_profile() + "'" " AND campaign_name LIKE '" + ui->txt_campaign_name->text() + "' AND id NOT LIKE '" + ui->txt_campaign_id->text() + "'"); sql_check.exec(); if ( !sql_check.next() ) { // the campaign name is unique QSqlQuery sql_insert(base); if ( ui->txt_campaign_id->text() == "" ) { // insert new campaign sql_insert.prepare("INSERT INTO campaign (user, profile, campaign_name, campaign_description) VALUES (?, ?, ?, ?)"); } else { // update current campaign sql_insert.prepare("UPDATE campaign SET user = ?, profile = ?, campaign_name = ?, campaign_description = ? " "WHERE id LIKE '" + ui->txt_campaign_id->text() + "'"); } sql_insert.bindValue(0, vApp->id_user()); sql_insert.bindValue(1, vApp->id_profile()); sql_insert.bindValue(2, ui->txt_campaign_name->text()); sql_insert.bindValue(3, ui->txt_campaign_description->toPlainText()); sql_insert.exec(); // change global campaign QSqlQuery sql_get_id(base); sql_get_id.prepare("SELECT * FROM campaign WHERE user LIKE '" + vApp->id_user() + "' AND profile LIKE '" + vApp->id_profile() + "'" " AND campaign_name LIKE '" + ui->txt_campaign_name->text() + "'"); sql_get_id.exec(); if ( sql_get_id.next() ) { // the campaign was succesfully saved QMessageBox msgbox; msgbox.setText("Kampanija je bila uspesno shranjen!"); msgbox.exec(); vApp->set_id_campaign(sql_get_id.value(sql_get_id.record().indexOf("id")).toString()); // send signal to the main window to refresh campaign combo box send("refresh-campaign"); } else { // there was an error while saving the campaign QMessageBox msgbox; msgbox.setText("Pri shranjevanju kampanije je prislo do napake!"); msgbox.exec(); } } else { // there already is campaign with this name QMessageBox msgbox; msgbox.setText("Kampanija s tem imenom ze obstaja! Prosim, spremenite ga!"); msgbox.exec(); } } base.close(); } QSqlDatabase::removeDatabase("create-new-campaign"); } else { // the profile name field is empty QMessageBox msgbox; msgbox.setText("Prosim vnesite ime kampanije!"); msgbox.exec(); } }
static void result(SQLHSTMT hstmt, SQLUSMALLINT i, datetime& var) { sql_check(SQL_HANDLE_STMT, hstmt, SQLBindCol(hstmt, i, SQL_C_TIMESTAMP, &var.value_, 0, &var.length_)); }
static void parameter(SQLHSTMT hstmt, SQLUSMALLINT i, datetime& var) { sql_check(SQL_HANDLE_STMT, hstmt, SQLBindParameter(hstmt, i, SQL_PARAM_INPUT, SQL_C_TIMESTAMP, SQL_TIMESTAMP, 0, 0, (SQLPOINTER) &var.value_, sizeof(SQL_TIMESTAMP_STRUCT), (SQLINTEGER*) &var.length_)); }
int main(void) { /* exec sql begin declare section */ #line 49 "test_informix2.pgc" int c ; #line 50 "test_informix2.pgc" timestamp d ; #line 51 "test_informix2.pgc" timestamp e ; #line 52 "test_informix2.pgc" timestamp maxd ; #line 53 "test_informix2.pgc" char dbname [ 30 ] ; /* exec sql end declare section */ #line 54 "test_informix2.pgc" interval *intvl; /* exec sql whenever sqlerror sqlprint ; */ #line 58 "test_informix2.pgc" ECPGdebug(1, stderr); strcpy(dbname, "ecpg1_regression"); { ECPGconnect(__LINE__, 1, dbname , NULL, NULL , NULL, 0); #line 63 "test_informix2.pgc" if (sqlca.sqlcode < 0) sqlprint();} #line 63 "test_informix2.pgc" sql_check("main", "connect", 0); { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "set DateStyle to 'DMY'", ECPGt_EOIT, ECPGt_EORT); #line 66 "test_informix2.pgc" if (sqlca.sqlcode < 0) sqlprint();} #line 66 "test_informix2.pgc" { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "create table history ( customerid integer , timestamp timestamp without time zone , action_taken char ( 5 ) , narrative varchar ( 100 ) )", ECPGt_EOIT, ECPGt_EORT); #line 68 "test_informix2.pgc" if (sqlca.sqlcode < 0) sqlprint();} #line 68 "test_informix2.pgc" sql_check("main", "create", 0); { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "insert into history ( customerid , timestamp , action_taken , narrative ) values ( 1 , '2003-05-07 13:28:34 CEST' , 'test' , 'test' )", ECPGt_EOIT, ECPGt_EORT); #line 73 "test_informix2.pgc" if (sqlca.sqlcode < 0) sqlprint();} #line 73 "test_informix2.pgc" sql_check("main", "insert", 0); { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "select max ( timestamp ) from history", ECPGt_EOIT, ECPGt_timestamp,&(maxd),(long)1,(long)1,sizeof(timestamp), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT); #line 78 "test_informix2.pgc" if (sqlca.sqlcode < 0) sqlprint();} #line 78 "test_informix2.pgc" sql_check("main", "select max", 100); { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "select customerid , timestamp from history where timestamp = $1 limit 1", ECPGt_timestamp,&(maxd),(long)1,(long)1,sizeof(timestamp), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_int,&(c),(long)1,(long)1,sizeof(int), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_timestamp,&(d),(long)1,(long)1,sizeof(timestamp), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT); #line 85 "test_informix2.pgc" if (sqlca.sqlcode < 0) sqlprint();} #line 85 "test_informix2.pgc" sql_check("main", "select", 0); printf("Read in customer %d\n", c); intvl = PGTYPESinterval_from_asc("1 day 2 hours 24 minutes 65 seconds", NULL); PGTYPEStimestamp_add_interval(&d, intvl, &e); free(intvl); c++; { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "insert into history ( customerid , timestamp , action_taken , narrative ) values ( $1 , $2 , 'test' , 'test' )", ECPGt_int,&(c),(long)1,(long)1,sizeof(int), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_timestamp,&(e),(long)1,(long)1,sizeof(timestamp), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT); #line 97 "test_informix2.pgc" if (sqlca.sqlcode < 0) sqlprint();} #line 97 "test_informix2.pgc" sql_check("main", "update", 0); { ECPGtrans(__LINE__, NULL, "commit"); #line 100 "test_informix2.pgc" if (sqlca.sqlcode < 0) sqlprint();} #line 100 "test_informix2.pgc" { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "drop table history", ECPGt_EOIT, ECPGt_EORT); #line 102 "test_informix2.pgc" if (sqlca.sqlcode < 0) sqlprint();} #line 102 "test_informix2.pgc" sql_check("main", "drop", 0); { ECPGtrans(__LINE__, NULL, "commit"); #line 105 "test_informix2.pgc" if (sqlca.sqlcode < 0) sqlprint();} #line 105 "test_informix2.pgc" { ECPGdisconnect(__LINE__, "CURRENT"); #line 107 "test_informix2.pgc" if (sqlca.sqlcode < 0) sqlprint();} #line 107 "test_informix2.pgc" sql_check("main", "disconnect", 0); printf("All OK!\n"); exit(0); /* Table "public.history" Column | Type | Nullable --------------+-----------------------------+---------- customerid | integer | not null timestamp | timestamp without time zone | not null action_taken | character(5) | not null narrative | character varying(100) | */ }