Permalink
Browse files

interim commit, caveat emptor

  • Loading branch information...
1 parent eb208a8 commit 65006905108184cc5dee8c059aaee0510234ff35 Martin Berends committed Mar 7, 2010
Showing with 39 additions and 17 deletions.
  1. +14 −0 README
  2. +17 −3 examples/mysqlclient.p6
  3. +8 −14 lib/NativeCall.pm
View
14 README
@@ -8,11 +8,25 @@ 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.
+MySQL
+
Initially the mysql client library is being used as a fairly substantial
test case. The result might become a useful component in the Rakudo *
release.
The /usr/include/mysql.h file defines the mysql client library functions
and their parameters.
+Prepare your system along these lines before trying out the examples:
+
+ $ mysql -u root -p
+ CREATE USER 'testuser'@'localhost' IDENTIFIED BY 'testpass';
+ GRANT CREATE ON *.* TO 'testuser'@'localhost';
+
+You can look at the results via a normal mysql connection:
+
+ $ mysql -utestuser -ptestpass
+ USE zavolaj;
+ SHOW TABLES;
+ SELECT * FROM nom;
View
@@ -151,7 +151,9 @@ say $field_count;
# There are two ways to retrieve result sets: all at once in a single
# batch, or one row at a time. Choose according to the amount of data
# and the overhead on the server and the client.
-my $batch-mode = True;
+my $batch-mode;
+$batch-mode = (True,False).pick; # aha, you came looking for this line :-)
+$batch-mode = True;
if $batch-mode {
# Retrieve all the rows in a single batch operation
say "store_result";
@@ -163,15 +165,27 @@ if $batch-mode {
print mysql_error($client);
say $num_rows;
+ # Since mysql_fetch_fields() is not usable yet, derive the
+ # column widths from the maximum widths of the data in each
+ # column
+ my @width = 0 xx $field_count;
+ for
+
say "fetch_row and fetch_field";
loop ( my $row_number=0; $row_number<$num_rows; $row_number++ ) {
- print "row $row_number: ";
+# print "$row_number: ";
my $row_data = mysql_fetch_row( $result_set );
+
# It would be better to be able to call mysql_fetch_fields().
+ # my @row = mysql_fetch_fields($result_set);
+ # But that cannot be implmented yet in Rakudo because the
+ # returned result is a packed binary record of character
+ # pointers, unsigned longs and unsigned ints. See mysql.h
+
loop ( my $field_number=0; $field_number<$field_count; $field_number++ ) {
- print "field $field_number ";
print $row_data[$field_number];
# my $field = mysql_fetch_field( $result_set );
+# print "$field ";
}
say " ";
}
View
@@ -6,11 +6,9 @@ class NativeArray {
has $!max-index = -1;
method postcircumfix:<[ ]>($idx) {
- say "in postcircumfix:<[ ]>($idx)";
if $idx > $!max-index {
self!update-desc-to-index($idx);
}
- say "trying to index";
Q:PIR {
$P0 = find_lex 'self'
$P0 = getattribute $P0, '$!unmanaged'
@@ -21,9 +19,7 @@ class NativeArray {
}
method !update-desc-to-index($idx) {
- say "in update-desc-to-index($idx)";
- my $fpa = pir::new__Ps('FixedIntegerArray');
- pir::set__vPi($fpa, 3);
+ my $fpa = pir::new__Ps('ResizableIntegerArray');
my $typeid;
given $!of {
when Str { $typeid = -70 }
@@ -36,16 +32,14 @@ class NativeArray {
$P1 = find_lex '$typeid'
$P2 = find_lex '$idx'
$I0 = $P2
- inc $I0
- $I0 = $I0 * 3
- $I1 = 0
+ inc $I0
+ $I1 = 0
+ $I2 = $P1
loop:
- if $I1 > $I0 goto loop_end
- $P0[$I1] = $P1
- inc $I1
- $P0[$I1] = 1
- inc $I1
- $P0[$I1] = 0
+ if $I1 > $I0 goto loop_end
+ push $P0, $I2
+ push $P0, 1
+ push $P0, 0
inc $I1
goto loop
loop_end:

0 comments on commit 6500690

Please sign in to comment.