Skip to content
Discussion options

You must be logged in to vote

You can also use match statements with get:

import apsw

con = apsw.Connection("")

con.execute("create table mytable(foo,bar,baz)")
con.executemany("insert into mytable values(?,?,?)",
                (
                    (1,2,3),
                    (4,5,6),
                    (7,8,9),
                ))


match con.execute("select foo, bar from mytable where baz=3").get:
    case None:
        print("no row")
    case [foo, bar]:
        print(f"{foo=} {bar=}")

match con.execute("select foo, bar from mytable where baz=-3").get:
    case None:
        print("no row")
    case [foo, bar]:
        print(f"{foo=} {bar=}")

That outputs:

foo=1 bar=2
no row

Since match statements don't h…

Replies: 5 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@DavidBuchanan314
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by rogerbinns
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants