1
c.execute("SELECT * FROM Student WHERE Forename =:forename AND Surname =:surname AND YearGroup =:yeargroup AND FormNumber =:formnumber BETWEEN :startdate AND :enddate", {"forename": forename, "surname": surname, "yeargroup": yeargroup, "formnumber": formnumber, "startdate": startdate, "enddate": enddate})

studentRequest = c.fetchall()
records = studentRequest

#write to file

f = open('Student Report', 'w')
f.write(name)
f.write(' Form Number: ' + (yeargroup +'/'+ formnumber))
f.write(str(records))
f.close()

This is my code but it doesn't seem to write the data from the database to the file. The name, Forum Number etc is written though.

Can anyone help?

1
  • try printing out 'records' to the terminal. I'm guessing it is a list or a tuple so you would need to access individual records by iterating through it. for item in record... Commented Feb 18, 2014 at 16:10

1 Answer 1

1

Does your output have "[]" in it? It sounds like your query doesn't find any matches.

If this isn't so, prepare a complete, runnable example showing the problem.

Sign up to request clarification or add additional context in comments.

6 Comments

Yes it does return a [] when attempted. Maybe this is a problem with inputting data to the database then?
I think your problem is your query syntax. Try starting with a small piece of it and see if that returns anything. Then build it from there.
@Jambofun, Yes, or your select query isn't the one you really want. A very common error people make when adding data to a database is forgetting to commit.
I think that I may of found the issue thank you Bill. However, i'm learning as I'm programming so am unsure of how to tackle it. I believe its to do with the 'BETWEEN' in my query as I have not related it in any way to the Date column in my table. How do I do this?
Perhaps the query you're looking for is more like SELECT * FROM Student WHERE Forename =:forename AND Surname =:surname AND YearGroup =:yeargroup AND FormNumber =:formnumber AND Date BETWEEN :startdate AND :enddate?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.