Skip to content

Instantly share code, notes, and snippets.

@webstrand
Created October 27, 2020 17:05
Show Gist options
  • Select an option

  • Save webstrand/104b7432c05a6a49cd4d210361a3bcd3 to your computer and use it in GitHub Desktop.

Select an option

Save webstrand/104b7432c05a6a49cd4d210361a3bcd3 to your computer and use it in GitHub Desktop.
For use with gpp
#!/usr/bin/gpp
#mode comment "/*" "*/"
/******************************************************************************/
/* ALL CODE GENERATED BY THIS FILE SHOULD RETAIN COMMENTS, NOTES, AND */
/* FORMATTING SO THAT IN THE FUTURE IF THE PREPROCESSOR IS LOST, THE CODE IS */
/* PRESERVED. */
/******************************************************************************/
#mode string QQQ "<<EOL\n" "\nEOL"
#define e(str) str
#define E(str)
/**
* Boilerplate trigger creation.
*/
#define CREATE_TRIGGER(TRIGGER_NAME, TRIGGER_COND, TRIGGER_BODY) <<EOL
DROP TRIGGER IF EXISTS TRIGGER_NAME;
DELIMITER $$
CREATE TRIGGER TRIGGER_NAME
TRIGGER_COND FOR EACH ROW
BEGIN
TRIGGER_BODY
END $$
DELIMITER /* preserve trailing space*/
EOL
/**
* Boilerplate table creator.
*/
#define CREATE_TABLE(TABLE_NAME,TABLE_PROPS,TABLE_ATTR) <<EOL
-- DROP TABLE IF EXISTS TABLE_NAME;
CREATE TABLE IF NOT EXISTS TABLE_NAME TABLE_PROPS ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
EOL
CREATE_TABLE(collations,(
collation_id int unsigned NOT NULL AUTO_INCREMENT
, creator varchar(60) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'Only stored for historical purposes, does not, and should not, affect permissions'
, creation_time datetime NOT NULL
, imported bit(1) NOT NULL DEFAULT 0
, PRIMARY KEY (collation_id)
));
CREATE_TRIGGER(some_table_insert,AFTER INSERT ON some_table,<<EOL
-- Documentation describing what this trigger is supposed to do.
UPDATE collations
SET creation_time = NOW()
WHERE collation_id = new.collation_id
EOL);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment