GithubHelp home page GithubHelp logo

pgsanity's People

Contributors

0mp avatar boechat107 avatar fernandahf avatar markdrago avatar mcandre avatar nitrocode avatar spenczar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pgsanity's Issues

ecpg error on new lines

on running:

from pgsanity.pgsanity import check_string
check_string(sql_command)

with a multi-line sql command I get:
*** Error in `ecpg': munmap_chunk(): invalid pointer: ***
I have found a workaround:

  sql_command = '\n'.join(
        filter(
            lambda line: line.strip() == "",
            sql_command.splitlines()
        )
    )

meaning I remove all empty lines.
I tried adding this snippet in: pgsanity.pgsanity.ecpg.check_syntax but it broke the tests:

  .............................F....F.FF..
======================================================================
FAIL: test_simple_failure (test.test_ecpg.TestEcpg)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/yonatan/github/pgsanity/test/test_ecpg.py", line 14, in test_simple_failure
    self.assertFalse(success)
AssertionError: True is not false

======================================================================
FAIL: test_check_invalid_string (test.test_pgsanity.TestPgSanity)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/yonatan/github/pgsanity/test/test_pgsanity.py", line 34, in test_check_invalid_string
    self.assertFalse(success)
AssertionError: True is not false

======================================================================
FAIL: test_check_invalid_file (test.test_pgsanity.TestPgSanityFiles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/yonatan/github/pgsanity/test/test_pgsanity.py", line 56, in test_check_invalid_file
    self.assertNotEqual(status_code, 0)
AssertionError: 0 == 0

======================================================================
FAIL: test_check_missing_semi (test.test_pgsanity.TestPgSanityFiles)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/yonatan/github/pgsanity/test/test_pgsanity.py", line 65, in test_check_missing_semi
    self.assertNotEqual(status_code, 0)
AssertionError: 0 == 0

----------------------------------------------------------------------
Ran 40 tests in 0.020s

FAILED (failures=4)

how can I fix this?

Python 2.6 support

I'm going to look into how much of argparse I'd need to pull in to make this work on python 2.6.

\gexec and other commands are flagged as errors

Good morning and thank you for your amazin job.
I'm working with some sql files and scripts, full of variables and \command, and pgsanity flag every command as an error, is there any way to flag them not as an error?
I'm running pgsanity on a docker container, i'm using ur suggestions to replace every variable with a sed -e but i don't wanna use it with just a backslash because it could be a typo.
Thank you.

Windows support?

pgsanity 0.2.9
ecpg 10.1
Python 2.7.13
Windows 10

echo select column1 alias2 asdf from table3>example.sql

When I run pgsanity example.sql I get Try "ecpg --help" for more information..
(Running ecpg -o - - outputs the same message Try "ecpg --help" for more information..)

Maybe Windows is not supported?

Adding pgsanity to FreeBSD ports

Hello!

First of all, thank you for pgsanity -> it's a really nice piece of software ๐Ÿ‘

I'm preparing a port of pgsanity for the FreeBSD ports at the moment. Would you find a minute please to create a 0.2.9 tag/release on GitHub so that it is easier to point to the latest version of pgsanity?

Thanks!

Profile python code to find slowdowns

I just killed a long running pgsanity process after 3 days.
Would the following backtrace indicate that it was still in the python code?

Traceback (most recent call last):
File "/usr/local/bin/pgsanity", line 9, in
load_entry_point('pgsanity==0.2.4', 'console_scripts', 'pgsanity')()
File "/usr/local/lib/python2.7/dist-packages/pgsanity/pgsanity.py", line 68, in main
return check_files(config.files)
File "/usr/local/lib/python2.7/dist-packages/pgsanity/pgsanity.py", line 63, in check_files
accumulator |= check_file(filename, show_filenames)
File "/usr/local/lib/python2.7/dist-packages/pgsanity/pgsanity.py", line 33, in check_file
prepped_file = prep_file(filelike)
File "/usr/local/lib/python2.7/dist-packages/pgsanity/pgsanity.py", line 21, in prep_file
prepped_sql = sqlprep.prepare_sql(raw_sql)
File "/usr/local/lib/python2.7/dist-packages/pgsanity/sqlprep.py", line 9, in prepare_sql
for (start, end, contents) in split_sql(sql):
File "/usr/local/lib/python2.7/dist-packages/pgsanity/sqlprep.py", line 52, in split_sql
results = get_next_occurence(sql[start:], bookends)
File "/usr/local/lib/python2.7/dist-packages/pgsanity/sqlprep.py", line 70, in get_next_occurence
index = haystack.find(needle)
KeyboardInterrupt

The SQL I was using was from https://bitbucket.org/voltagex/acorndata - this is a very large repo, but have a look at the sql file in the master branch. This is completely invalid SQL as far as Postgres is concerned; I was hoping to use pgsanity to show me how much needed to be changed to migrate from MSSQL to PostgreSQL.

Recurse over directories. `pgsanity .` like `jshint .`

In my big JavaScript projects, I like to run JSHint over all my .js code with:

$ jshint .

This automatically recurses over the current directory, or any other directory I pass in.

Could pgsanity please get this behavior as well?

As a workaround, I can do this:

find . -type f -name '*.psql' -exec pgsanity {} \;

But I'd prefer that pgsanity know to do this automatically.

Always print filenames with error messages

I often use Unix find to send many *.sql files individually to pgsanity:

$ find lib -name "*.sql" -exec pgsanity {} \;
line 7: ERROR: syntax error at or near ":db"
line 7: ERROR: syntax error at or near ":db"
line 7: ERROR: syntax error at or near ":db"

When I do this, pgsanity neglects to show the filename, making it hard to tell which files have the syntax errors. Please always show the filename, no matter how many files a pgsanity process is checking.

As a workaround, I'm using find lib -name "*.sql" \( -exec pgsanity {} \; -o -print \), but that prints the filenames after the warnings, rather than prefixing each line.

SQL-chunking algorithm may treat invalid SQL as a comment

At least on my own system, the following passes with exit-code 0:

SELECT '
-- this is not really a comment' AS c;
SELECT '
-- neither is this' AS c spam;

Despite the fact the above statements should actually fail with something like:

psql:shouldfail3.sql:4: ERROR:  syntax error at or near "spam"
LINE 2: -- neither is this' AS c spam;

No error is emitted because the statement is incorrectly prepared as:

EXEC SQL SELECT '
-- this is not really a comment' AS c;
SELECT '
-- neither is this' AS c spam;

I presume that ECPG just ignores everything after the first semicolon above, and therefore the invalid SQL in this example is simply not encountered.

I discovered this when I was trying to understand how the chunking algorithm did its thing, having wanted to grok it before trying to implement the ability to step over psql-commands.

More realistic instances similar to the above scenario likely exist under use of $$.

Short of fully integrating a tokenizer to get around this, I could probably just up the rock-paper-scissors game that's already going on in prepare_sql() with the if not in_block_comment business. Doing so should allow psql-stuff to be handled more readily.

What's your take?

Doesn't work with psql meta-commands & plpgsql syntax?

Hi! Noticed the following two issues when using pgsanity:

  1. pgsanity seems to throw an error on the first line in this SQL code:
\set start 1234
delete from x where y >= :start;
  1. Also doesn't seem to catch syntax errors in plpgsql code block:
DO $zzz$
dsafdsf
BEGIN
update test set id=4 where city='def';
END
$zzz$ LANGUAGE plpgsql;

No module named 'sqlprep'

When installing pgsanity either from github or using pip, I get the following error when running it:

Traceback (most recent call last):
File "/usr/bin/pgsanity", line 9, in
load_entry_point('pgsanity==0.2.5', 'console_scripts', 'pgsanity')()
File "/usr/lib/python3.4/site-packages/pkg_resources.py", line 351, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python3.4/site-packages/pkg_resources.py", line 2363, in load_entry_point
return ep.load()
File "/usr/lib/python3.4/site-packages/pkg_resources.py", line 2088, in load
entry = import(self.module_name, globals(),globals(), ['name'])
File "/usr/lib/python3.4/site-packages/pgsanity/pgsanity.py", line 9, in
import sqlprep
ImportError: No module named 'sqlprep'

I'm running Arch Linux and I have found out that the problem disappears when I manually call the script with python2. However this isn't very usable, at least for someone new to python.

Allow :colon variables

PostgreSQL uses a :colon syntax for parameterizing SQL commands with command line variables.

create-database.sql:

CREATE DATABASE :db;

Usage:

$ psql -f create-database.sql -v db=test

However, pgsanity/ecpg rejects these.

$ pgsanity create-database.sql
line 1: ERROR: syntax error at or near ":db"

Support for Python 3?

Mark,

Since we now live in a world where Python 2 is unsupported, and your utility is the #1 stackoverflow result when googling for Postgres SQL validators... have you given any thought to making this work on Python 3, perhaps using the six library or something?

We'd probably deploy this as part of our test process if it were ported.

I do not know how exactly download pgsanity

I am afraid that I do have a stupid elementary inquiry.
I am using Windows7 and do not know how to use it( like how to use linux sever ..etc).
I was wondering how ppl use pgsanity for Windows

OS:Windows7
Python:3.65

Documentation for pre-commit hook needs updating

The documentation for the pre-commit hook (added in #35) currently states that rev: v0.2.9 should be used. However, the pre-commit hook was added after the v0.2.9 tag, which means that pre-commit fails to install the hook (since .pre-commit-hooks.yaml doesn't exist in the repo for tag v0.2.9).

Therefore, the documentation needs to be updated to point to either a new tag for the most recent version of the code (e.g. rev: v0.2.10) or the latest commit SHA (i.e. rev: 5fb3ce7).

pgsanity reports error when .sql file is preceded with CREATE syntax

Just tried to verify the sanity of below sql files

BEGIN

CREATE SCHEMA transactional;

CREATE TABLE transactional.passenger (
  --primary key
  passenger_type_id      SERIAL,

  --datas
  passenger_type_name    VARCHAR, 
  is_active              BOOLEAN,
  additional_data        JSONB,

  --metadata
  sys_update_description VARCHAR,
  sys_update_timestamp   TIMESTAMPTZ,
  sys_update_name        VARCHAR,
  sys_creation_name      VARCHAR DEFAULT 'CIMAHI',
  sys_creation_timestamp TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,

  PRIMARY KEY (passenger_type_id),
  UNIQUE (passenger_type_name)
);

-- other create table, omitted for succinctness

COMMIT;

And below is the result from pgsanity: line 3: ERROR: syntax error at or near "CREATE". After commenting line 3, the file passed the verification (even without commenting the last COMMIT; line).

Is there an issue? I am using Python 2.7.6.

Many thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.