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

ctypes using HRESULT(python)
How to export property values with django-import-export
Plotting Coordinate Lines Using Matplotlib
BASH - Summarising information present in 2 genotype data columns in one column (ped file) [closed]
Python 3: How to call function from another file and pass arguments to that function ?
Streaming mp3 files in Django through Nginx
Opening PE file with Bokken
Python exercise: last letter / first letter
Python/Pygame: Can you run a program whilst having a Pygame window that can still update?
Replacing values in array from netCDF
confused about Python list syntax
Object orientated function parameter to alter variables
Batch processing and breaking up an image
How can I connect multiple if statements when using regular expressions?
Using A For Loop to Return Unique Values in a Pandas Dataframe
Scraping a paginated website with fixed url for every page (Python)

Categories

HOME
swift
ibm-watson-cognitive
admin-on-rest
project-management
npm
angular2-routing
smartphone
deep-linking
codeeffects
is-empty
apache2
phaser-framework
devstack
sequelize.js
codeblocks
ng-admin
uiscrollview
game-physics
react-leaflet
datagrip
mule-studio
bar-chart
rhapsody
cairo
anychart
jpeg2000
jsonserializer
flexlm
cruisecontrol.net
azure-servicebus-queues
jflex
non-deterministic
classpath
xilinx-ise
autofill
superscript
vegan
freebase
large-data
service-locator
precedence
remote-server
jboss-esb
initializer
polyfills
twiki
bing-translator-api
g1gc
cppunit
amd
vcf
defold
mouseclick-event
multi-agent
persistent
ogre3d
cgcontext
text-classification
crystal-reports-8.5
selenium-firefoxdriver
mercury
date-range
festival
coremidi
libreadline
audioqueue
rstudio-server
mailcatcher
aescryptoserviceprovider
qregexp
concur
code-readability
evo
visual-studio-code
mogrify
vine
crash-dumps
adodb
candidate-key
adcolony
hidden-field
eclipse-classpath
smartystreets
resource-files
xenocode
ksoap2
chrome-for-android
javascriptmvc
digital-design
qt4.6
zend-framework-modules
scrollto
legacy-code
text-size
goliath
opcodes
interface-design
rd
cots

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