There are some subtle changes to the code below.
I have now changed the dbh and sth objects to pmc's
You must now name the dbh and the sth. This allows us to use several of either as long as we have no name collisions.
Harry
.pcc_sub _MAIN prototyped
.param pmc argv
.include "/home/parrot/dbdi/lib/dbdi/dbdi_header.imc"
# I have added the facility to have multiple
# database handles but this adds some extra
# work for everyone.
.sym pmc dbh
.sym string dbstring
dbstring = "host=lhost dbname=name user=user password=pass"
.sym string dbh_name
dbh_name = "dbh"
.pcc_begin prototyped
.arg dbstring
.arg dbh_name
.pcc_call connect
retconnect:
.result dbh
.pcc_end
print "New $dbh successful????\n"
# Now that we have a $dbh we can pass it into
# the prepare funtion with the SQL statement.
# We must also name our statement handle which
# allows us to have multiple statement handles
# per dbh object. Name collisions are being
# checked. We also check to make sure that the
# dbh that is passed in is valid otherwise we
# abort.
.sym pmc sth
.sym string sql
sql = "select * from parrot"
.sym string sth_name
sth_name = "sth"
.pcc_begin prototyped
.arg dbh_name
.arg sth_name
.arg sql
.pcc_call prepare
retprepare:
.result sth
.pcc_end
print "SQL statement prepared????\n"
.sym int rows
.pcc_begin prototyped
.arg sth
.pcc_call execute
retexecute:
.result rows
.pcc_end
.PRINT("Execution Successful ", rows, " Affected\n" )
.sym PerlArray rowarray
.sym int rowcount
.sym PerlString field0
.sym PerlString field1
.sym PerlString field2
.sym PerlString field3
.sym PerlString field4
fetchnext:
.pcc_begin prototyped
.pcc_call fetch
retfetch:
.result rowarray
.result rowcount
.pcc_end
if rowcount == 0 goto finish
field0 = rowarray[0]
field1 = rowarray[1]
field2 = rowarray[2]
field3 = rowarray[3]
field4 = rowarray[4]
.PRINT("", field0, "")
.PRINT(" ", field1, "")
.PRINT(" ", field2, "")
.PRINT(" ", field3, "")
.PRINT(" ", field4, "")
.PRINT(" ROWCOUNT = ", rowcount , "\n" )
branch fetchnext
finish:
end
.end
.include "/home/parrot/dbdi/lib/dbdi/dbdi_functions.imc"
#######################################################
