神刀安全网

Fixing MySQL Bug#2: now MySQL makes toast!

Historical MySQL Bug#2 , opened 12 Sep 2002, states that MySQL Connector/J doesn’t make toast. It hasn’t been fixed for more than 14 years. I’ve finally created a patch for it. Fixing MySQL Bug#2: now MySQL makes toast!

First of all: why only fix this for MySQL Connector/J? We should make sure the server can do this for any implementation! With this fix, now MySQL server (starting with version 5.1) can make toast.

There are few dependences though (see assembled setup picture):

  1. Raspberry Pi  + PiFace shield
  2. Power switch relay (I’ve used an  IoT Power Relay )
  3. Toaster oven (any cheap mechanical model will work)

Patch:

  1. Make_toast binary, which is run on the Raspberry Pi and PiFace interface (you’ll need to install the PiFace library):
    #!/usr/bin/python importsys fromtime importsleep   if len(sys.argv) == 2 and sys.argv[1].isdigit():         toast_time = sys.argv[1] else:         toast_time = 10   print "Toasting for " + str(toast_time) + " seconds..."   importpifacedigitalioas p try:  p.init()  p.digital_write(7,1)  sleep(float(toast_time))  p.digital_write(7,0) except (KeyboardInterrupt, SystemExit):         print "Exiting and turning off heat..."  p.digital_write(7,0)         sys.exit(1)   print "Your toast is ready! Enjoy! " 

  2. MySQL UDF, based on  lib_mysqludf_sys , which calls the make_toast binary:
    char* make_toast(         UDF_INIT *initid ,      UDF_ARGS *args ,      char* result ,      unsigned long* length ,      char *is_null ,      char *error ){         FILE *pipe;         char line[1024];         unsigned long outlen, linelen;         char buf[40];           result = malloc(1);         outlen = 0;         sprintf(buf, "make_toast %s", args->args[0]);           pipe = popen(buf, "r");           while (fgets(line, sizeof(line), pipe) != NULL) {                 linelen = strlen(line);                 result = realloc(result, outlen + linelen);                 strncpy(result + outlen, line, linelen);                 outlen = outlen + linelen;         }           pclose(pipe);           if (!(*result) || result == NULL) {                 *is_null = 1;         } else {                 result[outlen] = 0x00;                 *length = strlen(result);         }           return result; } 

Usage:

mysql> call make_toast(300) 

Demo picture(thanks to my colleague Fernando Laudares Camargos ), actual video will follow:

Fixing MySQL Bug#2: now MySQL makes toast!

Implementation details:

Fixing MySQL Bug#2: now MySQL makes toast! Hardware/wiring

The relay switch powers on the toaster oven, and no modifications are needed to the oven itself. Make sure the timer is set to 30 min initially, the Raspberry Pi/MySQL UDF will now control how long you toast the bread.

The setup wiring is super easy (but may be counterintuitive if you are used to working with Arduino): use the output pins ( image ) and connect 5v on the PiFace to the “+” sign on the relay switch, and one of the pins to the “-” sign on the relay switch.

Software install

  1. Install PiFace software and Python bindings
  2. Test the make_toast python script
  3. Add user “mysql” to the spi and gpio groups so it can manipulate pins:
    # gpasswd -a mysql gpio # gpasswd -a mysql spi 

  4. Download the make toast UDF code  and run install.sh.
mysql> call make_toast(300); 

Enjoy your toast when it is hot!

转载本站任何文章请注明:转载至神刀安全网,谢谢神刀安全网 » Fixing MySQL Bug#2: now MySQL makes toast!

分享到:更多 ()

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
分享按钮