db");
// Create the user-defined function
sqlite_create_function($sqldb, "salarytogold", "convert_salary_to_gold", 1);
// Query the database using the UDF
$query = "select salarytogold(salary) FROM employees WHERE empid=1";
$result = sqlite_query($sqldb, $query);
list($salaryToGold) = sqlite_fetch_array($result);
// Display the results
echo "The employee can purchase: ".$salaryToGold." ounces.";
// End the database connection
sqlite_close($sqldb);
?>
Assuming employee Jason makes $10,000 per year, you can expect the following
output:
The employee can purchase 25 ounces.
Encoding Binary Data
The sqlite_udf_encode_binary() function encodes any binary data intended for
storage within an SQLite table. Its prototype follows:
string sqlite_udf_encode_binary(string data)
Use this function instead of sqlite_escape_string() when you??™re working with
data sent to a UDF.
Decoding Binary Data
The sqlite_udf_decode_binary() function decodes any binary data previously
encoded with the sqlite_udf_encode_binary() function. Its prototype follows:
string sqlite_udf_decode_binary(string data)
Use this function when you??™re returning possibly binary-unsafe data from a UDF.
CHAPTER 22 ?– SQLITE 589
Creating Aggregate Functions
When you work with database-driven applications, it??™s often useful to derive some
value based on some collective calculation of all values found within a particular
column or set of columns.
Pages:
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673