Skip to content

Instantly share code, notes, and snippets.

@Southclaws
Created August 22, 2018 12:53
Show Gist options
  • Save Southclaws/5eeb507805b66e44c1ea9830b344bb10 to your computer and use it in GitHub Desktop.
Save Southclaws/5eeb507805b66e44c1ea9830b344bb10 to your computer and use it in GitHub Desktop.

A quick proposal example for a preprocessor.

Input file "some-sql.pwn":

stock doSomeSQL() {
    @SQL(mysql_pqueryf, 10, 20) {
        SELECT *
        FROM table
        WHERE x=y
        AND a=b
        GROUP BY m
        HAVING n
        LIMIT %d
        OFFSET %d
    }
}

Output files:

stock doSomeSQL() {
    mysql_pqueryf_file("some-sql-2.sql", 10, 20);
    //     SELECT *
    //     FROM table
    //     WHERE x=y
    //     AND a=b
    //     GROUP BY m
    //     HAVING n
    //     LIMIT %d
    //     OFFSET %d
    // }
}

"some-sql-2.sql":

SELECT *
FROM table
WHERE x=y
AND a=b
GROUP BY m
HAVING n
LIMIT %d
OFFSET %d

In this example, the SQL type macro mysql_pqueryf results in the contained text being moved copied to a .sql file and the source code generating a call to a function. mysql_pqueryf is also defined to put this file in scriptfiles and it also takes n variadic arguments for formatting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment