@dataclassclassDB_ToDoListExists:#OutputsnoOf:int@classmethoddefget_statement(cls,ID:int)->TextAsFrom:class_ret:sequence="default,"#postgres uses default for sequencesoutput=" OUTPUT (noOf)"tail=" RETURNING noOf"#session.bind.dialect.namestatement=sa.text(f"/* PROC ToDoList_App.ToDoList.Exists */"f"select count(*) noOf from ToDoList_App.ToDoList"f" where ID = :ID")text_statement=statement.columns(noOf=sa.types.Integer,)text_statement=text_statement.bindparams(ID=ID,)returntext_statement@classmethoddefexecute(cls,session:Session,ID:int)->Optional['DB_ToDoListExists']:params=process_bind_params(session,[sa.types.Integer,],[ID,])res=session.execute(cls.get_statement(*params))rec=res.fetchone()ifrec:res.close()returnprocess_result_rec(DB_ToDoListExists,session,[sa.types.Integer,],rec)returnNone
1 2 3 4 5 6 7 8 9101112131415161718192021
publicbooleanexists()throwsSQLException{Stringstatement="/* PROC BooksAndAuthors.ToDoList.Exists */"+"select count(*) noOf from BooksAndAuthors.ToDoList"+" where ID = ?";PreparedStatementprep=connector.prepareStatement(statement);prep.setInt(1,id);ResultSetresult=prep.executeQuery();if(!result.next()){result.close();prep.close();returnfalse;}noOf=result.getInt(1);result.close();prep.close();returntrue;}