Hello,
I followed the example exactly to disable the version field and I am
still getting a Segmentation fault when I try and run the program.
Here is the .schema of panel1 (the other table p1copy is a copy).
sqlite> .schema panel1
CREATE TABLE panel1(id INTEGER PRIMARY KEY, timestamp DATETIME DEFAULT
CURRENT_TIMESTAMP, parsed_by_logger integer, System_Alarms_Panel1Alarm1A
integer, System_Alarms_Panel1Alarm1B integer,
System_Alarms_Panel1Alarm2A integer, System_Alarms_Panel1Alarm2B
integer, System_Alarms_Panel1Alarm3A integer,
System_Alarms_Panel1Alarm3B integer, System_Alarms_Panel1FreqHop
integer, System_Alarms_Panel1PressSys integer,
System_Alarms_Panel1PressBat integer, System_Alarms_Panel1FlowSys
integer, System_Alarms_Panel1RamSys integer, System_Alarms_Panel1RamBat
integer, Transducers_SignalStrength_LiftForcePressure integer,
Transducers_SignalStrength_SnubForcePressure integer,
Transducers_SignalStrength_THSlipsPressure integer,
Transducers_SignalStrength_Ram1A integer,
Transducers_SignalStrength_Ram1B integer,
Transducers_SignalStrength_Ram2A integer,
Transducers_SignalStrength_Ram2B integer,
Transducers_Packets_THSlipsValve integer,
Transducers_Packets_LiftForcePressure integer,
Transducers_Packets_SnubForcePressure integer,
Transducers_Packets_THSlipsPressure integer,
Transducers_Packets_THSlipsFlow integer, Transducers_Packets_Ram1A
integer, Transducers_Packets_Ram1B integer, Transducers_Packets_Ram2A
integer, Transducers_Packets_Ram2B integer,
Transducers_RFMeter_THSlipsValve integer,
Transducers_RFMeter_LiftForcePressure integer,
Transducers_RFMeter_SnubForcePressure integer,
Transducers_RFMeter_THSlipsPressure integer,
Transducers_RFMeter_THSlipsFlow integer, Transducers_RFMeter_Ram1A
integer, Transducers_RFMeter_Ram1B integer, Transducers_RFMeter_Ram2A
integer, Transducers_RFMeter_Ram2B integer, Config_Freq_Panel1Freq
integer, Config_IDs_Rams_Ram1AID integer, Config_IDs_Rams_Ram1BID
integer, Config_IDs_Rams_Ram2AID integer, Config_IDs_Rams_Ram2BID
integer, Transducers_Rams_Ram1AStatus integer,
Transducers_Rams_Ram1BStatus integer, Transducers_Rams_Ram2AStatus
integer, Transducers_Rams_Ram2BStatus integer,
Config_ED_Rams_Ram1AEnable integer, Config_ED_Rams_Ram1BEnable integer,
Config_ED_Rams_Ram2AEnable integer, Config_ED_Rams_Ram2BEnable integer,
Config_Activate_Rams_Ram1A integer, Config_Activate_Rams_Ram1B integer,
Config_Activate_Rams_Ram2A integer, Config_Activate_Rams_Ram2B integer,
Transducers_Pressures_LiftForcePressure integer,
Transducers_Pressures_SnubForcePressure integer,
Transducers_Pressures_THSlips integer, Config_IDs_Valves_THSlipsValveID
integer, Config_ED_Valves_THSlipsValveEnable integer,
Config_Activate_Valves_THSlipsValve integer,
Config_IDs_Pressures_LiftForcePressureID integer,
Config_IDs_Pressures_SnubForcePressureID integer,
Config_IDs_Pressures_TH integer,
Config_ED_Pressures_LiftForcePressureEnable integer,
Config_ED_Pressures_SnubForcePressureEnable integer,
Config_ED_Pressures_TH integer,
Config_Activate_Pressures_LiftForcePressure integer,
Config_Activate_Pressures_SnubForcePressure integer,
Config_Activate_Pressures_TH integer,
Config_Cal_PressureZero_LiftForcePressureZero integer,
Config_Cal_PressureZero_SnubForcePressureZero integer,
Config_Cal_PressureZero_TH integer,
Config_Cal_PressureADZero_LiftForcePressureADZero integer,
Config_Cal_PressureADZero_SnubForcePressureADZero integer,
Config_Cal_PressureADZero_TH integer,
Config_Cal_PressureSpan_LiftForcePressureSpan integer,
Config_Cal_PressureSpan_SnubForcePressureSpan integer,
Config_Cal_PressureSpan_TH integer,
Config_Cal_PressureADSpan_LiftForcePressureADSpan integer,
Config_Cal_PressureADSpan_SnubForcePressureADSpan integer,
Config_Cal_PressureADSpan_TH integer, Config_IDs_Pressures_Dupes_SH
integer, Config_ED_Pressures_Dupes_SH integer,
Config_Activate_Pressures_Dupes_SH integer,
Config_Cal_PressureZero_Dupes_SH integer,
Config_Cal_PressureADZero_Dupes_SH integer,
Config_Cal_PressureSpan_Dupes_SH integer,
Config_Cal_PressureADSpan_Dupes_SH integer,
Transducers_Flows_THSlipsFlowCounts integer, Config_IDs_Flows_TH
integer, Config_IDs_Flows_Dupes_SH integer, Config_ED_Flows_TH integer,
Config_ED_Flows_Dupes_SH integer, Config_Activate_Flows_TH integer,
Config_Activate_Flows_Dupes_SH integer, Transducers_Valves_THSlipsInputs
integer, Transducers_Valves_THSlipsOutputs integer,
Config_Cal_SlipsPressure_THThreshold integer,
Config_Cal_SlipsPressure_Dupes_SHThreshold integer,
Config_Cal_Position_THOpenA integer, Config_Cal_Position_THOpenB
integer, Config_Cal_Position_Dupes_SHOpenA integer,
Config_Cal_Position_Dupes_SHOpenB integer, Config_Cal_Position_THClosedA
integer, Config_Cal_Position_THClosedB integer,
Config_Cal_Position_Dupes_SHClosedA integer,
Config_Cal_Position_Dupes_SHClosedB integer,
Config_slipsmart_slips_setup_TH integer,
Config_Cal_Tolerances_Flows_THRecalOpenPercentage integer,
Config_Cal_Tolerances_Flows_THClosedPercentage integer,
Transducers_Slips_TH integer,
Config_Cal_Tolerances_Flows_Dupes_SHClosedPercentage integer,
Config_Cal_SlipsPressure_THMin integer,
Config_Cal_SlipsPressure_Dupes_SHMin integer, Config_Cal_Valves_TH1Pos1
integer, Config_Cal_Valves_TH1Pos2 integer, Config_Cal_Valves_TH2Pos1
integer, Config_Cal_Valves_TH2Pos2 integer,
Config_Cal_Tolerances_Valves_TH1PerMil integer,
Config_Cal_Tolerances_Valves_TH2PerMil integer);
CREATE TRIGGER alarms_trigger1 AFTER INSERT ON panel1 BEGIN UPDATE
alarms SET alarming = (SELECT p1.System_Alarms_Panel1RamSys OR
p2.System_Alarms_Panel2RamSys OR p3.System_Alarms_Panel3RamSys OR
p4.System_Alarms_Panel4RamSys from p1, p2, p3, p4) WHERE
name='RamSysAlarm'; UPDATE alarms SET alarming = (SELECT
p1.System_Alarms_Panel1RamBat OR p2.System_Alarms_Panel2RamBat OR
p3.System_Alarms_Panel3RamBat OR p4.System_Alarms_Panel4RamBat from p1,
p2, p3, p4) WHERE name='RamBatAlarm'; UPDATE alarms SET alarming =
(SELECT p1.System_Alarms_Panel1PressSys OR
p2.System_Alarms_Panel2PressSys from p1, p2) WHERE name='PressSysAlarm';
END;
On 12-05-31 12:37 AM, Nagaev Boris wrote:
Hello!
How to disable version field:
http://www.webtoolkit.eu/wt/doc/tutorial/dbo.html#customizing
Have you followed this instruction?
Show current tables structure (output of ".tables" in sqlite3
interactive mode), please.
Could you attach the code (causing Segmentation fault)?
On Thu, May 31, 2012 at 9:39 AM, Joel<[email protected]> wrote:
Hello,
Nageaev, thank you very much for taking the time to make a compilable and
working version of my application. I
I just have a quick follow up question based on the changes.
When I compile my program I get the following error:
what(): Sqlite3: insert into "p1copy" ("version",
"Config_IDs_Rams_Ram1AID", "Config_IDs_Rams_Ram1BID",
"Config_IDs_Rams_Ram2AID", "Config_IDs_Rams_Ram2BID") values (?, ?, ?, ?,
?): table p1copy has no column named version
Now I know this is a sqlite3 error that has occured because of the version
field and when I suppress the version field I get a Segmentation fault.
Thanks again for your response.
Joel
On 12-05-30 12:22 AM, Nagaev Boris wrote:
Hello!
Changes:
1. WItemDelegate is not a widget. It should be set to view by
view->setItemDelegateForColumn() (or setItemDelegate if you want it
for all the columns)
2. Function create_database should call session.createTables() to create
tables.
3. Fields in Panel1 were mixed up (Config_Cal_Position_THClosedB wa
mapped twice and Config_Cal_Position_THClosedB was mapped to
"Config_Cal_Position_THClosedb" (last letter "b", not "B").
4. To make this work, I removed Instructions table and create Panel2
class -- a copy of Panel1. Fields of Instructions differ from fields
of Panel1, so entry of Panel1 can't be saved to Instructions directly
(column to column): some domain specific transformation is needed
(change code of writeMod::setModelData to apply custom transformation
from one table to another).
5. When declaring methods in C++ inside class (event if they are
overloaded from ancestor class), do not mention class name. I mean, it
should be "setModelData" instead of "WItemDelegate::setModelData".
6. Every function or method should have return type (except
constructor and destructor). So it should be "void setModelData"
7. I have added constructor to writeMod class. It takes a pointer to
another model (writable) and save it as a field. Then in
setModelData() method this saved pointer would be used to save data
to.
8. Each operation with database should be done under active
transaction (see create_database())
Compilable and working version is attached.
One entry of Panel1 is created from the beginning. Whenever it is
edited in the view, modified version of it is stored to "p2" table.
This code can be changed to implement "Instructions" logic.
On Wed, May 30, 2012 at 3:45 AM, Joel<[email protected]> wrote:
Hello,
Thank you for your reply Nagaev, I very much appreciate it.
I have created two models for each one of my tables, and the read-only table
is set with view->setModel. I am having an issue with your third step
3. Inherit from WItemDelegate, overload method
WItemDelegate::setModelData with custom function, saving data to
another model (instructions table).
I am using the WItemDelegate class and following the example of how to deal
with a specialized editor and I have implemented the following in my code:
class mainWindow : public WContainerWidget
{
public:
mainWindow (dbo::Session& session, WContainerWidget *parent=0)
: WContainerWidget (parent)
{
dbo::QueryModel< dbo::ptr<Panel1> > *model = new dbo::QueryModel<
dbo::ptr<Panel1> >();
model->setQuery(session.find<Panel1>());
model->addColumn("Config_Cal_Position_THClosedB",ItemIsEditable);
model->addColumn("Config_IDs_Rams_Ram1AID",ItemIsEditable);
WTableView *view = new WTableView (this);
view->resize(800, 300);
view->setSelectionMode(SingleSelection);
view->setModel(model);
}
};
class writeMod : public WItemDelegate
{
public:
WItemDelegate::setModelData(const boost::any& editState,
Wt::WAbstractItemModel *model, const Wt::WModelIndex& index) const
{
model ->setData(index, editState, EditRole);
}
};
I am getting the following error
make[2]: Entering directory `/home/joel/moxa/awesomesauce/src'
arm-linux-g++ -DHAVE_CONFIG_H -I. -I..
-I/home/joel/moxa/witty_dist/usr/include
-I/home/joel/moxa/boost_dist/include -I/usr/local/arm-linux/include/
-mcpu=arm920t -MT awesomesauce.o -MD -MP -MF .deps/awesomesauce.Tpo -c -o
awesomesauce.o awesomesauce.cpp
awesomesauce.cpp:193: error: ISO C++ forbids declaration of ‘setModelData’
with no type
awesomesauce.cpp:193: error: cannot define member function
‘Wt::WItemDelegate::setModelData’ within ‘writeMod’
awesomesauce.cpp: In constructor ‘MyApplication::MyApplication(const
Wt::WEnvironment&)’:
awesomesauce.cpp:218: error: no matching function for call to
‘writeMod::writeMod(Wt::Dbo::Session&, Wt::WContainerWidget*)’
awesomesauce.cpp:191: note: candidates are: writeMod::writeMod()
awesomesauce.cpp:191: note: writeMod::writeMod(const
writeMod&)
make[2]: *** [awesomesauce.o] Error 1
make[2]: Leaving directory `/home/joel/moxa/awesomesauce/src'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/joel/moxa/awesomesauce'
make: *** [all] Error 2
I am new to c++ and web development so I know these errors probably seem
basic, I have tried to use WItemDelegate in a number of different ways but I
cannot get my code to compile. I tried using my WItemDelegate::setModelData
statment within the mainWindow class, but I got a compiler error telling me
that I cannot use this expression with the class, that is why I created a
new class writeMod.
I am going to continue to try and figure out what is going on, but if
someone has any ideas I would be very grateful.
Thanks,
Joel
On 12-05-29 02:51 AM, Nagaev Boris wrote:
Hello,
I think, this should help:
1. Create two models, first is targeted to read-only table, second to
instructions table.
2. Set one model (read-only table) with view->setModel
3. Inherit from WItemDelegate, overload method
WItemDelegate::setModelData with custom function, saving data to
another model (instructions table).
4. Set this item delegate using view->setItemDelegateForColumn for all
editable columns
Probably, you have to create two classes (one class per table) and to
map them both (Dbo::Session::mapClass).
To avoid code duplication, you can create one base class with all
needed fields, and inherit from them two empty classes.
On Tue, May 29, 2012 at 2:28 AM, Joel<[email protected]> wrote:
Hello,
I am working on an application which queries a sqlite3 database and adds
columns to a WTableView so that they can be displayed on a web browser.
The
data that is displayed on the web browser is editable but I do not want
to
write the edited result to the same table which it was queried from.
class mainWindow : public WContainerWidget
{
public:
mainWindow (dbo::Session& session, WContainerWidget *parent=0)
: WContainerWidget (parent)
{
dbo::QueryModel< dbo::ptr<Panel1> > *model = new dbo::QueryModel<
dbo::ptr<Panel1> >();
model->setQuery(session.find<Panel1>());
model->addColumn("Config_Cal_Position_THClosedB",ItemIsEditable);
model->addColumn("Config_IDs_Rams_Ram1AID",ItemIsEditable);
WTableView *view = new WTableView (this);
view->resize(800, 300);
view->setSelectionMode(SingleSelection);
view->setModel(model);
}
The<Panel1> table is a view only table, in order to edit the data I have
to
do so through an instruction table via the following sqlite3 command
insert into instructions(instruction_type, port, param1, param2, param3)
values (0,<1-4>, 86,<register name>,<register value>);
So basically, I am attempting to read from table<Panel1>, have the
ability
to edit the data on a browser, and write the edited result to
the<register
value> parameter of the instruction table.
Your help would be greatly appreciated!
Thanks,
Joel
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest
#include <Wt/WApplication>
#include <Wt/WContainerWidget>
#include <Wt/WEnvironment>
#include <Wt/WTableView>
#include <Wt/WText>
#include <Wt/WItemDelegate>
using namespace Wt;
#include <Wt/Dbo/Dbo>
#include <Wt/Dbo/Transaction>
#include <Wt/Dbo/backend/Sqlite3>
#include <Wt/Dbo/QueryModel>
#include <Wt/Dbo/SqlConnection>
#include <Wt/Dbo/WtSqlTraits>
namespace dbo = Wt::Dbo;
#include <string>
using namespace std;
// DataBase definition.
class Panel1 {
public:
int Config_IDs_Rams_Ram1AID, Config_IDs_Rams_Ram1BID, Config_IDs_Rams_Ram2AID, Config_IDs_Rams_Ram2BID;
template<class Action>
void persist(Action& a)
{
dbo::field(a, Config_IDs_Rams_Ram1AID, "Config_IDs_Rams_Ram1AID");
dbo::field(a, Config_IDs_Rams_Ram1BID, "Config_IDs_Rams_Ram1BID");
dbo::field(a, Config_IDs_Rams_Ram2AID, "Config_IDs_Rams_Ram2AID");
dbo::field(a, Config_IDs_Rams_Ram2BID, "Config_IDs_Rams_Ram2BID");
}
};
namespace Wt {
namespace Dbo {
template<>
struct dbo_traits<Panel1> : public dbo_default_traits {
static const char *versionField() {
return 0;
}
};
}
}
class CopyPanel1 {
public:
int Config_IDs_Rams_Ram1AID, Config_IDs_Rams_Ram1BID, Config_IDs_Rams_Ram2AID, Config_IDs_Rams_Ram2BID;
template<class Action>
void persist(Action& a)
{
dbo::field(a, Config_IDs_Rams_Ram1AID, "Config_IDs_Rams_Ram1AID");
dbo::field(a, Config_IDs_Rams_Ram1BID, "Config_IDs_Rams_Ram1BID");
dbo::field(a, Config_IDs_Rams_Ram2AID, "Config_IDs_Rams_Ram2AID");
dbo::field(a, Config_IDs_Rams_Ram2BID, "Config_IDs_Rams_Ram2BID");
}
};
namespace Wt {
namespace Dbo {
template<>
struct dbo_traits<CopyPanel1> : public dbo_default_traits {
static const char *versionField() {
return 0;
}
};
}
}
void create_database(void) {
dbo::Session session;
dbo::backend::Sqlite3 sqlite3("slipsmart.sl3");
session.setConnection(sqlite3);
dbo::Transaction t(session);
session.mapClass<Panel1>("panel1");
session.mapClass<CopyPanel1>("p1copy");
try {
session.createTables();
} catch (...) {
// tabls already created
}
t.commit();
dbo::Transaction t2(session);
session.add(new CopyPanel1());
t2.commit();
}
class writeMod : public WItemDelegate {
public:
writeMod(dbo::QueryModel<dbo::ptr<CopyPanel1> >* model2, WObject* parent = 0):
WItemDelegate(parent),
model2_(model2)
{ }
void setModelData(const boost::any& editState,
Wt::WAbstractItemModel* model,
const Wt::WModelIndex& index) const {
// add new row to Copy
model2_->insertRows(model2_->rowCount(), 1);
// Calculate index in Copy
WModelIndex index2 = model2_->index(model2_->rowCount() - 1,
index.column());
// Update value in Copy
model2_->setData(index2, editState, EditRole);
}
private:
dbo::QueryModel<dbo::ptr<CopyPanel1> >* model2_;
};
class mainWindow : public WContainerWidget
{
public:
mainWindow (dbo::Session & session, WContainerWidget *parent=0)
: WContainerWidget (parent)
{
dbo::QueryModel< dbo::ptr<Panel1> > *model1 = new dbo::QueryModel< dbo::ptr<Panel1> >();
model1->setQuery(session.find<Panel1>().where("oid = (select max(oid) from panel1)"));
model1->addColumn("Config_IDs_Rams_Ram1AID",ItemIsEditable);
model1->addColumn("Config_IDs_Rams_Ram1BID",ItemIsEditable);
model1->addColumn("Config_IDs_Rams_Ram2AID",ItemIsEditable);
model1->addColumn("Config_IDs_Rams_Ram2BID",ItemIsEditable);
//
dbo::QueryModel< dbo::ptr<CopyPanel1> >* model2 = new dbo::QueryModel< dbo::ptr<CopyPanel1> >();
model2->setQuery(session.find<CopyPanel1>());
model2->addColumn("Config_IDs_Rams_Ram1AID",ItemIsEditable);
model2->addColumn("Config_IDs_Rams_Ram1BID",ItemIsEditable);
model2->addColumn("Config_IDs_Rams_Ram2AID",ItemIsEditable);
model2->addColumn("Config_IDs_Rams_Ram2BID",ItemIsEditable);
//
WTableView *view = new WTableView (this);
view->setModel(model1);
view->setItemDelegate(new writeMod(model2, view));
view->setSelectionMode(SingleSelection);
view->resize(800, 300);
}
};
class MyApplication : public WApplication
{
private:
dbo::Session session;
dbo::backend::Sqlite3 sqlite3;
public:
MyApplication (WEnvironment const & env)
: WApplication (env), sqlite3 ("slipsmart.sl3")
{
session.setConnection (sqlite3);
session.mapClass<Panel1>("panel1");
session.mapClass<CopyPanel1>("p1copy");
setTitle("Slipsmart Version 2.0");
root () -> addWidget (new mainWindow (session, root ()));
}
~MyApplication (void) { std::cout << "MyApplication dead" << std::endl; }
};
WApplication * createApplication (WEnvironment const & env)
{ return new MyApplication (env); }
int main(int argc, char **argv)
{
create_database();
return WRun (argc, argv, & createApplication);
}
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest