python


MYsql Stored procedure only work the second time i execute it through python


I'm using python to create a data warehouse in MySQL.
I'm using the MySQLdb package to connect python to MySQL.
I am trying to create a table which will contain all dates from 2005 to 2018.
First, I create the relevant table:
cursor.execute("""
CREATE TABLE IF NOT EXISTS dim_date (
date_id int(11) NOT NULL AUTO_INCREMENT,
date date,
day int(11),
month int(11),
year int(11),
day_name varchar(45),
PRIMARY KEY (date_id),
INDEX date_index (date))
""")
Then, I run the following command to create and run the stored procedure that will fill in the dates:
cursor.execute("DROP PROCEDURE IF EXISTS BuildDate;")
cursor.execute("SET #currdate := '2005-01-01';")
cursor.execute("SET #enddate := '2018-01-01';")
cursor.execute("""
CREATE PROCEDURE BuildDate()
BEGIN
WHILE #currdate < #enddate DO
INSERT INTO ntr_yelp_dw.dim_date (date, day, month, year, day_name)
VALUES (
#currdate, DAY(#currdate), MONTH(#currdate),
YEAR(#currdate), DAYNAME(#currdate)
);
SET #currdate := DATE_ADD(#currdate, INTERVAL 1 DAY);
END WHILE;
END
""")
cursor.callproc("BuildDate")
The thing is that when I run the stored procedure code, the stored procedure is created, but the data isn't filled.
Only when I run it a second time, the data is created and inserted into the table.
Any thoughts?


Related Links

Memory allocation for numpy.array with copy=False?
Draw contours of detected objects using python and opencv
simple web crawler i need to eliminate the duplicate URL that present in the array
Python: comparing list to a string
Is there any way to write '\r' into a file on linux with python? [closed]
matplotlib retrieve color from plt.plot command
Why are tuples slower than lists at evaluating generators into themselves?
call and control git bash from python script in windows
How get in real time POST update with django and instagram api?
Binary search tree insert method
Log scale mathplotlib in Python?
Why does python come with so many similar, but subtly different functionality for fulfilling certain elementary computing tasks?
How to have adjacent elements reduced to a single element [closed]
adding row to pandas dataframe from series
Python3.4 PIP install error while building
“Settings” for a function in Python

Categories

HOME
ajax
ibm-watson-cognitive
meshlab
checkbox
scipy
docker-swarm
safari
urlencode
xcode8.3
openwrt
netflix-feign
dropbear
eclipse-luna
arraylist
internet-explorer-8
prestodb
jsonserializer
dspic
piwik
yosys
printdocument
jenkins-job-dsl
reply
dpi
superscript
helix-3d-toolkit
ksoap
stdclass
mediawiki-extensions
bing-translator-api
spring-bean
filepath
tuleap
chunked-encoding
gauss
maintenance
pluck
crystal-reports-8.5
forerunnerdb
nuget-server
heroku-postgres
emoticons
bettercms
restivejs
payu
gradle-script-kotlin
hspec
vst
json-schema-validator
gemini
anti-cheat
group-concat
bluesnap
web-essentials
hateoas
jenkins-scriptler
qbfc
integral
custom-url
adodb
java-melody
named-ranges
gyroscope-framework
ibmsbt
facebook-wall
ember-addon
emma
funkload
factors
facebook-chat
cdata
sql-server-2012-web
carddav
grunt-contrib-compass
iconv
xml-libxml
autostart
blockingqueue
getusermedia
parameterization
flexicious
hinstance
selectonemenu
objectbrowser
gtk2hs
dcpu-16
pantheios
dirty-data





Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm