Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7061039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:25:31+00:00 2026-05-28T04:25:31+00:00

Here’s a question for you mysql + python folks out there. Why does this

  • 0

Here’s a question for you mysql + python folks out there.

Why does this mysql sql sequence of commands not work when I execute it through Python, but it does when I execute it via the mysql CLI?


#!/usr/bin/env python

import oursql as mysql
import sys, traceback as tb
import logging

# some other stuff...

class MySqlAuth(object):
    def __init__(self, host = None, db = None, user = None, pw = None, port = None):
        self.host = 'localhost' if host is None else host
        self.db = 'mysql' if db is None else db
        self.user = 'root' if user is None else user
        self.pw = pw
        self.port = 3306 if port is None else port

    @property
    def cursor(self):
        auth_dict = dict()
        auth_dict['host'] = self.host
        auth_dict['user'] = self.user
        auth_dict['passwd'] = self.pw
        auth_dict['db'] = self.db
        auth_dict['port'] = self.port
        conn = mysql.connect(**auth_dict)
        cur = conn.cursor(mysql.DictCursor)
        return cur

def ExecuteNonQuery(auth, sql):
    try:
        cur = auth.cursor
        log.debug('SQL:  ' + sql)
        cur.execute(sql)
        cur.connection.commit()
        return cur.rowcount
    except:
        cur.connection.rollback()
        log.error("".join(tb.format_exception(*sys.exc_info())))
    finally:
        cur.connection.close()

def CreateTable(auth, table_name):

    CREATE_TABLE = """
    CREATE TABLE IF NOT EXISTS %(table)s ( 
              uid VARCHAR(120) PRIMARY KEY
            , k VARCHAR(1000) NOT NULL
            , v BLOB
            , create_ts TIMESTAMP NOT NULL
            , mod_ts TIMESTAMP NOT NULL
            , UNIQUE(k)
            , INDEX USING BTREE(k)
            , INDEX USING BTREE(mod_ts) );
    """
    ExecuteNonQuery(auth, CREATE_TABLE % { 'table' : table_name })

    CREATE_BEFORE_INSERT_TRIGGER = """
    DELIMITER //
    CREATE TRIGGER %(table)s_before_insert BEFORE INSERT ON %(table)s
    FOR EACH ROW
    BEGIN
        SET NEW.create_ts = NOW();
        SET NEW.mod_ts = NOW();
        SET NEW.uid = UUID();
    END;// DELIMIETER ;
    """
    ExecuteNonQuery(auth, CREATE_BEFORE_INSERT_TRIGGER % { 'table' : table_name })

    CREATE_BEFORE_INSERT_TRIGGER = """
    DELIMITER //
    CREATE TRIGGER %(table)s_before_update BEFORE UPDATE ON %(table)s
    FOR EACH ROW
    BEGIN
        SET NEW.mod_ts = NOW();
    END;// DELIMIETER ;
    """
    ExecuteNonQuery(auth, CREATE_BEFORE_UPDATE_TRIGGER % { 'table' : table_name })

# some other stuff

The error that I get when I run the python is this:


2012-01-15 11:53:00,138 [4214 MainThread mynosql.py] DEBUG SQL:  
    DELIMITER //
    CREATE TRIGGER nosql_before_insert BEFORE INSERT ON nosql
    FOR EACH ROW
    BEGIN
        SET NEW.create_ts = NOW();
        SET NEW.mod_ts = NOW();
        SET NEW.uid = UUID();
    END;// DELIMIETER ;

2012-01-15 11:53:00,140 [4214 MainThread mynosql.py] ERROR Traceback (most recent call last):
  File "./mynosql.py", line 39, in ExecuteNonQuery
    cur.execute(sql)
  File "cursor.pyx", line 120, in oursql.Cursor.execute (oursqlx/oursql.c:15856)
  File "cursor.pyx", line 111, in oursql.execute (oursqlx/oursql.c:15728)
  File "statement.pyx", line 157, in oursql._Statement.prepare (oursqlx/oursql.c:7750)
  File "statement.pyx", line 127, in oursql._Statement._raise_error (oursqlx/oursql.c:7360)
ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DELIMITER //\n    CREATE TRIGGER nosql_before_insert BEFORE INSERT ON nosql\n    F' at line 1", None)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T04:25:32+00:00Added an answer on May 28, 2026 at 4:25 am

    Although the error you are getting seems to be generated by the first DELIMITER // statement, you have a typo at the last mention of DELIMITER – you wrote it DELIMIETER ; – try to change that and see if that solves your issue.

    Update

    You have 2 typos for the same DELIMIETER ; – I believe you are getting the error just after the interpreter finds the first one:

     DELIMITER //
        CREATE TRIGGER %(table)s_before_insert BEFORE INSERT ON %(table)s
        FOR EACH ROW
        BEGIN
            SET NEW.create_ts = NOW();
            SET NEW.mod_ts = NOW();
            SET NEW.uid = UUID();
        END;// DELIMIETER ; <-- this one is wrong, it should be DELIMITER
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my question. I am having this simple menu. <div id=menu> <ul> <li>
Here's a coding problem for those that like this kind of thing. Let's see
Here is an example. foreach (var doc in documents) { var processor = this.factory.Create();
Here's what I'm trying to accomplish with this program: a recursive method that checks
Here is the css: #content ul { font-size: 12px; } I am trying this:
Here is what I am trying to achieve in PHP: I have this string:
Here a simple question : What do you think of code which use try
Here's what I'm trying to do... It's quite simple and obviously there must be
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Here's my code: // Not all headers are relevant to the code snippet. #include

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.