|
#include "main_koen.h"
|
|
|
|
int pool_size=2;
|
|
std::string connection_string="hostaddr = 127.0.0.1 port = 5432 dbname = mydb user = test password = test connect_timeout = 2" ;
|
|
Wt::Dbo::backend::Postgres *gres = new Wt::Dbo::backend::Postgres(connection_string);
|
|
Wt::Dbo::SqlConnectionPool *pool = new Wt::Dbo::FixedSqlConnectionPool(gres,pool_size);
|
|
|
|
WApplication *adminui(const WEnvironment& env)
|
|
{
|
|
WApplication *app = new WApplication(env);
|
|
|
|
new rootw(pool,app->root());
|
|
return app;
|
|
}
|
|
|
|
rootw::rootw(Wt::Dbo::SqlConnectionPool *pool,WContainerWidget *parent):WContainerWidget(parent)
|
|
{
|
|
session.setConnectionPool(*pool);
|
|
|
|
WVBoxLayout *lay= new WVBoxLayout();
|
|
lay->addWidget(e_name=new WLineEdit()); e_name->setMaximumSize(300,WLength::Auto);
|
|
lay->addWidget(e_pass=new WLineEdit()); e_pass->setMaximumSize(300,WLength::Auto);
|
|
// lay->addWidget(e_date=new WLineEdit());
|
|
lay->addWidget(btn=new Ext::Button("fire!"));
|
|
btn->clicked().connect(this,&rootw::submit);
|
|
lay->addWidget(t_status=new WText("<empty>"));
|
|
setLayout(lay);
|
|
}
|
|
|
|
rootw::~rootw()
|
|
{
|
|
|
|
}
|
|
|
|
void rootw::submit()
|
|
{
|
|
try{
|
|
Dbo::Transaction transaction(session);
|
|
session.execute("insert into public.mail_test values (default,?,?,default)")
|
|
.bind(e_name->text().toUTF8()).bind(e_pass->text().toUTF8());
|
|
transaction.commit();
|
|
t_status->setText("ok");
|
|
}catch(Dbo::Exception &a) { t_status->setText(a.what()); session.rereadAll(); }
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
int ret = WRun(argc, argv, &adminui);
|
|
return ret;
|
|
}
|