1
#include "odbxbackend.hh"
5
void OdbxBackend::execStmt( const char* stmt, unsigned long length, bool select )
10
DLOG( L.log( m_myname + " execStmt()", Logger::Debug ) );
12
if( m_qlog ) { L.log( m_myname + " Query: " + stmt, Logger::Info ); }
14
if( ( err = odbx_query( m_handle, stmt, length ) ) < 0 )
16
L.log( m_myname + " execStmt: Unable to execute query - " + string( odbx_error( m_handle, err ) ), Logger::Error );
17
throw( AhuException( "Error: odbx_query() failed" ) );
20
if( !select ) { while( getRecord() ); }
25
bool OdbxBackend::getRecord()
30
DLOG( L.log( m_myname + " getRecord()", Logger::Debug ) );
34
if( m_result != NULL )
38
if( ( err = odbx_row_fetch( m_result ) ) < 0 )
40
L.log( m_myname + " getRecord: Unable to get next row - " + string( odbx_error( m_handle, err ) ), Logger::Error );
41
throw( AhuException( "Error: odbx_row_fetch() failed" ) );
50
for( i = 0; i < odbx_column_count( m_result ); i++ )
52
fields += string( odbx_column_name( m_result, i ) );
54
if( odbx_field_value( m_result, i ) != NULL )
56
fields += "=" + string( odbx_field_value( m_result, i ) ) + ", ";
64
L.log( m_myname + " Values: " + fields, Logger::Error );
71
odbx_result_free( m_result );
75
while( ( err = odbx_result( m_handle, &m_result, NULL, 0 ) ) > 0 );
79
L.log( m_myname + " getRecord: Unable to get next result - " + string( odbx_error( m_handle, err ) ), Logger::Error );
80
throw( AhuException( "Error: odbx_result() failed" ) );
89
string OdbxBackend::escape( const string& str )
92
unsigned long len = sizeof( m_escbuf );
95
DLOG( L.log( m_myname + " escape()", Logger::Debug ) );
97
if( ( err = odbx_escape( m_handle, str.c_str(), str.size(), m_escbuf, &len ) ) < 0 )
99
L.log( m_myname + " escape: Unable to escape string - " + string( odbx_error( m_handle, err ) ), Logger::Error );
100
throw( AhuException( "Error: odbx_escape() failed" ) );
103
return string( m_escbuf, len );
108
void OdbxBackend::getDomainList( const string& stmt, vector<DomainInfo>* list, bool (*check_fcn)(u_int32_t,u_int32_t,SOAData*,DomainInfo*) )
111
u_int32_t nlast, nserial;
116
DLOG( L.log( m_myname + " getDomainList()", Logger::Debug ) );
118
execStmt( stmt.c_str(), stmt.size(), true );
120
if( !getRecord() ) { return; }
129
if( ( tmp = odbx_field_value( m_result, 6 ) ) != NULL )
131
DNSPacket::fillSOAData( string( tmp ), sd );
134
if( !sd.serial && ( tmp = odbx_field_value( m_result, 5 ) ) != NULL )
136
sd.serial = strtol( tmp, NULL, 10 );
139
if( ( tmp = odbx_field_value( m_result, 4 ) ) != NULL )
141
nlast = strtol( tmp, NULL, 10 );
144
if( ( tmp = odbx_field_value( m_result, 3 ) ) != NULL )
146
nserial = strtol( tmp, NULL, 10 );
149
if( (*check_fcn)( nlast, nserial, &sd, &di ) )
151
if( ( tmp = odbx_field_value( m_result, 2 ) ) != NULL )
153
di.master = string( tmp, odbx_field_length( m_result, 2 ) );
156
if( ( tmp = odbx_field_value( m_result, 1 ) ) != NULL )
158
di.zone = string( tmp, odbx_field_length( m_result, 1 ) );
161
if( ( tmp = odbx_field_value( m_result, 0 ) ) != NULL )
163
di.id = strtol( tmp, NULL, 10 );
166
di.last_check = nlast;
167
di.notified_serial = nserial;
168
di.serial = sd.serial;
171
list->push_back( di );
174
while( getRecord() );
179
bool checkSlave( u_int32_t nlast, u_int32_t nserial, SOAData* sd, DomainInfo* di )
181
if( nlast + sd->refresh < (u_int32_t) time( 0 ) )
183
di->kind = DomainInfo::Slave;
192
bool checkMaster( u_int32_t nlast, u_int32_t nserial, SOAData* sd, DomainInfo* di )
194
if( nserial != sd->serial )
196
di->kind = DomainInfo::Master;