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 4060200
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:18:28+00:00 2026-05-20T15:18:28+00:00

I’m using the MySQLdb package for interacting with MySQL. I’m having trouble getting the

  • 0

I’m using the MySQLdb package for interacting with MySQL. I’m having trouble getting the proper type conversions.

I am using a 16-byte binary uuid as a primary key for the table and have a mediumblob holding zlib compressed json information.

I’m using the following schema:

CREATE TABLE repositories (
    added_id int auto_increment not null,
    id binary(16) not null,
    data mediumblob not null,
    create_date int not null,
    update_date int not null,
    PRIMARY KEY (added_id),
    UNIQUE(id)
) DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ENGINE=InnoDB;

Then I create a new row in the table using the following code:

data = zlib.compress(json.dumps({'hello':'how are you :D'})
row_id = uuid.uuid(4).hex
added_id = cursor.execute('
    INSERT INTO repositories (id, data, create_date, update_date) 
    VALUES (%s, %s, %s, %s)',
    binascii.a2b_hex(row_id), 
    data, 
    time.time(), 
    time.time()
)

Then to retrieve data I use a similar query:

query = cursor.execute('SELECT added_id, id, data, create_date, update_date ' \
    'FROM repositories WHERE id = %s',
    binascii.a2b_hex(row_id)
)

Then the query returns an empty result.

Any help would be appreciated. Also, as an aside, is it better to store unix epoch dates as integers or TIMESTAMP?

NOTE: I am not having problems inserting the data, just trying to retrieve it from the database. The row exists when I check via mysqlclient.

Thanks Alot!@

  • 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-20T15:18:28+00:00Added an answer on May 20, 2026 at 3:18 pm

    One tip: you should be able to call uuid.uuid4().bytes to get the raw
    bytes. As for timestamps, if you want to perform time/date manipulation
    in SQL it’s often easier to deal with real TIMESTAMP types.

    I created a test table to try to reproduce what you’re seeing:

    CREATE TABLE xyz (
        added_id INT AUTO_INCREMENT NOT NULL,
        id BINARY(16) NOT NULL,
        PRIMARY KEY (added_id),
        UNIQUE (id)
    ) DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ENGINE=InnoDB;
    

    My script is able to insert and query for the rows using the binary field as a
    key without problem. Perhaps you are incorrectly fetching / iterating over the
    results returned by the cursor?

    import binascii
    import MySQLdb
    import uuid
    
    conn = MySQLdb.connect(host='localhost')
    
    key = uuid.uuid4()
    print 'inserting', repr(key.bytes)
    r = conn.cursor()
    r.execute('INSERT INTO xyz (id) VALUES (%s)', key.bytes)
    conn.commit()
    
    print 'selecting', repr(key.bytes)
    r.execute('SELECT added_id, id FROM xyz WHERE id = %s', key.bytes)
    for row in r.fetchall():
        print row[0], binascii.b2a_hex(row[1])
    

    Output:

    % python qu.py    
    inserting '\x96\xc5\xa4\xc3Z+L\xf0\x86\x1e\x05\xebt\xf7\\\xd5'
    selecting '\x96\xc5\xa4\xc3Z+L\xf0\x86\x1e\x05\xebt\xf7\\\xd5'
    1 96c5a4c35a2b4cf0861e05eb74f75cd5
    % python qu.py
    inserting '\xac\xc9,jn\xb2O@\xbb\xa27h\xcd<B\xda'
    selecting '\xac\xc9,jn\xb2O@\xbb\xa27h\xcd<B\xda'
    2 acc92c6a6eb24f40bba23768cd3c42da
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm making a simple page using Google Maps API 3. My first. One marker
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
In order to apply a triggered animation to all ToolTip s in my app,
I want use html5's new tag to play a wav file (currently only supported
I want to count how many characters a certain string has in PHP, but
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

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.