现在我已经创建了 SQL 数据库(1、2),我想用它做点什么。我已经启动了一个小函数来处理数据集内容的打印,但是我无法弄清楚如何:
- 调整打印命令上的字符串之间的空间,以使其正确合理?可以使用 ljust() 在 python 中做到这一点,但是如何用 Genie 做类似的事情呢?
- 遍历数据集上的所有条目?据我了解,精灵中没有光标的等价物(不过,也许我在这里错了)。
- 连接到创建的数据库?如何打开它?
- 额外的一点:如何用精灵创建一个存根?我想创建空函数和类,为代码提供一个空结构,但是
pass
精灵中没有命令,编译器似乎不接受空的 if 语句或函数。
这是我试图模仿的python代码:
def PrintAllRecipes(self):
print '%s %s %s %s' % ('Item'.ljust(5),'Name'.ljust(30),'Serves'.ljust(20),'Source'.ljust(30))
print '--------------------------------------------------------------------------------------'
sql = 'SELECT * FROM Recipes'
cntr = 0
for x in cursor.execute(sql):
cntr += 1
print '%s %s %s %s' % (str(x[0]).rjust(5),x[1].ljust(30),x[2].ljust(20),x[3].ljust(30))
print '--------------------------------------------------------------------------------------'
self.totalcount = cntr
这是我已经走了多远:
[indent=4]
class Cookbook
def PrintAllRecipes()
print "%s %s %s %s" % ("Item".ljust(5),"Name".ljust(30),"Serves".ljust(20),"Source".ljust(30))
print "--------------------------------------------------------------------------------------"
var sql = "SELECT * FROM Recipes"
var cntr = 0
for x in cursor.execute(sql)
cntr += 1
print "%s %s %s %s" % (str(x[0]).rjust(5),x[1].ljust(30),x[2].ljust(20),x[3].ljust(30))
print "--------------------------------------------------------------------------------------"
self.totalcount = cntr
def raw_input (query : string? = null) : string?
if (query != null)
stdout.printf ("%s", query)
return stdin.read_line ()
init
//def Menu()
//cbk = Cookbook()
//var loop = True
print "==================================================="
print " RECIPE DATABASE "
print " 1 - Show All Recipes"
print " 2 - Search for a recipe"
print " 3 - Show a Recipe"
print " 4 - Delete a recipe"
print " 5 - Add a recipe"
print " 6 - Print a recipe"
print " 0 - Exit"
print "==================================================="
response:string = raw_input("Enter a selection -> ")