summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ba45b0a)
raw | patch | inline | side by side (parent: ba45b0a)
author | rettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Thu, 24 Jan 2008 09:46:27 +0000 (09:46 +0000) | ||
committer | rettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Thu, 24 Jan 2008 09:46:27 +0000 (09:46 +0000) |
add option limit to query_jobdb at GosaPackages
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8582 594d385d-05f5-0310-b6e9-bd551577e9d8
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8582 594d385d-05f5-0310-b6e9-bd551577e9d8
index 031702871c87002e54d15614811c90fec72aff8f..2e838333f0edb6cae2ea347605b2ec6eeb88ded4 100644 (file)
}
}
-
-# error-flags
-# 1 no table ($table) defined
-# 2 no restriction parameter ($restric_pram) defined
-# 3 no restriction value ($restric_val) defined
-# 4 column name not known in table
-# 5 no column names to change specified
-#sub update_dbentry {
-# my $self = shift;
-# my $arg = shift;
-#
-#
-# # check completeness of function parameter
-# # extract table statement from arg hash
-# my $table = $arg->{table};
-# if (not defined $table) {
-# return 1;
-# } else {
-# delete $arg->{table};
-# }
-#
-# # extract where parameter from arg hash
-# my $where_statement = "";
-# if( exists $arg->{where} ) {
-# my $where_hash = @{ $arg->{where} }[0];
-# if( 0 < keys %{ $where_hash } ) {
-# my @where_list;
-# while( my ($rest_pram, $rest_val) = each %{ $where_hash } ) {
-# my $statement;
-# if( $rest_pram eq 'timestamp' ) {
-# $statement = "$rest_pram<'@{ $rest_val }[0]'";
-# } else {
-# $statement = "$rest_pram='@{ $rest_val }[0]'";
-# }
-# push( @where_list, $statement );
-# }
-# $where_statement .= "WHERE ".join('AND ', @where_list);
-# }
-# }
-#
-# # extract update parameter from arg hash
-# my $update_hash = @{ $arg->{update} }[0];
-# my $update_statement = "";
-# if( 0 < keys %{ $update_hash } ) {
-# my @update_list;
-# while( my ($rest_pram, $rest_val) = each %{ $update_hash } ) {
-# my $statement = "$rest_pram='@{ $rest_val }[0]'";
-# push( @update_list, $statement );
-# }
-# $update_statement .= join(', ', @update_list);
-# }
-#
-# my $sql_statement = "UPDATE $table SET $update_statement $where_statement";
-# &create_lock($self,'update_dbentry');
-# my $db_answer = $self->{dbh}->do($sql_statement);
-# &remove_lock($self,'update_dbentry');
-# return $db_answer;
-#}
sub update_dbentry {
my ($self, $sql)= @_;
my $db_answer= &exec_statement($self, $sql);
sub select_dbentry {
my ($self, $sql)= @_;
-
+ my $error= 0;
+ my $answer= {};
+
my $db_answer= &exec_statement($self, $sql);
# fetch column list of db and create a hash with column_name->column_value of the select query
my $table = $1;
my $column_list = &get_table_columns($self, $table);
my $list_len = @{ $column_list } ;
- my $answer = {};
my $hit_counter = 0;
foreach my $hit ( @{ $db_answer }) {
$hit_counter++;
index 88b5b65e07710b9f7e789e0cfcddf880dd37f1b3..04a1f29c575d0a5ea1c1b22047aa147afb104617 100644 (file)
elsif ($header eq 'delete_jobdb_entry') { $out_msg = &delete_jobdb_entry }
elsif ($header eq 'clear_jobdb') { $out_msg = &clear_jobdb }
elsif ($header eq 'update_status_jobdb_entry' ) { $out_msg = &update_status_jobdb_entry }
- elsif ($header eq 'update_timestamp_jobdb_entry' ) { $out_msg = &update_timestamp_jobdb_entry }
+ elsif ($header eq 'count_jobdb' ) { $out_msg = &count_jobdb }
else {
# msg could not be assigned to core function
# fetch all available eventhandler under $server_event_dir
return $update_str;
}
+sub get_limit_statement {
+ my ($msg, $msg_hash)= @_;
+ my $error= 0;
+ my $limit_str = "";
+ my ($from, $to);
+
+ if( not exists $msg_hash->{'limit'} ) { $error++; };
+
+ if( $error == 0 ) {
+ eval {
+ my $limit= @{$msg_hash->{'limit'}}[0];
+ $from= @{$limit->{'from'}}[0];
+ $to= @{$limit->{'to'}}[0];
+ };
+ if( $@ ) {
+ $error++;
+ }
+ }
+
+ if( $error == 0 ) {
+ $limit_str= "LIMIT $from, $to";
+ }
+
+ return $limit_str;
+}
+
sub query_jobdb {
my ($msg) = @_;
my $msg_hash = &transform_msg2hash($msg);
my $select= &get_select_statement($msg, $msg_hash);
my $table= $main::job_queue_table_name;
my $where= &get_where_statement($msg, $msg_hash);
- my $sql_statement= "SELECT $select FROM $table $where";
+ my $limit= &get_limit_statement($msg, $msg_hash);
+ my $sql_statement= "SELECT $select FROM $table $where $limit";
# execute db query
my $res_hash = $main::job_db->select_dbentry($sql_statement);
my $out_xml = &db_res_2_xml($res_hash);
+
+ return $out_xml;
+}
+
+
+sub count_jobdb {
+ my ($msg)= @_;
+ my $out_xml= "<xml><count>error</count></xml>";
+
+ # prepare query sql statement
+ my $table= $main::job_queue_table_name;
+ my $sql_statement= "SELECT * FROM $table ";
+ # execute db query
+ my $res_hash = $main::job_db->select_dbentry($sql_statement);
+
+ my $count = keys(%{$res_hash});
+ $out_xml= "<xml><count>$count</count></xml>";
+
return $out_xml;
}
+
sub delete_jobdb_entry {
my ($msg) = @_ ;
my $msg_hash = &transform_msg2hash($msg);
index 80ce0ada7ea9b34d085b9bdf44aece6257816bdd..ceb9268257eeaee5302622ae0bacf1380a79a385 100644 (file)
#===============================================================================
sub register_at_bus {
+
+
+ print STDERR ">>>>>>>>>>>>>>>>>>>>>>>>1\n";
+
# add bus to known_server_db
my $res = $main::known_server_db->add_dbentry( {table=>'known_server',
primkey=>'hostname',
hostkey=>$bus_passwd,
timestamp=>&get_time,
} );
+ print STDERR ">>>>>>>>>>>>>>>>>>>>>>>>2\n";
my $msg_hash = &create_xml_hash("here_i_am", $server_address, $bus_address);
my $answer = "";
$answer = &send_msg_hash2address($msg_hash, $bus_address, $bus_passwd);
else {
if ($target eq "*") {
# msg is for all clients
- my $query_res = $main::known_clients_db->select_dbentry( {table=>'known_clients'} );
+ my $sql_statement = "SELECT * FROM known_clients";
+ my $query_res = $main::known_clients_db->select_dbentry( $sql_statement );
while( my ($hit_num, $hit) = each %{ $query_res } ) {
$host_name = $hit->{hostname};
$host_key = $hit->{hostkey};
my $host_key;
- if( not defined $host_key ) {
- my $query_res = $main::known_clients_db->select_dbentry( {table=>'known_clients', hostname=>$target} );
+ if( not defined $host_key ) {
+ my $sql_statement = "SELECT * FROM known_clients WHERE hostname='$target'";
+ my $query_res = $main::known_clients_db->select_dbentry( $sql_statement );
if( 1 == keys %{$query_res} ) {
$host_key = $query_res->{1}->{host_key};
}
}
if( not defined $host_key ) {
- my $query_res = $main::known_server_db->select_dbentry( {table=>'known_server', hostname=>$target} );
+ my $sql_statement = "SELECT * FROM known_server WHERE hostname='$target'";
+ my $query_res = $main::known_server_db->select_dbentry( $sql_statement );
if( 1 == keys %{$query_res} ) {
$host_key = $query_res->{1}->{host_key};
}
my $query_res;
# check known_clients_db
- $query_res = $main::known_clients_db->select_dbentry( {table=>'known_clients', hostname=>$source_name} );
+ my $sql_statement = "SELECT * FROM known_clients WHERE hostname='$source_name'";
+ $query_res = $main::known_clients_db->select_dbentry( $sql_statement );
if( 1 == keys %{$query_res} ) {
my $update_hash = { table=>'known_clients' };
$update_hash->{where} = [ { hostname=>[$source_name] } ];
index f095d31a1d79ef1d1a1163bd05fc1362b40ea3d3..bcfef94a13f0fbb540568edcab599bbddd3c56cc 100755 (executable)
--- a/gosa-si/tests/client.php
+++ b/gosa-si/tests/client.php
/* Prepare a hunge bunch of data to be send */
# add
-#$data = "<xml><header>gosa_ping</header><source>10.89.1.155:20082</source><target>10.89.1.155:20080</target></xml>";
#$data = "<xml> <header>job_ping</header> <source>10.89.1.155:20083</source><mac>00:1B:77:04:8A:6C</mac> <timestamp>19700101000000</timestamp> </xml>";
#$data = "<xml> <header>job_sayHello</header> <source>10.89.1.155:20083</source><mac>00:1B:77:04:8A:6C</mac> <timestamp>20130102133900</timestamp> </xml>";
-$data = "<xml> <header>job_ping</header> <source>10.89.1.155:20083</source><mac>00:1B:77:04:8A:6C</mac> <timestamp>20130102133900</timestamp> </xml>";
+#$data = "<xml> <header>job_ping</header> <source>10.89.1.155:20083</source><mac>00:1B:77:04:8A:6C</mac> <timestamp>20130102133900</timestamp> </xml>";
# delete
-#$data = "<xml> <header>gosa_delete_jobdb_entry</header><where><clause><phrase><status>error</status></phrase></clause></where></xml>";
+#$data = "<xml> <header>gosa_delete_jobdb_entry</header><where><clause><phrase><id>3</id></phrase></clause></where></xml>";
# update
#$data = "<xml> <header>gosa_update_status_jobdb_entry</header> <where><clause><phrase> <status>waiting</status></phrase></clause> </where> <update><status>processing</status> <result>update</result></update></xml>";
# query
-#$data = "<xml><header>gosa_query_jobdb</header><where><clause><connector>and</connector><phrase><operator>gt</operator><id>2</id></phrase><phrase><operator>le</operator><id>4</id></phrase></clause></where></xml>";
-#$data= "<xml><header>gosa_query_jobdb</header><where><clause><phrase><status>waiting</status></phrase></clause></where></xml>";
+#$data = "<xml><header>gosa_query_jobdb</header><where><clause><connector>and</connector><phrase><operator>gt</operator><ROWID>0</ROWID></phrase><phrase><operator>le</operator><ROWID>5</ROWID></phrase></clause></where></xml>";
+$data= "<xml><header>gosa_query_jobdb</header><where><clause><phrase><headertag>ping</headertag></phrase></clause></where><limit><from>0</from><to>3</to></limit></xml>";
+
+# count
+#$data = "<xml> <header>gosa_count_jobdb</header></xml>";
+
# clear