in reply to Code factory
Of course this has a number of shortcomings, such as:sub make_select_query { my ($table, $select_fields, $conditions) = @_; my $query = "SELECT "; if ( defined $select_fields ) { if ( ref($select_array) eq "ARRAY" ) { $query .= join ",", @$select_array; } else { $query .= $select_fields; } } else { $query .= "\*"; } $query .= " FROM " . $table; # only put the where and conditions in the query string # if conditions are present if (keys %$conditions) { $query .= " WHERE "; foreach my $key (keys %$conditions) { push @conds, $key . "=\'" . $conditions->{$key} . "\'"; } } $query .= join " and ", @conds; return $query; }
... $condtions = { "age" => " >= 21 ", "sex" => " = female ", };
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Code factory
by Coruscate (Sexton) on Jul 08, 2003 at 00:36 UTC | |
by duct_tape (Hermit) on Jul 08, 2003 at 14:36 UTC | |
by tadman (Prior) on Jul 08, 2003 at 19:01 UTC | |
by Notromda (Pilgrim) on Jul 09, 2003 at 01:55 UTC | |
by duct_tape (Hermit) on Aug 26, 2003 at 20:03 UTC |