Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,154,678 members, 7,823,917 topics. Date: Friday, 10 May 2024 at 06:16 PM

Python Mysql - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Python Mysql (1491 Views)

Please How Do I Print This Data From MY Database. MYSQL, PHP / Lets Start A Real Web-deveopment Course Here Html+css+javascript+php+mysql / DHTMLSQL - A Very Advanced Wrapper For Mysql Database! (2) (3) (4)

(1) (Reply) (Go Down)

Python Mysql by lukman008: 5:23am On Jul 26, 2015
What's up guys.. I'm writing a Python application which uses a datepicker.. I tried inserting the value from the datepicker into a database but it gives me the error ' Python datetime cannot be converted to a mysql type'

I converted the date value to a string and I was able to insert it,but now I need to use the date in a BETWEEN statement but I get syntax error. Please how can I go about this? Any help would be appreciated. This is the source code below

.............
date =str(self.dp.GetValue())

def display (self,event):
Level=into(self.textctrl.GetValue()):
If level==100:
Tomorrow = datetime.now().date() + timedelta (days = 1)
Tomorrow = str(Tomorrow)

Next_tomorrow = datetime.now().date() + timedelta (days = 2)

Next_Tomorrow = str(Next_Tomorrow)
cursor.execute("SELECT name,dept FROM table1 " "WHERE date BETWEEN %s AND %s" , (Tomorrow, Next_tomorrow)


PS:dp is the name of my datepicker


I hope its not too long I wanted to make it as explanatory as possible. Thank you.
Re: Python Mysql by umaryusuf(m): 10:29am On Jul 26, 2015
lukman008:
What's up guys.. I'm writing a Python application which uses a datepicker.. I tried inserting the value from the datepicker into a database but it gives me the error ' Python datetime cannot be converted to a mysql type'
I converted the date value to a string and I was able to insert it,but now I need to use the date in a BETWEEN statement but I get syntax error. Please how can I go about this? Any help would be appreciated. This is the source code below
.............
date =str(self.dp.GetValue())
def display (self,event):
Level=into(self.textctrl.GetValue()):
If level==100:
Tomorrow = datetime.now().date() + timedelta (days = 1)
Tomorrow = str(Tomorrow)
Next_tomorrow = datetime.now().date() + timedelta (days = 2)
Next_Tomorrow = str(Next_Tomorrow)
cursor.execute("SELECT name,dept FROM table1 " "WHERE date BETWEEN %s AND %s" , (Tomorrow, Next_tomorrow)
PS:dp is the name of my datepicker
I hope its not too long I wanted to make it as explanatory as possible. Thank you.



Consider the following:-
Have u tried another db (sqlite) to see if it throw the same error?

Also from ur code above, the variable "Level" isn't the same as that in if-statement "level". See attached image.

What library/framework are u using for the application?

Re: Python Mysql by lukman008: 1:06pm On Jul 26, 2015
I made a mistake in the level thing.. Its not the problem.. It should be level =int(self.GetValue ())

Using sqlite would be too much work .. I mean I'd have to start again.. And wamp server is really making things easier for me.
The exact error is "syntax error in 'WHERE date BETWEEN '2015-07-27' AND '2015-07-28' in line 1"
Re: Python Mysql by umaryusuf(m): 3:18pm On Jul 26, 2015
lukman008:
I made a mistake in the level thing.. Its not the problem.. It should be level =int(self.GetValue ())

Using sqlite would be too much work .. I mean I'd have to start again.. And wamp server is really making things easier for me.
The exact error is "syntax error in 'WHERE date BETWEEN '2015-07-27' AND '2015-07-28' in line 1"

You did not state what library u are using? I wanted to know the exact resources required to test run your code.

However the error position is obviously from the SQL statement as seen above.

Check ur sql syntax well, I suspect issues with "SQL BETWEEN" Condition. I saw some empty quotes and unclosed parenthesis within ur syntax. Also check your string formating within your syntax.


The SQL BETWEEN Condition is used to retrieve values within a range in a SELECT, INSERT, UPDATE, or DELETE statement. The values can be numbers, text, or dates (as u want to use).

Make your syntax match this SQL BETWEEN Syntax
SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN value1 AND value2;

That is:-

cursor.execute("SELECT name, dept FROM table1 " "WHERE date BETWEEN %s AND %s" ), (Tomorrow, Next_tomorrow)

Or, do like so:-

query = ("SELECT name, dept FROM table1 " "WHERE date BETWEEN %s AND %s" )

cursor.execute(query, (Tomorrow, Next_tomorrow))


Hope this helps.
Re: Python Mysql by lordZOUGA(m): 4:01pm On Jul 26, 2015
It is better to save dates as UNIX timestamps in the database. It will make your life longer.

1 Like

Re: Python Mysql by lukman008: 7:09pm On Jul 28, 2015
Thanks guys.. The problem was a comma in the wrong place angry.. Can't believe it took me so long to notice it.. Thanks a lot... #GodBless smiley smiley
Re: Python Mysql by maekhel(m): 8:38pm On Jul 28, 2015
lukman008:
Thanks guys.. The problem was a comma in the wrong place angry.. Can't believe it took me so long to notice it.. Thanks a lot... #GodBless smiley smiley
Lil errors like dat can be so frustrating
Re: Python Mysql by umaryusuf(m): 3:33pm On Jul 30, 2015
lukman008:
Thanks guys.. The problem was a comma in the wrong place angry.. Can't believe it took me so long to notice it.. Thanks a lot... #GodBless smiley smiley

Ok, good to hear u fixed it.

But, u for post the correct syntax that worked for u, for the sake of future researchers that my stumble on this thread. Because there are scanty resources on "Python and MySQL" compared to "PHP and MySQL".
Re: Python Mysql by lukman008: 3:04pm On Aug 09, 2015
Oh.. Okay..
cursor.execute("SELECT name, dept FROM table1 " "WHERE date BETWEEN %s AND %s" ), (Tomorrow, Next_tomorrow)
Re: Python Mysql by somando19: 5:54pm On Aug 09, 2015
Help me with code that will make my calculator working perfection and how to create table using mySQL database
Re: Python Mysql by lukman008: 11:01am On Aug 16, 2015
What are you trying to do
Re: Python Mysql by lukman008: 11:02am On Aug 16, 2015
What calculator.. What problem are you facing? What library are you using.. What are you trying to query.. Your question is too vague.. Please explain so I can help
Re: Python Mysql by Kensharval(m): 9:02pm On Aug 18, 2015
If you wish to have a professional shared hosting quality in a free hosting package, come and host with 000webhost.com and experience the best service you can get absolutely free. Founded in December 2006, 000webhost.com has a trusted free hosting members base of over 60,000 members and still counting! Offering professional quality hosting, support, uptime and reliability, we have a great community of webmasters, you'd love to be a part of! Register now and get it all free: *** 1500 MB of disk space *** 100 GB of data transfer *** PHP and MySQL support with no restrictions *** cPanel control panel *** Website Builder *** Absolutely no advertising! Join us now: http:// www.000webhost.com/876430.html
Re: Python Mysql by Arafen(m): 2:26pm On Jan 13, 2022
In my work, I try to use third-party helpers to write and check code. Also the joins in sql solution helps connect tables and saves a lot of time. I recommend looking at their site for useful solutions for almost any area of programming and databases.
Re: Python Mysql by 1saed: 5:58pm On Jan 13, 2022
Hi

Trust you having a fulfilling day already


A lot of development led me to put down this piece.


So many micro scale businesses are in dire need of an app to take care of their voluminous daily transactions.


I had a time on call with a would-be client today from Onitsha Anambra state.

He wanted to be sure if our platform, Thriftplus, can manage his business. I asked him to provide his typical day's operation, and he did, I took note.


After three more questions, he paused and said this is his third failed attempt at obtaining a product that truly answers to his business needs and that he was just tired of the search.



One thing led to another, I arranged a zoom meet with him , cos we have stopped the policy of giving random access to intended clients.

I noticed that in the course of the meet, his words were so few. When I was through, he rolled out loads of queries, which I tried to provide answers to.


The meeting ended, we exchanged pleasantries and he parted by saying.... Finale I found a solution



As at today, he's referenced three other clients and we have been smiling to bank.



Take note

If your business is daily contributions, savings and loans, target savings, investment banking
Or you run a cooperative and you have search the internet for a solution, come to Thriftplus.



Our platform offers services to all the businesses mentioned above.



And we giving you 60days free access ( that's it)

To get started, visit our site


https://Thriftplus.pythonanywhere.com



Mathew

07031009036

(1) (Reply)

In Need Of A Laptop For Programming / Second New Laptop Will Go A Long Way. / Top 10 AI Apps Of 2022

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 28
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.