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

Python - Py2exe error
Anaconda import packages from another environment
How to Drag & Drop Multiple rows of a QTableView in pyqt5
Handle prompts in Python - popen
How to create an infinite iterator to generate an incrementing alphabet pattern?
Python RTMP Authenticiation Script
How to change background colour in Kivy
Is it correct to use kwargs in the following scenario of python code?
List comprehension with elements appearing twice
How to unread a single char in Python?
Python - pass console command to 3rd party console application
Use select_related for comma separated field
Tensorflow Slim: 'module' object has no attribute 'sum_of_squares'
Trouble trying to test Tensorflow's RNN PTB example
Assert two variables are almost equal in python
PyQt: How to expand all children in a QTreeWidget

Categories

HOME
cil
erlang
payment-gateway
meshlab
bing
laravel-5.3
google-sheets-api
deep-linking
zend-framework2
search-engine
appmaker
ios10
defragmentation
value
tizen-wearable-sdk
proguard
constructor
eclipse-cdt
lotus-notes
wordpress-theming
cloudflare
netezza
scaling
dendrogram
ada
zend-framework-mvc
jsonserializer
facebook4j
servicemix
profile
widevine
pptp
google-api-dotnet-client
pep8-assembly
pari
entity-system
fractals
pljson
fabric-digits
remote-server
css-counter
ksoap
codesys
installshield-2012
android-preferences
common.logging
microdata
asmx
ticker
selenium-firefoxdriver
shinyjs
libtiff.net
coremidi
slam-algorithm
gitweb
json-schema-validator
contour
application-loader
risk-analysis
ubercart
epl
ember-cli-addons
grunt-contrib-concat
genetic-programming
method-overriding
smartystreets
httpcontext
db4o
sslexception
nscolor
dllexport
ruboto
iconv
objcmongodb
supersized
electronic-signature
goliath
symbol-server
hadoop-plugins
unreachable-code
rtsp-client
savestate
evb
handheld
standardized
hardware-infrastructure

Resources

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
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App