Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > cd14cddf3b3ceaf1193157472227757a > files > 697

parrot-doc-1.6.0-1mdv2010.0.i586.rpm

# Copyright (C) 2008-2009, Parrot Foundation.
# $Id: mysqltest.pir 41252 2009-09-13 16:58:01Z NotFound $

=head1 TITLE

mysqltest.pir - Test NCI with mysqlclient

=head1 SYNOPSIS

A test for Mysql.pir module.

Compile Mysql.pbc before usage.

This is an initial version, be careful and not expect too much.

Connection data and query are hard coded, edit the file to change.

=cut

########################################################################

.sub main :main

    load_bytecode 'Mysql.pbc'
    .local pmc m
    m = new ['Mysql']

    .local pmc get_client_info

    print 'mysql client version: '
    get_client_info = get_global ['Mysql'], 'get_client_info'
    $S0 = get_client_info()
    say $S0
# Just a test of the error method
    $S0 = m.'error'()
    $I0 = bytelength $S0
    unless $I0 goto good
    say $S0
    exit 1
good:
    say 'connect...'

    m.'connect'('localhost', 'parrot', 'baDworD', 'parrot')

    say 'query...'
    m.'query'('select * from hello;')

    .local pmc r
    r = m.'use_result'()
    .local pmc row
    .local int n
    n = r.'field_count'()
nextrow:
    row = r.'fetch_row'()
    $I0 = defined row
    unless $I0 goto finish
    #n = row
    $I0 = 0
    print "'"
nextcol:
    eq $I0, n, endrow
    $S0 = row [$I0]
    print $S0
    inc $I0
    eq $I0, n, endrow
    print "', '"
    goto nextcol
endrow:
    say "'"
    goto nextrow
finish:

    r.'free'()

# Testing prepared statement

# Skipping, still not working
    .return()

    .local pmc stmt
    stmt = m.'prepare'('select * from hello where foo = ?')
    $I0 = stmt.'param_count'()
    print 'Param count: '
    say $I0

    say 'Closing...'
    $I0 = stmt.'close'()
    print 'Close result: '
    say $I0
.end

#-----------------------------------------------------------------------
# Local Variables:
#   mode: pir
#   fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir: