#include <stdio.h>
#include <stdlib.h>
#include "sqlglot.h"
int main(void) {
printf("sqlglot-rust version: %s\n\n", sqlglot_version());
const char *sql = "SELECT NOW(), IFNULL(a, b) FROM t LIMIT 10";
printf("Input (MySQL): %s\n", sql);
char *pg = sqlglot_transpile(sql, "mysql", "postgres");
if (pg) {
printf("Output (Postgres): %s\n", pg);
sqlglot_free(pg);
}
char *tsql = sqlglot_transpile(sql, "mysql", "tsql");
if (tsql) {
printf("Output (T-SQL): %s\n\n", tsql);
sqlglot_free(tsql);
}
const char *simple = "SELECT a, b FROM users WHERE active = true";
char *json = sqlglot_parse(simple, "ansi");
if (json) {
printf("AST JSON (first 200 chars):\n %.200s...\n\n", json);
}
if (json) {
char *regenerated = sqlglot_generate(json, "postgres");
if (regenerated) {
printf("Regenerated (Postgres): %s\n", regenerated);
sqlglot_free(regenerated);
}
sqlglot_free(json);
}
char *bad = sqlglot_parse("NOT VALID SQL ???", "ansi");
if (bad == NULL) {
printf("\nGraceful NULL on parse error — as expected.\n");
} else {
sqlglot_free(bad);
}
return 0;
}