Python Forum
is this a good way to catch exceptions?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
is this a good way to catch exceptions?
#11
really ?
Beacuse this is how I ahve done this for more then 1 year on 5-6 codes
didn't have any problems
I will have a look - but if you can point me to what will be better to do - it will be great

Thanks ,
Reply
#12
SQL injection is a real thing, yes. Maybe your level of risk is low for whatever reason (no-one else can run these scripts, they aren't accessible in a way where the input can't be verified, ...), but given that it's so easy to do this properly, there isn't any reason not to. You can educate yourself on SQL injection and as I mentioned before, check the documentation for your database driver to see how to parameterise the queries correctly (it's not obvious which DB you're using).
Reply
#13
I'm using mysql DB
and the only different I'm seeing is in the writing without '+' and using '%'
("INSERT INTO salaries "
              "(emp_no, salary, from_date, to_date) "
              "VALUES (%(emp_no)s, %(salary)s, %(from_date)s, %(to_date)s)")
this is what you mean?

I can change my code to this - if it's the right\acceptable way to write.
Reply
#14
That looks like the right idea, yes. The docs should show you the call to execute as well where you actually pass the values for those parameters.
Reply
#15
Finally, I have found something which helped me. Many thanks!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  try catch not working? korenron 2 812 Jan-15-2023, 01:54 PM
Last Post: korenron
  PiCamera - print exceptions? korenron 2 792 Dec-15-2022, 10:48 PM
Last Post: Larz60+
  Multiprocessing queue catch get timeout Pythocodras 1 2,242 Apr-22-2022, 06:01 PM
Last Post: Pythocodras
  Class exceptions DPaul 1 1,259 Mar-11-2022, 09:01 AM
Last Post: Gribouillis
  twisted: catch return from sql wardancer84 0 1,501 Sep-08-2021, 12:38 PM
Last Post: wardancer84
  how to catch schema error? maiya 0 1,809 Jul-16-2021, 08:37 AM
Last Post: maiya
  pool mysql error - not catch by try\except? korenron 1 2,101 Jul-05-2021, 11:26 AM
Last Post: ibreeden
  Python, exceptions KingKhan248 6 2,947 Nov-15-2020, 06:54 AM
Last Post: buran
  try catch question ,get data from main code korenron 7 3,104 Nov-03-2020, 09:28 AM
Last Post: korenron
  Split string between two different delimiters, with exceptions DreamingInsanity 2 1,983 Aug-24-2020, 08:23 AM
Last Post: DreamingInsanity

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020