Commit 18f43cda authored by Jonas Nylund's avatar Jonas Nylund

SEV No limit in long attribute names anymore

parent 58cca3fd
...@@ -318,73 +318,6 @@ int sev_server::send_itemlist( qcom_sQid tgt) ...@@ -318,73 +318,6 @@ int sev_server::send_itemlist( qcom_sQid tgt)
} }
return 1; return 1;
} }
/*
int sev_server::send_itemlist( qcom_sQid tgt)
{
int item_cnt = 0;
qcom_sPut put;
pwr_tStatus sts, lsts;
int size;
for ( unsigned int i = 0; i < m_db->m_items.size(); i++) {
if ( m_db->m_items[i].deleted)
continue;
item_cnt++;
}
if ( !item_cnt)
return 1;
size = sizeof(sev_sMsgHistItems) + (item_cnt - 1) * sizeof(sev_sHistItem);
put.size = size;
put.data = qcom_Alloc(&lsts, put.size);
((sev_sMsgHistItems *)put.data)->Type = sev_eMsgType_HistItems;
((sev_sMsgHistItems *)put.data)->NumItems = item_cnt;
int idx = 0;
for ( unsigned int i = 0; i < m_db->m_items.size(); i++) {
if ( m_db->m_items[i].deleted)
continue;
((sev_sMsgHistItems *)put.data)->Items[idx].oid = m_db->m_items[i].oid;
strcpy( ((sev_sMsgHistItems *)put.data)->Items[idx].oname, m_db->m_items[i].oname);
((sev_sMsgHistItems *)put.data)->Items[idx].storagetime =
net_DeltaTimeToNetTime(&m_db->m_items[i].storagetime);
((sev_sMsgHistItems *)put.data)->Items[idx].creatime =
net_TimeToNetTime( &m_db->m_items[i].creatime);
((sev_sMsgHistItems *)put.data)->Items[idx].modtime =
net_TimeToNetTime( &m_db->m_items[i].modtime);
strcpy( ((sev_sMsgHistItems *)put.data)->Items[idx].description, m_db->m_items[i].description);
strcpy( ((sev_sMsgHistItems *)put.data)->Items[idx].attr[0].aname, m_db->m_items[i].attr[0].aname);
((sev_sMsgHistItems *)put.data)->Items[idx].attrnum = m_db->m_items[i].attrnum;
((sev_sMsgHistItems *)put.data)->Items[idx].attr[0].type = m_db->m_items[i].attr[0].type;
((sev_sMsgHistItems *)put.data)->Items[idx].attr[0].size = m_db->m_items[i].attr[0].size;
strcpy( ((sev_sMsgHistItems *)put.data)->Items[idx].attr[0].unit, m_db->m_items[i].attr[0].unit);
((sev_sMsgHistItems *)put.data)->Items[idx].scantime = m_db->m_items[i].scantime;
((sev_sMsgHistItems *)put.data)->Items[idx].deadband = m_db->m_items[i].deadband;
((sev_sMsgHistItems *)put.data)->Items[idx].options = m_db->m_items[i].options;
idx++;
}
if ( !item_cnt)
((sev_sMsgHistItems *)put.data)->Status = SEV__NOITEMS;
else
((sev_sMsgHistItems *)put.data)->Status = SEV__SUCCESS;
put.reply.nid = m_nodes[0].nid;
put.reply.qix = sev_eProcSevServer;
put.type.b = (qcom_eBtype) sev_cMsgClass;
put.type.s = (qcom_eStype) sev_eMsgType_HistItems;
put.msg_id = m_msg_id++;
if ( !qcom_Put( &sts, &tgt, &put)) {
qcom_Free( &sts, put.data);
return 0;
}
return 1;
}
*/
int sev_server::send_server_status( qcom_sQid tgt) int sev_server::send_server_status( qcom_sQid tgt)
{ {
...@@ -584,7 +517,7 @@ int sev_server::check_histitems( sev_sMsgHistItems *msg, unsigned int size) ...@@ -584,7 +517,7 @@ int sev_server::check_histitems( sev_sMsgHistItems *msg, unsigned int size)
attributeName[0] = '\0'; attributeName[0] = '\0';
storagetime = net_NetTimeToDeltaTime( &buffP->storagetime ); storagetime = net_NetTimeToDeltaTime( &buffP->storagetime );
sprintf( tablename, "obj_%s", m_db->oid_to_table( buffP->oid, attributeName) ); sprintf( tablename, "HiaHia"); //Dummy-name, real name created in add_objectitem
bool newobject = false; bool newobject = false;
if ( !m_db->check_objectitem( &m_sts, if ( !m_db->check_objectitem( &m_sts,
tablename, tablename,
...@@ -650,7 +583,6 @@ int sev_server::check_histitems( sev_sMsgHistItems *msg, unsigned int size) ...@@ -650,7 +583,6 @@ int sev_server::check_histitems( sev_sMsgHistItems *msg, unsigned int size)
//rename the table to something and create a new one. //rename the table to something and create a new one.
//this is the only way to do this without hanging the server for several minutes //this is the only way to do this without hanging the server for several minutes
m_db->handle_objectchange(&m_sts, tablename, idx, newobject); m_db->handle_objectchange(&m_sts, tablename, idx, newobject);
} }
//If node is coming up again we do not want deadband to be active due to init of old_value //If node is coming up again we do not want deadband to be active due to init of old_value
...@@ -700,6 +632,7 @@ int sev_server::check_histitems( sev_sMsgHistItems *msg, unsigned int size) ...@@ -700,6 +632,7 @@ int sev_server::check_histitems( sev_sMsgHistItems *msg, unsigned int size)
msg->Items[i].deadband, msg->Items[i].options, &idx); msg->Items[i].deadband, msg->Items[i].options, &idx);
if ( EVEN(m_sts)) return m_sts; if ( EVEN(m_sts)) return m_sts;
} }
if ( ODD(m_sts) ) { if ( ODD(m_sts) ) {
//Create space for the old values used if we have deadband active //Create space for the old values used if we have deadband active
if ( m_db->m_items[idx].old_value != 0 ) { if ( m_db->m_items[idx].old_value != 0 ) {
...@@ -788,10 +721,8 @@ int sev_server::send_histdata( qcom_sQid tgt, sev_sMsgHistDataGetRequest *rmsg, ...@@ -788,10 +721,8 @@ int sev_server::send_histdata( qcom_sQid tgt, sev_sMsgHistDataGetRequest *rmsg,
starttime = net_NetTimeToTime( &rmsg->StartTime); starttime = net_NetTimeToTime( &rmsg->StartTime);
endtime = net_NetTimeToTime( &rmsg->EndTime); endtime = net_NetTimeToTime( &rmsg->EndTime);
sev_item item; sev_item item;
char tablename[500];
strcpy( tablename, m_db->oid_to_table( rmsg->Oid, rmsg->AName) );
m_db->get_item(&m_sts, &item, tablename); m_db->get_item(&m_sts, &item, rmsg->Oid, rmsg->AName);
if(ODD(m_sts)) { if(ODD(m_sts)) {
m_db->get_values( &m_sts, rmsg->Oid, item.options, item.deadband, m_db->get_values( &m_sts, rmsg->Oid, item.options, item.deadband,
rmsg->AName, item.attr[0].type, item.attr[0].size, rmsg->AName, item.attr[0].type, item.attr[0].size,
...@@ -848,10 +779,8 @@ int sev_server::send_objecthistdata( qcom_sQid tgt, sev_sMsgHistDataGetRequest * ...@@ -848,10 +779,8 @@ int sev_server::send_objecthistdata( qcom_sQid tgt, sev_sMsgHistDataGetRequest *
starttime = net_NetTimeToTime( &rmsg->StartTime); starttime = net_NetTimeToTime( &rmsg->StartTime);
endtime = net_NetTimeToTime( &rmsg->EndTime); endtime = net_NetTimeToTime( &rmsg->EndTime);
sev_item item; sev_item item;
char tablename[500];
sprintf( tablename, "obj_%s", m_db->oid_to_table( rmsg->Oid, rmsg->AName) );
m_db->get_objectitem(&m_sts, &item, tablename); m_db->get_objectitem(&m_sts, &item, rmsg->Oid, rmsg->AName);
if(ODD(m_sts)) { if(ODD(m_sts)) {
m_db->get_objectvalues(&m_sts, &item, item.value_size, &starttime, &endtime, rmsg->NumPoints, &tbuf, &vbuf, &rows); m_db->get_objectvalues(&m_sts, &item, item.value_size, &starttime, &endtime, rmsg->NumPoints, &tbuf, &vbuf, &rows);
} }
...@@ -959,7 +888,7 @@ void sev_server::garbage_item( int idx) ...@@ -959,7 +888,7 @@ void sev_server::garbage_item( int idx)
m_db->m_items[idx].options, limit); m_db->m_items[idx].options, limit);
} }
else { else {
m_db->delete_old_data( &m_sts, m_db->m_items[idx].oid, m_db->m_items[idx].attr[0].aname, m_db->delete_old_data( &m_sts, m_db->m_items[idx].tablename,
m_db->m_items[idx].options, limit); m_db->m_items[idx].options, limit);
} }
} }
......
...@@ -92,7 +92,7 @@ class sev_db { ...@@ -92,7 +92,7 @@ class sev_db {
pwr_tTime *endtime, int maxsize, pwr_tTime **tbuf, void **vbuf, pwr_tTime *endtime, int maxsize, pwr_tTime **tbuf, void **vbuf,
unsigned int *bsize) { return 0;} unsigned int *bsize) { return 0;}
virtual int get_items( pwr_tStatus *sts) { return 0;} virtual int get_items( pwr_tStatus *sts) { return 0;}
virtual int delete_old_data( pwr_tStatus *sts, pwr_tOid oid, char *aname, virtual int delete_old_data( pwr_tStatus *sts, char *tablename,
pwr_tMask options, pwr_tTime limit) { return 0;} pwr_tMask options, pwr_tTime limit) { return 0;}
virtual char *oid_to_table( pwr_tOid oid, char *aname) { return 0;} virtual char *oid_to_table( pwr_tOid oid, char *aname) { return 0;}
...@@ -106,8 +106,8 @@ class sev_db { ...@@ -106,8 +106,8 @@ class sev_db {
pwr_tFloat32 deadband, pwr_tMask options, unsigned int *idx) { return 0;} pwr_tFloat32 deadband, pwr_tMask options, unsigned int *idx) { return 0;}
virtual int store_objectitem( pwr_tStatus *sts, char *tablename, pwr_tOid oid, char *oname, char *aname, virtual int store_objectitem( pwr_tStatus *sts, char *tablename, pwr_tOid oid, char *oname, char *aname,
pwr_tDeltaTime storagetime, char *description, pwr_tFloat32 scantime, pwr_tFloat32 deadband, pwr_tMask options) { return 0;} pwr_tDeltaTime storagetime, char *description, pwr_tFloat32 scantime, pwr_tFloat32 deadband, pwr_tMask options) { return 0;}
virtual int get_item( pwr_tStatus *sts, sev_item *item, char *tablename) { return 0;} virtual int get_item( pwr_tStatus *sts, sev_item *item, pwr_tOid oid, char *attributename) { return 0;}
virtual int get_objectitem( pwr_tStatus *sts, sev_item *item, char *tablename) { return 0;} virtual int get_objectitem( pwr_tStatus *sts, sev_item *item, pwr_tOid oid, char *attributename) { return 0;}
virtual int get_objectitems( pwr_tStatus *sts) { return 0;} virtual int get_objectitems( pwr_tStatus *sts) { return 0;}
virtual int check_objectitemattr( pwr_tStatus *sts, char *tablename, pwr_tOid oid, char *aname, char *oname, virtual int check_objectitemattr( pwr_tStatus *sts, char *tablename, pwr_tOid oid, char *aname, char *oname,
pwr_eType type, unsigned int size, unsigned int *idx) { return 0;} pwr_eType type, unsigned int size, unsigned int *idx) { return 0;}
......
...@@ -559,7 +559,7 @@ int sev_dbms_env::get_systemname() ...@@ -559,7 +559,7 @@ int sev_dbms_env::get_systemname()
return 1; return 1;
} }
int sev_dbms::create_table( pwr_tStatus *sts, pwr_tOid oid, char *aname, pwr_eType type, int sev_dbms::create_table( pwr_tStatus *sts, char *tablename, pwr_eType type,
unsigned int size, pwr_tMask options, float deadband) unsigned int size, pwr_tMask options, float deadband)
{ {
char query[200]; char query[200];
...@@ -605,7 +605,7 @@ int sev_dbms::create_table( pwr_tStatus *sts, pwr_tOid oid, char *aname, pwr_eTy ...@@ -605,7 +605,7 @@ int sev_dbms::create_table( pwr_tStatus *sts, pwr_tOid oid, char *aname, pwr_eTy
sprintf( query, "create table %s ( %s" sprintf( query, "create table %s ( %s"
"%s, value %s %s, index (time));", "%s, value %s %s, index (time));",
oid_to_table(oid, aname), readoptstr, timeformatstr, pwrtype_to_type( type, size), jumpstr); tablename, readoptstr, timeformatstr, pwrtype_to_type( type, size), jumpstr);
int rc = mysql_query( m_env->con(), query); int rc = mysql_query( m_env->con(), query);
if (rc) { if (rc) {
...@@ -617,12 +617,11 @@ int sev_dbms::create_table( pwr_tStatus *sts, pwr_tOid oid, char *aname, pwr_eTy ...@@ -617,12 +617,11 @@ int sev_dbms::create_table( pwr_tStatus *sts, pwr_tOid oid, char *aname, pwr_eTy
return 1; return 1;
} }
int sev_dbms::delete_table( pwr_tStatus *sts, pwr_tOid oid, char *aname) int sev_dbms::delete_table( pwr_tStatus *sts, char *tablename)
{ {
char query[200]; char query[200];
sprintf( query, "drop table %s;", sprintf( query, "drop table %s;", tablename);
oid_to_table(oid, aname));
int rc = mysql_query( m_env->con(), query); int rc = mysql_query( m_env->con(), query);
if (rc) { if (rc) {
...@@ -647,6 +646,21 @@ int sev_dbms::store_item( pwr_tStatus *sts, char *tablename, pwr_tOid oid, char ...@@ -647,6 +646,21 @@ int sev_dbms::store_item( pwr_tStatus *sts, char *tablename, pwr_tOid oid, char
time_AtoAscii( &creatime, time_eFormat_NumDateAndTime, timestr, sizeof(timestr)); time_AtoAscii( &creatime, time_eFormat_NumDateAndTime, timestr, sizeof(timestr));
timestr[19] = 0; timestr[19] = 0;
unsigned int next_id = get_nextAutoIncrement((char*)"items");
/*
char volName[32];
strncpy(volName, oname, sizeof(volName));
for ( char *s = volName; *s; s++) {
if ( *s == ':') {
*s = 0;
break;
}
}
sprintf(tablename, "%s_%d", volName, next_id);
*/
sprintf(tablename, "%s_%d", oid_to_table(oid, (char*)""), next_id);
sprintf( query, "insert into items (id,tablename,vid,oix,oname,aname,uptime,cretime,storagetime,vtype,vsize,description,unit,scantime,deadband,options) " sprintf( query, "insert into items (id,tablename,vid,oix,oname,aname,uptime,cretime,storagetime,vtype,vsize,description,unit,scantime,deadband,options) "
"values (0,'%s',%d,%d,'%s','%s','%s','%s',%ld,%d,%d,'%s','%s',%f,%f,%d);", "values (0,'%s',%d,%d,'%s','%s','%s','%s',%ld,%d,%d,'%s','%s',%f,%f,%d);",
tablename, oid.vid, oid.oix, oname, aname, timestr, timestr, (long int)storagetime.tv_sec, vtype, tablename, oid.vid, oid.oix, oname, aname, timestr, timestr, (long int)storagetime.tv_sec, vtype,
...@@ -913,17 +927,17 @@ int sev_dbms::store_value( pwr_tStatus *sts, int item_idx, int attr_idx, ...@@ -913,17 +927,17 @@ int sev_dbms::store_value( pwr_tStatus *sts, int item_idx, int attr_idx,
switch ( m_items[item_idx].attr[attr_idx].type) { switch ( m_items[item_idx].attr[attr_idx].type) {
case pwr_eType_String: case pwr_eType_String:
sprintf( query, "insert into %s (time, ntime, %s) values (%ld,%ld,'%s')", sprintf( query, "insert into %s (time, ntime, %s) values (%ld,%ld,'%s')",
oid_to_table(m_items[item_idx].oid, m_items[item_idx].attr[attr_idx].aname), colname, m_items[item_idx].tablename, colname,
(long int)time.tv_sec, (long int)time.tv_nsec, bufstr); (long int)time.tv_sec, (long int)time.tv_nsec, bufstr);
break; break;
default: default:
if ( m_items[item_idx].options & pwr_mSevOptionsMask_UseDeadBand) if ( m_items[item_idx].options & pwr_mSevOptionsMask_UseDeadBand)
sprintf( query, "insert into %s (time, ntime, %s, jump) values (%ld,%ld,%s,%d)", sprintf( query, "insert into %s (time, ntime, %s, jump) values (%ld,%ld,%s,%d)",
oid_to_table(m_items[item_idx].oid, m_items[item_idx].attr[attr_idx].aname), colname, m_items[item_idx].tablename, colname,
(long int)time.tv_sec, (long int)time.tv_nsec, bufstr, set_jump); (long int)time.tv_sec, (long int)time.tv_nsec, bufstr, set_jump);
else else
sprintf( query, "insert into %s (time, ntime, %s) values (%ld,%ld,%s)", sprintf( query, "insert into %s (time, ntime, %s) values (%ld,%ld,%s)",
oid_to_table(m_items[item_idx].oid, m_items[item_idx].attr[attr_idx].aname), colname, m_items[item_idx].tablename, colname,
(long int)time.tv_sec, (long int)time.tv_nsec, bufstr); (long int)time.tv_sec, (long int)time.tv_nsec, bufstr);
} }
} }
...@@ -932,15 +946,15 @@ int sev_dbms::store_value( pwr_tStatus *sts, int item_idx, int attr_idx, ...@@ -932,15 +946,15 @@ int sev_dbms::store_value( pwr_tStatus *sts, int item_idx, int attr_idx,
switch ( m_items[item_idx].attr[attr_idx].type) { switch ( m_items[item_idx].attr[attr_idx].type) {
case pwr_eType_String: case pwr_eType_String:
sprintf( query, "insert into %s (time, %s) values (%ld,'%s')", sprintf( query, "insert into %s (time, %s) values (%ld,'%s')",
oid_to_table(m_items[item_idx].oid, m_items[item_idx].attr[attr_idx].aname), colname, (long int)time.tv_sec, bufstr); m_items[item_idx].tablename, colname, (long int)time.tv_sec, bufstr);
break; break;
default: default:
if ( m_items[item_idx].options & pwr_mSevOptionsMask_UseDeadBand) if ( m_items[item_idx].options & pwr_mSevOptionsMask_UseDeadBand)
sprintf( query, "insert into %s (time, %s, jump) values (%ld,%s,%d)", sprintf( query, "insert into %s (time, %s, jump) values (%ld,%s,%d)",
oid_to_table(m_items[item_idx].oid, m_items[item_idx].attr[attr_idx].aname), colname, (long int)time.tv_sec, bufstr, set_jump); m_items[item_idx].tablename, colname, (long int)time.tv_sec, bufstr, set_jump);
else else
sprintf( query, "insert into %s (time, %s) values (%ld,%s)", sprintf( query, "insert into %s (time, %s) values (%ld,%s)",
oid_to_table(m_items[item_idx].oid, m_items[item_idx].attr[attr_idx].aname), colname, (long int)time.tv_sec, bufstr); m_items[item_idx].tablename, colname, (long int)time.tv_sec, bufstr);
} }
} }
} }
...@@ -950,17 +964,17 @@ int sev_dbms::store_value( pwr_tStatus *sts, int item_idx, int attr_idx, ...@@ -950,17 +964,17 @@ int sev_dbms::store_value( pwr_tStatus *sts, int item_idx, int attr_idx,
switch ( m_items[item_idx].attr[attr_idx].type) { switch ( m_items[item_idx].attr[attr_idx].type) {
case pwr_eType_String: case pwr_eType_String:
sprintf( query, "insert into %s (time, ntime, %s) values ('%s',%ld,'%s')", sprintf( query, "insert into %s (time, ntime, %s) values ('%s',%ld,'%s')",
oid_to_table(m_items[item_idx].oid, m_items[item_idx].attr[attr_idx].aname), colname, m_items[item_idx].tablename, colname,
timstr, (long int)time.tv_nsec, bufstr); timstr, (long int)time.tv_nsec, bufstr);
break; break;
default: default:
if ( m_items[item_idx].options & pwr_mSevOptionsMask_UseDeadBand) if ( m_items[item_idx].options & pwr_mSevOptionsMask_UseDeadBand)
sprintf( query, "insert into %s (time, ntime, %s, jump) values ('%s',%ld,%s,%d)", sprintf( query, "insert into %s (time, ntime, %s, jump) values ('%s',%ld,%s,%d)",
oid_to_table(m_items[item_idx].oid, m_items[item_idx].attr[attr_idx].aname), colname, m_items[item_idx].tablename, colname,
timstr, (long int)time.tv_nsec, bufstr, set_jump); timstr, (long int)time.tv_nsec, bufstr, set_jump);
else else
sprintf( query, "insert into %s (time, ntime, %s) values ('%s',%ld,%s)", sprintf( query, "insert into %s (time, ntime, %s) values ('%s',%ld,%s)",
oid_to_table(m_items[item_idx].oid, m_items[item_idx].attr[attr_idx].aname), colname, m_items[item_idx].tablename, colname,
timstr, (long int)time.tv_nsec, bufstr); timstr, (long int)time.tv_nsec, bufstr);
} }
} }
...@@ -969,15 +983,15 @@ int sev_dbms::store_value( pwr_tStatus *sts, int item_idx, int attr_idx, ...@@ -969,15 +983,15 @@ int sev_dbms::store_value( pwr_tStatus *sts, int item_idx, int attr_idx,
switch ( m_items[item_idx].attr[attr_idx].type) { switch ( m_items[item_idx].attr[attr_idx].type) {
case pwr_eType_String: case pwr_eType_String:
sprintf( query, "insert into %s (time, %s) values ('%s','%s')", sprintf( query, "insert into %s (time, %s) values ('%s','%s')",
oid_to_table(m_items[item_idx].oid, m_items[item_idx].attr[attr_idx].aname), colname, timstr, bufstr); m_items[item_idx].tablename, colname, timstr, bufstr);
break; break;
default: default:
if ( m_items[item_idx].options & pwr_mSevOptionsMask_UseDeadBand) if ( m_items[item_idx].options & pwr_mSevOptionsMask_UseDeadBand)
sprintf( query, "insert into %s (time, %s, jump) values ('%s',%s,%d)", sprintf( query, "insert into %s (time, %s, jump) values ('%s',%s,%d)",
oid_to_table(m_items[item_idx].oid, m_items[item_idx].attr[attr_idx].aname), colname, timstr, bufstr, set_jump); m_items[item_idx].tablename, colname, timstr, bufstr, set_jump);
else else
sprintf( query, "insert into %s (time, %s) values ('%s',%s)", sprintf( query, "insert into %s (time, %s) values ('%s',%s)",
oid_to_table(m_items[item_idx].oid, m_items[item_idx].attr[attr_idx].aname), colname, timstr, bufstr); m_items[item_idx].tablename, colname, timstr, bufstr);
} }
} }
} }
...@@ -1001,13 +1015,13 @@ int sev_dbms::store_value( pwr_tStatus *sts, int item_idx, int attr_idx, ...@@ -1001,13 +1015,13 @@ int sev_dbms::store_value( pwr_tStatus *sts, int item_idx, int attr_idx,
if ( m_items[item_idx].options & pwr_mSevOptionsMask_HighTimeResolution) { if ( m_items[item_idx].options & pwr_mSevOptionsMask_HighTimeResolution) {
// Posix time, high resolution // Posix time, high resolution
sprintf( query, "update %s set time = %ld, ntime = %ld where id = %d", sprintf( query, "update %s set time = %ld, ntime = %ld where id = %d",
oid_to_table(m_items[item_idx].oid, m_items[item_idx].attr[attr_idx].aname), m_items[item_idx].tablename,
(long int)time.tv_sec, (long int)time.tv_nsec, m_items[item_idx].last_id); (long int)time.tv_sec, (long int)time.tv_nsec, m_items[item_idx].last_id);
} }
else { else {
// Posix time, low resolution // Posix time, low resolution
sprintf( query, "update %s set time = %ld where id = %d", sprintf( query, "update %s set time = %ld where id = %d",
oid_to_table(m_items[item_idx].oid, m_items[item_idx].attr[attr_idx].aname), (long int)time.tv_sec, m_items[item_idx].tablename, (long int)time.tv_sec,
m_items[item_idx].last_id); m_items[item_idx].last_id);
} }
} }
...@@ -1015,13 +1029,13 @@ int sev_dbms::store_value( pwr_tStatus *sts, int item_idx, int attr_idx, ...@@ -1015,13 +1029,13 @@ int sev_dbms::store_value( pwr_tStatus *sts, int item_idx, int attr_idx,
if ( m_items[item_idx].options & pwr_mSevOptionsMask_HighTimeResolution) { if ( m_items[item_idx].options & pwr_mSevOptionsMask_HighTimeResolution) {
// Sql time, high resolution // Sql time, high resolution
sprintf( query, "update %s set time = '%s', ntime = %ld where id = %d", sprintf( query, "update %s set time = '%s', ntime = %ld where id = %d",
oid_to_table(m_items[item_idx].oid, m_items[item_idx].attr[attr_idx].aname), m_items[item_idx].tablename,
timstr, (long int)time.tv_nsec, m_items[item_idx].last_id); timstr, (long int)time.tv_nsec, m_items[item_idx].last_id);
} }
else { else {
// Sql time, low resolution // Sql time, low resolution
sprintf( query, "update %s set time = '%s' where id = %d", sprintf( query, "update %s set time = '%s' where id = %d",
oid_to_table(m_items[item_idx].oid, m_items[item_idx].attr[attr_idx].aname), timstr, m_items[item_idx].tablename, timstr,
m_items[item_idx].last_id); m_items[item_idx].last_id);
} }
} }
...@@ -1052,6 +1066,13 @@ int sev_dbms::get_values( pwr_tStatus *sts, pwr_tOid oid, pwr_tMask options, flo ...@@ -1052,6 +1066,13 @@ int sev_dbms::get_values( pwr_tStatus *sts, pwr_tOid oid, pwr_tMask options, flo
pwr_tTime *starttime, pwr_tTime *endtime, pwr_tTime *starttime, pwr_tTime *endtime,
int maxsize, pwr_tTime **tbuf, void **vbuf, unsigned int *bsize) int maxsize, pwr_tTime **tbuf, void **vbuf, unsigned int *bsize)
{ {
sev_item item;
get_item(sts, &item, oid, aname);
if(EVEN(*sts)) {
return 0;
}
char query[200]; char query[200];
char starttimstr[40]; char starttimstr[40];
char endtimstr[40]; char endtimstr[40];
...@@ -1075,7 +1096,7 @@ int sev_dbms::get_values( pwr_tStatus *sts, pwr_tOid oid, pwr_tMask options, flo ...@@ -1075,7 +1096,7 @@ int sev_dbms::get_values( pwr_tStatus *sts, pwr_tOid oid, pwr_tMask options, flo
etime = *endtime; etime = *endtime;
// Get number of rows // Get number of rows
sprintf( query, "show table status where name = '%s';", oid_to_table(oid, aname)); sprintf( query, "show table status where name = '%s';", item.tablename);
int rc = mysql_query( m_env->con(), query); int rc = mysql_query( m_env->con(), query);
if (rc) { if (rc) {
...@@ -1262,7 +1283,7 @@ int sev_dbms::get_values( pwr_tStatus *sts, pwr_tOid oid, pwr_tMask options, flo ...@@ -1262,7 +1283,7 @@ int sev_dbms::get_values( pwr_tStatus *sts, pwr_tOid oid, pwr_tMask options, flo
} }
sprintf( query, "select %s from %s %s order by %s", sprintf( query, "select %s from %s %s order by %s",
column_part, oid_to_table(oid, aname), where_part, orderby_part); column_part, item.tablename, where_part, orderby_part);
rc = mysql_query( m_env->con(), query); rc = mysql_query( m_env->con(), query);
if (rc) { if (rc) {
...@@ -1539,13 +1560,11 @@ int sev_dbms::add_item( pwr_tStatus *sts, pwr_tOid oid, char *oname, char *aname ...@@ -1539,13 +1560,11 @@ int sev_dbms::add_item( pwr_tStatus *sts, pwr_tOid oid, char *oname, char *aname
{ {
char tablename[256]; char tablename[256];
strcpy( tablename, oid_to_table( oid, aname));
store_item( sts, tablename, oid, oname, aname, storagetime, type, size, description, unit, store_item( sts, tablename, oid, oname, aname, storagetime, type, size, description, unit,
scantime, deadband, options); scantime, deadband, options);
if ( EVEN(*sts)) return 0; if ( EVEN(*sts)) return 0;
create_table( sts, oid, aname, type, size, options, deadband); create_table( sts, tablename, type, size, options, deadband);
if ( EVEN(*sts)) return 0; if ( EVEN(*sts)) return 0;
sev_item item; sev_item item;
...@@ -1577,30 +1596,32 @@ int sev_dbms::add_item( pwr_tStatus *sts, pwr_tOid oid, char *oname, char *aname ...@@ -1577,30 +1596,32 @@ int sev_dbms::add_item( pwr_tStatus *sts, pwr_tOid oid, char *oname, char *aname
int sev_dbms::delete_item( pwr_tStatus *sts, pwr_tOid oid, char *aname) int sev_dbms::delete_item( pwr_tStatus *sts, pwr_tOid oid, char *aname)
{ {
char tablename[256]; sev_item item;
get_item(sts, &item, oid, aname);
if(EVEN(*sts)) {
return 0;
}
strcpy( tablename, oid_to_table( oid, aname));
remove_item( sts, oid, aname); remove_item( sts, oid, aname);
if ( ODD(*sts)) if ( ODD(*sts))
delete_table( sts, oid, aname); delete_table( sts, item.tablename);
if ( ODD(*sts)) { if ( ODD(*sts)) {
for ( int i = 0; i < (int)m_items.size(); i++) { for ( int i = 0; i < (int)m_items.size(); i++) {
if ( m_items[i].deleted) if ( m_items[i].deleted)
continue; continue;
if ( cdh_ObjidIsEqual( m_items[i].oid, oid) && if ( cdh_ObjidIsEqual( m_items[i].oid, oid) &&
cdh_NoCaseStrcmp( m_items[i].attr[0].aname, aname) == 0) { cdh_NoCaseStrcmp( m_items[i].attr[0].aname, aname) == 0) {
m_items[i].deleted = 1; m_items[i].deleted = 1;
break; break;
} }
} }
} }
return 1; return 1;
} }
int sev_dbms::delete_old_data( pwr_tStatus *sts, pwr_tOid oid, char *aname, int sev_dbms::delete_old_data( pwr_tStatus *sts, char *tablename,
pwr_tMask options, pwr_tTime limit) pwr_tMask options, pwr_tTime limit)
{ {
char query[300]; char query[300];
...@@ -1613,21 +1634,21 @@ int sev_dbms::delete_old_data( pwr_tStatus *sts, pwr_tOid oid, char *aname, ...@@ -1613,21 +1634,21 @@ int sev_dbms::delete_old_data( pwr_tStatus *sts, pwr_tOid oid, char *aname,
if(options & pwr_mSevOptionsMask_ReadOptimized) { if(options & pwr_mSevOptionsMask_ReadOptimized) {
pwr_tUInt64 nbRowsToClean = 2000; pwr_tUInt64 nbRowsToClean = 2000;
nbRowsToClean += get_minFromIntegerColumn(oid_to_table(oid, aname), (char *)"id"); nbRowsToClean += get_minFromIntegerColumn(tablename, (char *)"id");
if ( options & pwr_mSevOptionsMask_PosixTime) if ( options & pwr_mSevOptionsMask_PosixTime)
sprintf( query, "delete from %s where id < %llu and time < %ld;", sprintf( query, "delete from %s where id < %llu and time < %ld;",
oid_to_table(oid, aname), nbRowsToClean, (long int)limit.tv_sec); tablename, nbRowsToClean, (long int)limit.tv_sec);
else else
sprintf( query, "delete from %s where id < %llu and time < '%s';", sprintf( query, "delete from %s where id < %llu and time < '%s';",
oid_to_table(oid, aname), nbRowsToClean, timstr); tablename, nbRowsToClean, timstr);
} }
else { else {
if ( options & pwr_mSevOptionsMask_PosixTime) if ( options & pwr_mSevOptionsMask_PosixTime)
sprintf( query, "delete from %s where time < %ld;", sprintf( query, "delete from %s where time < %ld;",
oid_to_table(oid, aname), (long int)limit.tv_sec); tablename, (long int)limit.tv_sec);
else else
sprintf( query, "delete from %s where time < '%s';", sprintf( query, "delete from %s where time < '%s';",
oid_to_table(oid, aname), timstr); tablename, timstr);
} }
int rc = mysql_query( m_env->con(), query); int rc = mysql_query( m_env->con(), query);
if (rc) { if (rc) {
...@@ -1782,6 +1803,8 @@ int sev_dbms::check_objectitem( pwr_tStatus *sts, char *tablename, pwr_tOid oid, ...@@ -1782,6 +1803,8 @@ int sev_dbms::check_objectitem( pwr_tStatus *sts, char *tablename, pwr_tOid oid,
//This won't work!! We have to alter the table to be able to change this //This won't work!! We have to alter the table to be able to change this
//m_items[i].options = options; //m_items[i].options = options;
strcpy(tablename, m_items[i].tablename);
*idx = i; *idx = i;
*sts = SEV__SUCCESS; *sts = SEV__SUCCESS;
return 1; return 1;
...@@ -1837,6 +1860,21 @@ int sev_dbms::store_objectitem( pwr_tStatus *sts, char *tablename, pwr_tOid oid, ...@@ -1837,6 +1860,21 @@ int sev_dbms::store_objectitem( pwr_tStatus *sts, char *tablename, pwr_tOid oid,
time_AtoAscii( &creatime, time_eFormat_NumDateAndTime, timestr, sizeof(timestr)); time_AtoAscii( &creatime, time_eFormat_NumDateAndTime, timestr, sizeof(timestr));
timestr[19] = 0; timestr[19] = 0;
unsigned int next_id = get_nextAutoIncrement((char*)"objectitems");
/*
char volName[32];
strncpy(volName, oname, sizeof(volName));
for ( char *s = volName; *s; s++) {
if ( *s == ':') {
*s = 0;
break;
}
}
sprintf(tablename, "obj_%s_%d", volName, next_id);
*/
sprintf(tablename, "obj_%s_%d", oid_to_table(oid, (char*)""), next_id);
sprintf( query, "insert into objectitems (id,tablename,vid,oix,oname,aname,uptime,cretime,storagetime,description,scantime,deadband,options) " sprintf( query, "insert into objectitems (id,tablename,vid,oix,oname,aname,uptime,cretime,storagetime,description,scantime,deadband,options) "
"values (0,'%s',%d,%d,'%s','%s','%s','%s',%ld,'%s',%f,%f,%d);", "values (0,'%s',%d,%d,'%s','%s','%s','%s',%ld,'%s',%f,%f,%d);",
tablename, oid.vid, oid.oix, oname, aname, timestr, timestr, (long int)storagetime.tv_sec, description, scantime, deadband, options); tablename, oid.vid, oid.oix, oname, aname, timestr, timestr, (long int)storagetime.tv_sec, description, scantime, deadband, options);
...@@ -2007,6 +2045,40 @@ pwr_tUInt64 sev_dbms::get_maxFromIntegerColumn( char *tablename, char *colname ) ...@@ -2007,6 +2045,40 @@ pwr_tUInt64 sev_dbms::get_maxFromIntegerColumn( char *tablename, char *colname )
return retVal; return retVal;
} }
pwr_tUInt64 sev_dbms::get_nextAutoIncrement( char *tablename )
{
char query[200];
pwr_tUInt64 retVal = 0;
sprintf( query, "SELECT Auto_increment FROM information_schema.tables WHERE table_name='%s'", tablename);
//printf( "%s: %s\n", __FUNCTION__ ,query);
int rc = mysql_query( m_env->con(), query);
if (rc) {
printf("In %s row %d:\n", __FILE__, __LINE__);
printf( "%s: %s\n", __FUNCTION__,mysql_error(m_env->con()));
return 0;
}
MYSQL_RES *result = mysql_store_result( m_env->con());
if ( !result) {
printf("In %s row %d:\n", __FILE__, __LINE__);
printf( "%s Result Error\n", __FUNCTION__);
return retVal;
}
int rows = mysql_num_rows( result);
if(rows <= 0) {
mysql_free_result( result);
return retVal;
}
MYSQL_ROW row;
row = mysql_fetch_row( result);
if(row[0] != NULL) {
retVal = strtoull(row[0], 0, 10);
}
mysql_free_result( result);
return retVal;
}
int sev_dbms::store_objectvalue( pwr_tStatus *sts, int item_idx, int attr_idx, int sev_dbms::store_objectvalue( pwr_tStatus *sts, int item_idx, int attr_idx,
pwr_tTime time, void *buf, void *oldbuf, unsigned int size) pwr_tTime time, void *buf, void *oldbuf, unsigned int size)
...@@ -2084,10 +2156,13 @@ int sev_dbms::store_objectvalue( pwr_tStatus *sts, int item_idx, int attr_idx, ...@@ -2084,10 +2156,13 @@ int sev_dbms::store_objectvalue( pwr_tStatus *sts, int item_idx, int attr_idx,
valuesStr.append(bufstr); valuesStr.append(bufstr);
valuesStr.append("',"); valuesStr.append("',");
} }
char colNameStr[80];
colsStr.append("`"); sprintf(colNameStr, "`%s`,", create_colName(i, m_items[item_idx].attr[i].aname));
colsStr.append(m_items[item_idx].attr[i].aname); colsStr.append(colNameStr);
colsStr.append("`,");
// colsStr.append("`");
// colsStr.append(m_items[item_idx].attr[i].aname);
// colsStr.append("`,");
buf = (char*)buf + m_items[item_idx].attr[i].size; buf = (char*)buf + m_items[item_idx].attr[i].size;
} }
...@@ -2197,12 +2272,12 @@ int sev_dbms::store_objectvalue( pwr_tStatus *sts, int item_idx, int attr_idx, ...@@ -2197,12 +2272,12 @@ int sev_dbms::store_objectvalue( pwr_tStatus *sts, int item_idx, int attr_idx,
return 1; return 1;
} }
int sev_dbms::get_item( pwr_tStatus *sts, sev_item *item, char *tablename) int sev_dbms::get_item( pwr_tStatus *sts, sev_item *item, pwr_tOid oid, char *attributename)
{ {
char query[300]; char query[300];
sprintf( query, "select id,tablename,vid,oix,oname,aname,uptime,cretime,storagetime,vtype,vsize,description,unit,scantime,deadband,options " sprintf( query, "select id,tablename,vid,oix,oname,aname,uptime,cretime,storagetime,vtype,vsize,description,unit,scantime,deadband,options "
"from items where tablename='%s'", tablename); "from items where vid=%d and oix=%d and aname='%s'", oid.vid, oid.oix, attributename);
int rc = mysql_query( m_env->con(), query); int rc = mysql_query( m_env->con(), query);
if (rc) { if (rc) {
...@@ -2271,12 +2346,12 @@ int sev_dbms::get_item( pwr_tStatus *sts, sev_item *item, char *tablename) ...@@ -2271,12 +2346,12 @@ int sev_dbms::get_item( pwr_tStatus *sts, sev_item *item, char *tablename)
return 1; return 1;
} }
int sev_dbms::get_objectitem( pwr_tStatus *sts, sev_item *item, char *tablename) int sev_dbms::get_objectitem( pwr_tStatus *sts, sev_item *item, pwr_tOid oid, char *attributename)
{ {
char query[300]; char query[300];
sprintf( query, "select id,tablename,vid,oix,oname,aname,uptime,cretime,storagetime,description,scantime,deadband,options " sprintf( query, "select id,tablename,vid,oix,oname,aname,uptime,cretime,storagetime,description,scantime,deadband,options "
"from objectitems where tablename='%s'", tablename); "from objectitems where vid=%d and oix=%d and aname='%s'", oid.vid, oid.oix, attributename);
int rc = mysql_query( m_env->con(), query); int rc = mysql_query( m_env->con(), query);
if (rc) { if (rc) {
...@@ -2674,10 +2749,13 @@ int sev_dbms::get_objectvalues( pwr_tStatus *sts, sev_item *item, ...@@ -2674,10 +2749,13 @@ int sev_dbms::get_objectvalues( pwr_tStatus *sts, sev_item *item,
else { else {
colsStr.append("sev__time, "); colsStr.append("sev__time, ");
} }
char colName[64];
for(size_t i = 0; i < item->attr.size(); i++) { for(size_t i = 0; i < item->attr.size(); i++) {
colsStr.append("`"); sprintf(colName, "`col_%d`,", i);
colsStr.append(item->attr[i].aname); colsStr.append(colName);
colsStr.append("`,"); // colsStr.append("`");
// colsStr.append(item->attr[i].aname);
// colsStr.append("`,");
} }
//remove last , //remove last ,
colsStr.resize(colsStr.length()-1); colsStr.resize(colsStr.length()-1);
...@@ -3014,7 +3092,7 @@ int sev_dbms::handle_itemchange(pwr_tStatus *sts, char *tablename, unsigned int ...@@ -3014,7 +3092,7 @@ int sev_dbms::handle_itemchange(pwr_tStatus *sts, char *tablename, unsigned int
sev_item *item = &m_items[item_idx]; sev_item *item = &m_items[item_idx];
create_table( sts, item->oid, item->attr[0].aname, item->attr[0].type, item->attr[0].size, item->options, item->deadband); create_table( sts, item->tablename, item->attr[0].type, item->attr[0].size, item->options, item->deadband);
if ( EVEN(*sts)) return 0; if ( EVEN(*sts)) return 0;
if(item->options & pwr_mSevOptionsMask_ReadOptimized ) { if(item->options & pwr_mSevOptionsMask_ReadOptimized ) {
...@@ -3044,14 +3122,16 @@ int sev_dbms::handle_objectchange(pwr_tStatus *sts, char *tablename, unsigned in ...@@ -3044,14 +3122,16 @@ int sev_dbms::handle_objectchange(pwr_tStatus *sts, char *tablename, unsigned in
char query[600]; char query[600];
int rc; int rc;
if(!newObject) { sev_item *item = &m_items[item_idx];
if (!newObject) {
char timestr[40]; char timestr[40];
pwr_tTime uptime; pwr_tTime uptime;
time_GetTime( &uptime); time_GetTime( &uptime);
time_AtoAscii( &uptime, time_eFormat_NumDateAndTime, timestr, sizeof(timestr)); time_AtoAscii( &uptime, time_eFormat_NumDateAndTime, timestr, sizeof(timestr));
timestr[19] = 0; timestr[19] = 0;
// Replace ':' '-' and ' ' in timestr with '_' // Replace ':' '-' and ' ' in timestr with '_'
for ( char *s = timestr; *s; s++) { for ( char *s = timestr; *s; s++) {
if ( *s == ':') if ( *s == ':')
...@@ -3061,12 +3141,12 @@ int sev_dbms::handle_objectchange(pwr_tStatus *sts, char *tablename, unsigned in ...@@ -3061,12 +3141,12 @@ int sev_dbms::handle_objectchange(pwr_tStatus *sts, char *tablename, unsigned in
if ( *s == '-') if ( *s == '-')
*s = '_'; *s = '_';
} }
snprintf(newTableName, sizeof(newTableName), "%s_%s", tablename, timestr); snprintf(newTableName, sizeof(newTableName), "%s_%s", tablename, timestr);
printf("Recreating table %s due to attribute definition changes, old table saved to %s \n", tablename, newTableName); printf("Recreating table %s due to attribute definition changes, old table saved to %s \n", tablename, newTableName);
errh_Warning("Recreating table %s due to attribute definition changes, old table saved to %s", tablename, newTableName); errh_Warning("Recreating table %s due to attribute definition changes, old table saved to %s", tablename, newTableName);
sprintf(query, "RENAME TABLE %s to %s", tablename, newTableName); sprintf(query, "RENAME TABLE %s to %s", tablename, newTableName);
rc = mysql_query( m_env->con(), query); rc = mysql_query( m_env->con(), query);
if (rc) { if (rc) {
...@@ -3075,18 +3155,15 @@ int sev_dbms::handle_objectchange(pwr_tStatus *sts, char *tablename, unsigned in ...@@ -3075,18 +3155,15 @@ int sev_dbms::handle_objectchange(pwr_tStatus *sts, char *tablename, unsigned in
*sts = SEV__DBERROR; *sts = SEV__DBERROR;
return 0; return 0;
} }
}
sev_item *item = &m_items[item_idx];
create_objecttable( sts, tablename, item->options, item->deadband); create_objecttable( sts, tablename, item->options, item->deadband);
if ( EVEN(*sts)) return 0; if ( EVEN(*sts)) return 0;
if(!newObject) { if (item->options & pwr_mSevOptionsMask_ReadOptimized ) {
if(item->options & pwr_mSevOptionsMask_ReadOptimized ) {
//If we set increment to same value as in the old table we can easily move the data from the old table to the new one //If we set increment to same value as in the old table we can easily move the data from the old table to the new one
pwr_tUInt64 autoIncrValue = get_maxFromIntegerColumn(newTableName, (char*)"sev__id"); pwr_tUInt64 autoIncrValue = get_maxFromIntegerColumn(newTableName, (char*)"sev__id");
if(autoIncrValue) if (autoIncrValue)
autoIncrValue++; autoIncrValue++;
sprintf(query, "ALTER TABLE %s AUTO_INCREMENT = %llu", tablename, autoIncrValue); sprintf(query, "ALTER TABLE %s AUTO_INCREMENT = %llu", tablename, autoIncrValue);
rc = mysql_query( m_env->con(), query); rc = mysql_query( m_env->con(), query);
...@@ -3097,7 +3174,7 @@ int sev_dbms::handle_objectchange(pwr_tStatus *sts, char *tablename, unsigned in ...@@ -3097,7 +3174,7 @@ int sev_dbms::handle_objectchange(pwr_tStatus *sts, char *tablename, unsigned in
return 0; return 0;
} }
} }
sprintf(query, "delete from objectitemattributes where tablename = '%s'", tablename); sprintf(query, "delete from objectitemattributes where tablename = '%s'", tablename);
rc = mysql_query( m_env->con(), query); rc = mysql_query( m_env->con(), query);
if (rc) { if (rc) {
...@@ -3108,8 +3185,11 @@ int sev_dbms::handle_objectchange(pwr_tStatus *sts, char *tablename, unsigned in ...@@ -3108,8 +3185,11 @@ int sev_dbms::handle_objectchange(pwr_tStatus *sts, char *tablename, unsigned in
} }
} }
for(size_t i = 0; i < item->attr.size(); i++) { for (size_t i = 0; i < item->attr.size(); i++) {
sprintf( query, "alter table %s add `%s` %s;", tablename, item->attr[i].aname, pwrtype_to_type( item->attr[i].type, item->attr[i].size)); char colName[64];
strncpy(colName, create_colName(i, item->attr[i].aname), sizeof(colName));
//sprintf(colName, "col_%d", i);
sprintf( query, "alter table %s add `%s` %s;", tablename, colName, pwrtype_to_type( item->attr[i].type, item->attr[i].size));
rc = mysql_query( m_env->con(), query); rc = mysql_query( m_env->con(), query);
if (rc) { if (rc) {
printf("In %s row %d:\n", __FILE__, __LINE__); printf("In %s row %d:\n", __FILE__, __LINE__);
...@@ -3119,7 +3199,7 @@ int sev_dbms::handle_objectchange(pwr_tStatus *sts, char *tablename, unsigned in ...@@ -3119,7 +3199,7 @@ int sev_dbms::handle_objectchange(pwr_tStatus *sts, char *tablename, unsigned in
} }
int aidx = i; int aidx = i;
sprintf( query, "insert into objectitemattributes (tablename, attributename, attributeidx, attributetype, attributesize) " sprintf( query, "insert into objectitemattributes (tablename, attributename, attributeidx, attributetype, attributesize) "
"values('%s', '%s', %d, %d, %d)", tablename, item->attr[i].aname, aidx, item->attr[i].type, item->attr[i].size); "values('%s', '%s', %d, %d, %d)", tablename, item->attr[i].aname, aidx, item->attr[i].type, item->attr[i].size);
rc = mysql_query( m_env->con(), query); rc = mysql_query( m_env->con(), query);
if (rc) { if (rc) {
printf("In %s row %d:\n", __FILE__, __LINE__); printf("In %s row %d:\n", __FILE__, __LINE__);
......
...@@ -103,6 +103,8 @@ class sev_dbms_env ...@@ -103,6 +103,8 @@ class sev_dbms_env
class sev_dbms : public sev_db { class sev_dbms : public sev_db {
public: public:
static const unsigned int constMaxColNameLength = 64;
sev_dbms_env *m_env; sev_dbms_env *m_env;
sev_dbms( sev_dbms_env *env) : m_env(env) {} sev_dbms( sev_dbms_env *env) : m_env(env) {}
...@@ -122,14 +124,14 @@ class sev_dbms : public sev_db { ...@@ -122,14 +124,14 @@ class sev_dbms : public sev_db {
pwr_eType type, unsigned int size, pwr_tFloat32 scantime, pwr_tTime *creatime, pwr_eType type, unsigned int size, pwr_tFloat32 scantime, pwr_tTime *creatime,
pwr_tTime *starttime, pwr_tTime *starttime,
pwr_tTime *endtime, int maxsize, pwr_tTime **tbuf, void **vbuf, unsigned int *bsize); pwr_tTime *endtime, int maxsize, pwr_tTime **tbuf, void **vbuf, unsigned int *bsize);
int delete_old_data( pwr_tStatus *sts, pwr_tOid oid, char *aname, int delete_old_data( pwr_tStatus *sts, char *tablename,
pwr_tMask options, pwr_tTime limit); pwr_tMask options, pwr_tTime limit);
int delete_item( pwr_tStatus *sts, pwr_tOid oid, char *aname); int delete_item( pwr_tStatus *sts, pwr_tOid oid, char *aname);
int get_items( pwr_tStatus *sts); int get_items( pwr_tStatus *sts);
int create_table( pwr_tStatus *sts, pwr_tOid oid, char *aname, pwr_eType type, unsigned int size, int create_table( pwr_tStatus *sts, char *tablename, pwr_eType type, unsigned int size,
pwr_tMask options, float deadband); pwr_tMask options, float deadband);
int delete_table( pwr_tStatus *sts, pwr_tOid oid, char *aname); int delete_table( pwr_tStatus *sts, char *tablename);
int store_item( pwr_tStatus *sts, char *tabelname, pwr_tOid oid, char *oname, char *aname, int store_item( pwr_tStatus *sts, char *tabelname, pwr_tOid oid, char *oname, char *aname,
pwr_tDeltaTime storagetime, pwr_eType vtype, unsigned int vsize, pwr_tDeltaTime storagetime, pwr_eType vtype, unsigned int vsize,
char *description, char *unit, pwr_tFloat32 scantime, char *description, char *unit, pwr_tFloat32 scantime,
...@@ -152,8 +154,8 @@ class sev_dbms : public sev_db { ...@@ -152,8 +154,8 @@ class sev_dbms : public sev_db {
int create_objecttable( pwr_tStatus *sts, char *tablename, pwr_tMask options, float deadband); int create_objecttable( pwr_tStatus *sts, char *tablename, pwr_tMask options, float deadband);
int store_objectvalue( pwr_tStatus *sts, int item_idx, int attr_idx, int store_objectvalue( pwr_tStatus *sts, int item_idx, int attr_idx,
pwr_tTime time, void *buf, void *oldbuf, unsigned int size); pwr_tTime time, void *buf, void *oldbuf, unsigned int size);
int get_item( pwr_tStatus *sts, sev_item *item, char *tablename); int get_item( pwr_tStatus *sts, sev_item *item, pwr_tOid oid, char *attributename);
int get_objectitem( pwr_tStatus *sts, sev_item *item, char *tablename); int get_objectitem( pwr_tStatus *sts, sev_item *item, pwr_tOid oid, char *attributename);
int get_objectitems( pwr_tStatus *sts); int get_objectitems( pwr_tStatus *sts);
int get_objectitemattributes( pwr_tStatus *sts, sev_item *item, char *tablename); int get_objectitemattributes( pwr_tStatus *sts, sev_item *item, char *tablename);
int check_objectitemattr( pwr_tStatus *sts, char *tablename, pwr_tOid oid, char *aname, char *oname, int check_objectitemattr( pwr_tStatus *sts, char *tablename, pwr_tOid oid, char *aname, char *oname,
...@@ -165,8 +167,19 @@ class sev_dbms : public sev_db { ...@@ -165,8 +167,19 @@ class sev_dbms : public sev_db {
int maxsize, pwr_tTime **tbuf, void **vbuf, unsigned int *bsize); int maxsize, pwr_tTime **tbuf, void **vbuf, unsigned int *bsize);
pwr_tUInt64 get_minFromIntegerColumn( char *tablename, char *colname ); pwr_tUInt64 get_minFromIntegerColumn( char *tablename, char *colname );
pwr_tUInt64 get_maxFromIntegerColumn( char *tablename, char *colname ); pwr_tUInt64 get_maxFromIntegerColumn( char *tablename, char *colname );
pwr_tUInt64 get_nextAutoIncrement( char *tablename );
int handle_itemchange(pwr_tStatus *sts, char *tablename, unsigned int item_idx); int handle_itemchange(pwr_tStatus *sts, char *tablename, unsigned int item_idx);
int handle_objectchange(pwr_tStatus *sts, char *tablename, unsigned int item_idx, bool newObject); int handle_objectchange(pwr_tStatus *sts, char *tablename, unsigned int item_idx, bool newObject);
inline char* create_colName(unsigned int index, char *attributename) {
static char colName[constMaxColNameLength];
strncpy(colName, attributename, constMaxColNameLength);
if(strlen(attributename) > constMaxColNameLength)
{
colName[constMaxColNameLength-5] = 0;
snprintf(&colName[strlen(colName)], 5, "_%d", index);
}
return colName;
}
}; };
#endif #endif
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment