#!/usr/bin/python3

###########################################################################
##  Example program of Python for Jaguar
##
##  Copyright  DataJaguar Inc
##
###########################################################################
import sys
import jaguarpy 

jag = jaguarpy.Jaguar()

rc = jag.connect( "127.0.0.1", int(sys.argv[1]), "demouser", "test" )
print ("Connected to Jaguar server rc=%d " % ( rc ) )

rc = jag.startQuery( "select * from jbench limit 10" );
while jag.fetch():
    jag.printRow();
    u=jag.getValue("uid")
    a=jag.getValue("addr")
    s = 'uid is ' + repr(u) + '  addr is ' + repr(a)
    js=jag.json()
    print (s)
    print (js)
jag.endQuery()


rc = jag.execute( "drop table t123;");
rc = jag.execute( "create table t123 (key: uid char(32), value: dept char(32) ); " );
rc = jag.execute( "insert into t123 values ( k1, v1 )");
rc = jag.execute( "insert into t123 values ( k2, v1 )");
rc = jag.execute( "insert into t123 values ( k3, v3 )");

rc = jag.startQuery( "select * from t123 limit 10" );
while jag.fetch():
    jag.printRow();
    js=jag.json()
    print (js)
    v, exist = jag.getDoubleValue("fff")
    print(f"fff double value={v} exist={exist}")
jag.endQuery()

rc = jag.execute( "drop table t123" );

jag.close()
jag = None
