Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

improve the MySQL client example with column names

  • Loading branch information...
commit c18fbb26ccc93123cbb0a37f916780ca62430be6 1 parent baef4ef
Martin Berends authored
Showing with 40 additions and 3 deletions.
  1. +17 −2 README
  2. +23 −1 examples/mysqlclient.p6
View
19 README
@@ -8,12 +8,22 @@ Interface gives a similar facility in PIR.
The project name is the Slovak translation of the imperative "call!", to
complement Blizkost, a Rakudo-to-Perl-5 integration project.
+The functions that Zavolaj can currently call must have signatures (the
+type of the return value and the types of the arguments) that already
+exist in a fixed list inside Parrot. Adding more signatures currently
+involves adding entries to the parrot/src/nci/extra_thunks.nci file.
+
+There is a project to enable calling all possible function signatures:
+http://github.com/plobsing/parrot-libjit-fb is currently a Parrot
+extension. Zavolaj does not use it yet.
+
MySQL
Initially the MySQL client library is being used as a test case, because
it is a popular application, is frequently asked about, and because
-there is specific support for MySQL in parrot/src/nci/extra_thunks.nci.
-Some of the code might become a part of the Rakudo * distribution.
+Parrot does have all the function signatures. There is a Rakudo project
+http://github.com/mberends/fakedbi that wraps these functions with a DBI
+compatible interface.
The /usr/include/mysql.h file defines the mysql client library functions
and their parameters.
@@ -45,6 +55,11 @@ SQLite3
This library cannot be called yet because of missing Parrot NCI
signatures, see the example file for details.
+Microsoft Windows
+
+The win32-api-call.p6 script shows the beginning of a GUI application
+written in Perl 6.
+
Testing
Before running 'make test', you *must* perform this:
View
24 examples/mysqlclient.p6
@@ -1,5 +1,13 @@
# mysqlclient.p6
+# Requirements:
+# 1. MySQL client lib (eg on Debian, sudo apt-get install mysqlclient-dev
+# 2. An account and a database on a MySQL server, for this example:
+# username = testuser
+# password = testpass
+# database = zavolaj
+# 3. Permissions, eg "grant all privileges on zavolaj.* to testuser@localhost"
+
# Fortunately made possible by explicitly by hardcoded support in
# parrot/src/nci/extra_thunks.nci.
# See /usr/include/mysql.h for what should be callable, or browse
@@ -42,7 +50,7 @@ sub mysql_error( OpaquePointer $mysql_client)
{ ... }
sub mysql_fetch_field( OpaquePointer $result_set )
- returns OpaquePointer
+ returns Positional of Str
is native('libmysqlclient')
{ ... }
@@ -217,6 +225,13 @@ if $batch-mode {
my $result_set = mysql_store_result($client);
print mysql_error($client);
+ say "Columns:";
+ loop ( my $column_number=0; $column_number<$field_count; $column_number++ ) {
+ my $field_info = mysql_fetch_field($result_set);
+ my $column_name = $field_info[0];
+ say " $column_name";
+ }
+
print "row_count ";
$row_count = mysql_num_rows($result_set);
print mysql_error($client);
@@ -277,6 +292,13 @@ else {
my $result_set = mysql_use_result($client);
print mysql_error($client);
+ say "Columns:";
+ loop ( my $column_number=0; $column_number<$field_count; $column_number++ ) {
+ my $field_info = mysql_fetch_field($result_set);
+ my $column_name = $field_info[0];
+ say " $column_name";
+ }
+
while my $row_data = mysql_fetch_row($result_set) {
my @row;
loop ( my $field_number=0; $field_number<$field_count; $field_number++ ) {
Please sign in to comment.
Something went wrong with that request. Please try again.