fix

fix

fix
This commit is contained in:
feng lv 2021-03-05 15:44:06 +00:00
parent 1438fd20cb
commit d208013161
3 changed files with 56 additions and 3 deletions

View File

@ -155,9 +155,26 @@ int mainEntryClickHouseFormat(int argc, char ** argv)
std::cout << "\n;\n";
std::cout << std::endl;
}
do
{
/// skip spaces to avoid throw exception after last query
while (pos != end && std::isspace(*pos))
++pos;
/// for skip comment after the last query and to not throw exception
if (end - pos > 2 && *pos == '-' && *(pos + 1) == '-')
{
pos += 2;
/// skip until the end of the line
while (pos != end && *pos != '\n')
++pos;
}
/// need to parse next sql
else
break;
} while (pos != end);
} while (multiple && pos != end);
}
}

View File

@ -0,0 +1,25 @@
SELECT 1
;
SELECT 1
UNION ALL
(
SELECT 1
UNION DISTINCT
SELECT 1
)
;
SELECT 1
;
SELECT 1
UNION ALL
(
SELECT 1
UNION DISTINCT
SELECT 1
)
;
OK

View File

@ -0,0 +1,11 @@
#!/usr/bin/env bash
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# shellcheck source=../shell_config.sh
. "$CURDIR"/../shell_config.sh
echo "select 1; select 1 union all (select 1 union distinct select 1); " | $CLICKHOUSE_FORMAT -n;
echo "select 1; select 1 union all (select 1 union distinct select 1); -- comment " | $CLICKHOUSE_FORMAT -n;
echo "insert into t values (1); " | $CLICKHOUSE_FORMAT -n 2>&1 \ | grep -F -q "Code: 1004" && echo 'OK' || echo 'FAIL'