How to print a sqlite table content with genie programming language -


based on previous questions here managed create dataset, print recipes listed , trying pick 1 of recipes list , show title, instructions , ingredients. instructions mapped recipes via pkid column , ingredients mapped recipes through recipeid column. when open database on sqlite database browser can access information inside tables dropdown list, suppose proper name them tables within database.

i not being able "filter" pkid , recipeid, after picking 1 recipe, appropriate content shown.

this code in python of trying in genie:

  def printsinglerecipe(self,which):     sql = 'select * recipes pkid = %s' % str(which)     print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'     x in cursor.execute(sql):       recipeid =x[0]       print "title: " + x[1]       print "serves: " + x[2]       print "source: " + x[3]     print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'     sql = 'select * ingredients recipeid = %s' % recipeid     print 'ingredient list:'     x in cursor.execute(sql):         print x[1]     print ''     print 'instructions:'     sql = 'select * instructions recipeid = %s' % recipeid     x in cursor.execute(sql):       print x[1]     print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'     resp = raw_input('press key -> ') 

i have not been able improve of code, seems using approach used before of iterating in step statement cannot used here. how far got in genie:

def printsinglerecipe(db:database)     stmt:statement = preparedstatements.select_all( db )     res:int = userinterface.raw_input("select recipe -> ").to_int()     cols:int = stmt.column_count ()     var row = new dict of string, string     item:int = 1     print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"     while res == row         i:int = 0 (cols - 1)             row[ stmt.column_name( ) ] = stmt.column_text( )         stdout.printf( "%-5s", item.to_string( "%03i" ))         stdout.printf( "%-30s", row[ "title" ])         stdout.printf( "%-20s", row[ "serves" ])         stdout.printf( "%-30s\n", row[ "source" ])     print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"     print "ingredient list"     print " "     stdout.printf("%-5s", item.to_string( "%03i" )) 

i have found solution problem, maybe can optimized. enough.

answers question helped immensely. solution used use exec function , point callback printsinglerecipe().

some adjustments had done work callback, got needed.

here code function gets called:

while true     response:string = userinterface.get_input_from_menu()     if response == "1" // show recipes         printallrecipes(db)     else if response "2" // search recipe         pass     else if response "3" //show recipe         res:string = userinterface.raw_input("select recipe -> ")         sql:string = "select * recipes pkid = " + res         db.exec(sql, printsinglerecipe, null)     else if response "4"//delete recipe         pass     else if response "5" //add recipe         pass     else if response "6" //print recipe         pass     else if response "0" //exit         print "goodbye"         break     else         print "unrecognized command. try again." 

here how printsinglerecipe looks like:

def printsinglerecipe(n_columns:int, values:array of string, column_names:array of string):int     print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"     i:int = 0 n_columns         stdout.printf ("%s = %s\n", column_names[i], values[i])     print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"     print "ingredient list"     print " "     return 0 

Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -