import sys
import random
import string
def main():
    print "# this test is generated by change_column_blob_data.py"
    print "# generate hot blob expansion test cases"
    print "source include/have_tokudb.inc;"
    print "--disable_warnings"
    print "DROP TABLE IF EXISTS t, ti;"
    print "--enable_warnings"
    print "SET SESSION DEFAULT_STORAGE_ENGINE=\"TokuDB\";"
    print "SET SESSION TOKUDB_DISABLE_SLOW_ALTER=1;"
    for f in [ "", "f INT DEFAULT 0", "f INT DEFAULT 0 NOT NULL" ]:
        for v in [ "", "v VARCHAR(32) DEFAULT ''", "v VARCHAR(32) DEFAULT '' NOT NULL" ]:
            for nn in [ "", "NOT NULL" ]:
                gen_test(f, v, nn)
    return 0
def gen_test(f, v, nn):
    blob_types = [ "TINYBLOB", "BLOB", "MEDIUMBLOB", "LONGBLOB" ]

    print gen_table(f, v, nn)
    
    for r in range(3):
        print insert_row("t")

    print "CREATE TABLE ti LIKE t;"
    print "ALTER TABLE ti ENGINE=myisam;"
    print "INSERT INTO ti SELECT * FROM t;"

    for i in range(len(blob_types)):
        print "ALTER TABLE t CHANGE COLUMN a a %s %s;" % (blob_types[i], nn)
        print "ALTER TABLE ti CHANGE COLUMN a a %s %s;" % (blob_types[i], nn)
    for i in range(len(blob_types)):
        print "ALTER TABLE t CHANGE COLUMN b b %s %s;" % (blob_types[i], nn)
        print "ALTER TABLE ti CHANGE COLUMN b b %s %s;" % (blob_types[i], nn)
    # compare tables
    print "let $diff_tables = test.t, test.ti;"
    print "source include/diff_tables.inc;"
    print "DROP TABLE t, ti;"
def gen_table(f, v, nn):
    t = "CREATE TABLE t ("
    if f != "":
        t += "%s, " % (f)
    if v != "":
        t += "%s, " % (v)
    t += "a TINYBLOB %s, b TINYBLOB %s);" % (nn, nn)
    return t
def insert_row(t):
    t = "INSERT INTO %s (a, b) VALUES (" % (t)
    l = random.randint(1, 32)
    s = ''.join(random.choice(string.ascii_lowercase + string.ascii_uppercase + string.digits) for x in range(l))
    t += "'%s'," % (s)
    l = random.randint(1, 260)
    s = ''.join(random.choice(string.ascii_lowercase + string.ascii_uppercase + string.digits) for x in range(l))
    t += "'%s');" % (s)
    return t

sys.exit(main())
