Hi all,     

                I’m working on the same movie review project as before, but I 
recently tried to create a new search module for my search function, which is 
to search for the movie’s imdbid. Each movie has its own unique imdbid, but 
when I search for a single unique imdbid, somehow all the movies pop out. Can 
someone point out the source of the problem? On a side note, I tried to include 
a print statement in each condition statement, but nothing is printed, and I 
tried fetchone instead of fetchall, but it didn’t work either. Thanks in 
advance!

Here is my results function:

````

@app.route("/movie_results")

def movie_results():

    name = request.args.get("movie.title")

    year = request.args.get("movie.year")

    imdbid = request.args.get("movie.imdbid")

    name_pattern = "%" + name + "%"

    if year == '' or None and imdbid == '' or None:

        search_movie_statement = sqlalchemy.text('SELECT * FROM movies WHERE 
title ILIKE :movie_title')

        movie_specific = engine.execute(search_movie_statement, 
movie_title=name_pattern).fetchall()

        if len(movie_specific) != 0 and movie_specific is not None:

            return render_template("movie_specific.html", 
movie_specific=movie_specific)

        if len(movie_specific) == 0:

            return render_template("error2.html", message="No such movie.")

    elif name == '' or None and imdbid == '' or None:

        search_movie_statement = sqlalchemy.text('SELECT * FROM movies WHERE 
year = :year')

        movie_specific = engine.execute(search_movie_statement, 
year=year).fetchall()

        if len(movie_specific) != 0 and movie_specific is not None:

            return render_template("movie_specific.html", 
movie_specific=movie_specific)

        if len(movie_specific) == 0:

            return render_template("error2.html", message="No such movie.")

 

    elif name == '' or None and year == '' or None:

        search_movie_statement = sqlalchemy.text('SELECT * FROM movies WHERE 
"imdbID" = :imdbId')

        movie_specific = engine.execute(search_movie_statement, 
imdbId=imdbid).fetchall()

        if len(movie_specific) != 0 and movie_specific is not None:

            return render_template("movie_specific.html", 
movie_specific=movie_specific)

        if len(movie_specific) == 0:

            return render_template("error2.html", message="No such movie.")

 

    elif name == '' or None:

        print(name)

        search_movie_statement = sqlalchemy.text('SELECT * FROM movies WHERE 
"imdbID" = :imdbid AND year = :year')

        movie_specific = engine.execute(search_movie_statement, imdbid=imdbid, 
year=year).fetchall()

        if len(movie_specific) != 0 and movie_specific is not None:

            return render_template("movie_specific.html", 
movie_specific=movie_specific)

        if len(movie_specific) == 0:

            return render_template("error2.html", message="No such movie.")

 

    elif year == '' or None:

        search_movie_statement = sqlalchemy.text('SELECT * FROM movies WHERE 
"imdbID" = :imdbid and title ILIKE :movie_title')

        movie_specific = engine.execute(search_movie_statement, imdbid=imdbid, 
movie_title=name_pattern).fetchall()

        if len(movie_specific) != 0 and movie_specific is not None:

            return render_template("movie_specific.html", 
movie_specific=movie_specific)

        if len(movie_specific) == 0:

            return render_template("error2.html", message="No such movie.")

 

    elif imdbid == '' or None:

        search_movie_statement = sqlalchemy.text('SELECT * FROM movies WHERE 
year = :year and title ILIKE :movie_title')

        movie_specific = engine.execute(search_movie_statement, year=year, 
movie_title=name_pattern).fetchall()

        if len(movie_specific) != 0 and movie_specific is not None:

            return render_template("movie_specific.html", 
movie_specific=movie_specific)

        if len(movie_specific) == 0:

            return render_template("error2.html", message="No such movie.")

 

    elif name != None and name != '' and year != '' and year != None and imdbid 
!= '' and imdbid != None:

        search_movie_statement = sqlalchemy.text('SELECT * FROM movies WHERE 
year = :year and title ILIKE :movie_title and imdbID = :imdbid')

        movie_specific = engine.execute(search_movie_statement, year=year, 
movie_title=name_pattern, imdbid=imdbid).fetchall()

        if len(movie_specific) != 0 and movie_specific is not None:

            return render_template("movie_specific.html", 
movie_specific=movie_specific)

        if len(movie_specific) == 0:

            return render_template("error2.html", message="No such movie.")

````

Here is my movie table:

````

CREATE TABLE movies (

      "title" TEXT UNIQUE NOT NULL,

      "year" INTEGER NOT NULL,

      "runtime" INTEGER NOT NULL,

      "imdbID" VARCHAR NOT NULL,

      "imdbRating" NUMERIC NOT NULL

  );

````

Thanks, 

Cravan

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/A18038FC-74A8-4C04-9147-69CD429A1E75%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to