Jun-14-2020, 12:46 AM
Hey guys now I'm trying to do a search of a table with isbn title author and year. For now I'm just trying direct searches since I don't want to involve the wildcare special chars for the LIKE searches. But I still can't get it to work. Can someone help me figure it out?
Thanks!
Thanks!
@app.route("/search", methods=["GET", "POST"]) def search(): b = db.execute("SELECT * FROM books WHERE author=:search ", {"search":search}).fetchone() print(b) return render_template("search.html")
Error:sqlalchemy.exc.ProgrammingError
sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) can't adapt type 'function'
[SQL: SELECT * FROM books WHERE author=%(search)s ]
[parameters: {'search': <function search at 0x0478B418>}]
(Background on this error at: http://sqlalche.me/e/f405)
Traceback (most recent call last)
File "C:\Python38\Lib\site-packages\sqlalchemy\engine\base.py", line 1247, in _execute_context
self.dialect.do_execute(
File "C:\Python38\Lib\site-packages\sqlalchemy\engine\default.py", line 590, in do_execute
cursor.execute(statement, parameters)
The above exception was the direct cause of the following exception:
File "C:\Python38\Lib\site-packages\flask\app.py", line 2464, in __call__
return self.wsgi_app(environ, start_response)
File "C:\Python38\Lib\site-packages\flask\app.py", line 2450, in wsgi_app
response = self.handle_exception(e)
File "C:\Python38\Lib\site-packages\flask\app.py", line 1867, in handle_exception
reraise(exc_type, exc_value, tb)
File "C:\Python38\Lib\site-packages\flask\_compat.py", line 39, in reraise
raise value
File "C:\Python38\Lib\site-packages\flask\app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "C:\Python38\Lib\site-packages\flask\app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Python38\Lib\site-packages\flask\app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\Python38\Lib\site-packages\flask\_compat.py", line 39, in reraise
raise value
File "C:\Python38\Lib\site-packages\flask\app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Python38\Lib\site-packages\flask\app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "C:\school\project1\application.py", line 32, in search
b = db.execute("SELECT * FROM books WHERE author=:search ", {"search":search}).fetchone()
File "C:\Python38\Lib\site-packages\sqlalchemy\orm\scoping.py", line 162, in do
return getattr(self.registry(), name)(*args, **kwargs)
File "C:\Python38\Lib\site-packages\sqlalchemy\orm\session.py", line 1277, in execute
return self._connection_for_bind(bind, close_with_result=True).execute(
File "C:\Python38\Lib\site-packages\sqlalchemy\engine\base.py", line 984, in execute
return meth(self, multiparams, params)
File "C:\Python38\Lib\site-packages\sqlalchemy\sql\elements.py", line 293, in _execute_on_connection
return connection._execute_clauseelement(self, multiparams, params)
File "C:\Python38\Lib\site-packages\sqlalchemy\engine\base.py", line 1097, in _execute_clauseelement
ret = self._execute_context(
File "C:\Python38\Lib\site-packages\sqlalchemy\engine\base.py", line 1287, in _execute_context
self._handle_dbapi_exception(
File "C:\Python38\Lib\site-packages\sqlalchemy\engine\base.py", line 1481, in _handle_dbapi_exception
util.raise_(
File "C:\Python38\Lib\site-packages\sqlalchemy\util\compat.py", line 178, in raise_
raise exception
File "C:\Python38\Lib\site-packages\sqlalchemy\engine\base.py", line 1247, in _execute_context
self.dialect.do_execute(
File "C:\Python38\Lib\site-packages\sqlalchemy\engine\default.py", line 590, in do_execute
cursor.execute(statement, parameters)
sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) can't adapt type 'function'
[SQL: SELECT * FROM books WHERE author=%(search)s ]
[parameters: {'search': <function search at 0x0478B418>}]
(Background on this error at: http://sqlalche.me/e/f405)