This commit is contained in:
Isaac Connor 2018-05-12 14:33:56 -07:00
parent b445ddc981
commit 1ef5226316
1 changed files with 14 additions and 14 deletions

View File

@ -24,7 +24,6 @@
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
Group::Group() {
Warning("Instantiating default Group Object. Should not happen.");
@ -33,30 +32,31 @@ Group::Group() {
strcpy(name, "Default");
}
Group::Group( MYSQL_ROW &dbrow ) {
// The order of columns is: Id, ParentId, Name
Group::Group(MYSQL_ROW &dbrow) {
unsigned int index = 0;
id = atoi( dbrow[index++] );
parent_id = dbrow[index] ? atoi( dbrow[index] ): 0; index++;
strncpy( name, dbrow[index++], sizeof(name)-1 );
id = atoi(dbrow[index++]);
parent_id = dbrow[index] ? atoi(dbrow[index]): 0; index++;
strncpy(name, dbrow[index++], sizeof(name)-1);
}
/* If a zero or invalid p_id is passed, then the old default path will be assumed. */
Group::Group( unsigned int p_id ) {
Group::Group(unsigned int p_id) {
id = 0;
if ( p_id ) {
char sql[ZM_SQL_SML_BUFSIZ];
snprintf( sql, sizeof(sql), "SELECT Id, ParentId, Name FROM Group WHERE Id=%d", p_id );
Debug(2,"Loading Group for %d using %s", p_id, sql );
snprintf(sql, sizeof(sql), "SELECT Id, ParentId, Name FROM Group WHERE Id=%d", p_id);
Debug(2,"Loading Group for %d using %s", p_id, sql);
zmDbRow dbrow;
if ( ! dbrow.fetch( sql ) ) {
Error( "Unable to load group for id %d: %s", p_id, mysql_error( &dbconn ) );
if ( !dbrow.fetch(sql) ) {
Error("Unable to load group for id %d: %s", p_id, mysql_error(&dbconn));
} else {
unsigned int index = 0;
id = atoi( dbrow[index++] );
parent_id = dbrow[index] ? atoi( dbrow[index] ): 0; index++;
strncpy( name, dbrow[index++], sizeof(name)-1 );
Debug( 1, "Loaded Group area %d '%s'", id, this->Name() );
id = atoi(dbrow[index++]);
parent_id = dbrow[index] ? atoi(dbrow[index]): 0; index++;
strncpy(name, dbrow[index++], sizeof(name)-1);
Debug(1, "Loaded Group area %d '%s'", id, this->Name());
}
}
if ( ! id ) {