pg_query 0.2.9 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 2c434b8e00b40d06b104aae879be0538073ea63e
4
- data.tar.gz: 23f8b4c1bd7948b7686fa413aab4aad053bd0516
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZmUwNmJlMDhkZjA5MjVmYTIyMDIzNTk1NzUwNjdiMWM4YjllNzc1OQ==
5
+ data.tar.gz: !binary |-
6
+ ZGM4M2RmYTcxZDVhMjYwZDgwOTgwZjAwZGYzOWU3MTRkODYzMzBlNQ==
5
7
  SHA512:
6
- metadata.gz: 0ce5919e1e9d0908b0605e59dce2835c8d4f8b8083d174ffe0dc9e9fed33ec8d3abbde68440e924e8a69429a5657b256d17b087f4fb51c8b3815601a067e9c3c
7
- data.tar.gz: 9a0c19be11e104e7bb3f6bde9c64adb234ac19979ed031506081f199a1f5a6ff67a3026ee26a13a19dd6775b0d5d9e72a1618ce132594616ed4da79c786b7b5b
8
+ metadata.gz: !binary |-
9
+ ZDM2Nzg2MzVhNDEwMDkwOTg1ZDQ4YjdlMThhZmI4YTc4N2Y4YzMwOTViODA4
10
+ NmQ4MmZiN2Y2OTcyOWVjN2UzNTJkOWI1MDcxZTliMDBjYWZkNTExNmJhZWM0
11
+ ZTcxMzEzMjk3N2Y3MmY4NTkzZTFjMTdlOGUzNjA2YWI2ZjFiOGU=
12
+ data.tar.gz: !binary |-
13
+ ZjBkNTEwY2U3NDIwNjlmZmQzNjQ4YzRmOGJjMDJjNjExYTE5ZTAxYWMxN2Y1
14
+ NGYyMzQ0M2YwOWVlZjJhNzVmMWE3ZTcwMjliYTQ2OGRiMmVlOTVjM2JlNWYx
15
+ YTgzYTQwOTk2YTE0NWMyNDA1ZDIxZmJmNGMzZTdlYjkyNGMyODM=
@@ -30,6 +30,9 @@ $objs << File.join(File.dirname(__FILE__), "pg_query.o")
30
30
 
31
31
  $CFLAGS << " -I #{pgdir}/src/include"
32
32
 
33
+ # Similar to those used by PostgreSQL
34
+ $CFLAGS << " -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv"
35
+
33
36
  SYMFILE = File.join(File.dirname(__FILE__), "pg_query.sym")
34
37
  if RUBY_PLATFORM =~ /darwin/
35
38
  $DLDFLAGS << "-Wl,-exported_symbols_list #{SYMFILE}" unless defined?(::Rubinius)
@@ -37,4 +40,4 @@ else
37
40
  $DLDFLAGS << "-Wl,--retain-symbols-file=#{SYMFILE}"
38
41
  end
39
42
 
40
- create_makefile 'pg_query/pg_query'
43
+ create_makefile 'pg_query/pg_query'
@@ -14,6 +14,8 @@
14
14
 
15
15
  const char* progname = "pg_query";
16
16
 
17
+ void Init_pg_query(void);
18
+
17
19
  static VALUE new_parse_error(ErrorData* error)
18
20
  {
19
21
  VALUE cPgQuery, cParseError;
@@ -29,6 +31,7 @@ static VALUE new_parse_error(ErrorData* error)
29
31
  }
30
32
 
31
33
  #define STDERR_BUFFER_LEN 4096
34
+ //#define DEBUG
32
35
 
33
36
  static VALUE pg_query_raw_parse(VALUE self, VALUE input)
34
37
  {
@@ -38,8 +41,10 @@ static VALUE pg_query_raw_parse(VALUE self, VALUE input)
38
41
  VALUE result = Qnil;
39
42
  VALUE error = Qnil;
40
43
  char stderr_buffer[STDERR_BUFFER_LEN + 1] = {0};
44
+ #ifndef DEBUG
41
45
  int stderr_global;
42
46
  int stderr_pipe[2];
47
+ #endif
43
48
 
44
49
  ctx = AllocSetContextCreate(TopMemoryContext,
45
50
  "pg_query_raw_parse",
@@ -48,6 +53,7 @@ static VALUE pg_query_raw_parse(VALUE self, VALUE input)
48
53
  ALLOCSET_DEFAULT_MAXSIZE);
49
54
  MemoryContextSwitchTo(ctx);
50
55
 
56
+ #ifndef DEBUG
51
57
  // Setup pipe for stderr redirection
52
58
  if (pipe(stderr_pipe) != 0)
53
59
  rb_raise(rb_eIOError, "Failed to open pipe, too many open file descriptors");
@@ -58,6 +64,7 @@ static VALUE pg_query_raw_parse(VALUE self, VALUE input)
58
64
  stderr_global = dup(STDERR_FILENO);
59
65
  dup2(stderr_pipe[1], STDERR_FILENO);
60
66
  close(stderr_pipe[1]);
67
+ #endif
61
68
 
62
69
  // Parse it!
63
70
  PG_TRY();
@@ -70,9 +77,11 @@ static VALUE pg_query_raw_parse(VALUE self, VALUE input)
70
77
 
71
78
  str = nodeToJSONString(tree);
72
79
 
80
+ #ifndef DEBUG
73
81
  // Save stderr for result
74
82
  read(stderr_pipe[0], stderr_buffer, STDERR_BUFFER_LEN);
75
-
83
+ #endif
84
+
76
85
  result = rb_ary_new();
77
86
  rb_ary_push(result, rb_str_new2(str));
78
87
  rb_ary_push(result, rb_str_new2(stderr_buffer));
@@ -87,10 +96,14 @@ static VALUE pg_query_raw_parse(VALUE self, VALUE input)
87
96
  }
88
97
  PG_END_TRY();
89
98
 
90
- // Restore stderr, close pipe & return to previous PostgreSQL memory context
99
+ #ifndef DEBUG
100
+ // Restore stderr, close pipe
91
101
  dup2(stderr_global, STDERR_FILENO);
92
102
  close(stderr_pipe[0]);
93
103
  close(stderr_global);
104
+ #endif
105
+
106
+ // Return to previous PostgreSQL memory context
94
107
  MemoryContextSwitchTo(TopMemoryContext);
95
108
  MemoryContextDelete(ctx);
96
109
 
@@ -347,7 +360,7 @@ generate_normalized_query(pgssConstLocations *jstate, const char *query,
347
360
  return norm_query;
348
361
  }
349
362
 
350
- bool const_record_walker(Node *node, pgssConstLocations *jstate)
363
+ static bool const_record_walker(Node *node, pgssConstLocations *jstate)
351
364
  {
352
365
  bool result;
353
366
 
@@ -27,26 +27,26 @@ class PgQuery
27
27
  @parsetree = parsetree
28
28
  @warnings = warnings
29
29
  end
30
-
30
+
31
31
  def tables
32
32
  load_tables_and_aliases! if @tables.nil?
33
33
  @tables
34
34
  end
35
-
35
+
36
36
  def aliases
37
37
  load_tables_and_aliases! if @aliases.nil?
38
38
  @aliases
39
39
  end
40
-
40
+
41
41
  protected
42
42
  def load_tables_and_aliases!
43
43
  @tables = []
44
44
  @aliases = {}
45
-
45
+
46
46
  statements = @parsetree.dup
47
47
  from_clause_items = []
48
48
  where_clause_items = []
49
-
49
+
50
50
  loop do
51
51
  if statement = statements.shift
52
52
  case statement.keys[0]
@@ -63,22 +63,39 @@ protected
63
63
  statements << statement["SELECT"]["larg"] if statement["SELECT"]["larg"]
64
64
  statements << statement["SELECT"]["rarg"] if statement["SELECT"]["rarg"]
65
65
  end
66
- when "INSERT INTO", "UPDATE", "DELETE FROM", "VACUUM", "COPY", "ALTER TABLE"
66
+ when "INSERT INTO", "UPDATE", "DELETE FROM", "VACUUM", "COPY", "ALTER TABLE", "CREATESTMT", "INDEXSTMT", "RULESTMT", "CREATETRIGSTMT"
67
67
  from_clause_items << statement.values[0]["relation"]
68
- when "EXPLAIN"
69
- statements << statement["EXPLAIN"]["query"]
68
+ when "EXPLAIN", "VIEWSTMT"
69
+ statements << statement.values[0]["query"]
70
70
  when "CREATE TABLE AS"
71
71
  from_clause_items << statement["CREATE TABLE AS"]["into"]["INTOCLAUSE"]["rel"] rescue nil
72
- when "LOCK"
73
- from_clause_items += statement["LOCK"]["relations"]
72
+ when "LOCK", "TRUNCATE"
73
+ from_clause_items += statement.values[0]["relations"]
74
+ when "GRANTSTMT"
75
+ objects = statement["GRANTSTMT"]["objects"]
76
+ case statement["GRANTSTMT"]["objtype"]
77
+ when 0 # Column
78
+ # FIXME
79
+ when 1 # Table
80
+ from_clause_items += objects
81
+ when 2 # Sequence
82
+ # FIXME
83
+ end
74
84
  when "DROP"
75
- object_type = statement["DROP"]["removeType"]
76
- @tables += statement["DROP"]["objects"].map {|r| r.join('.') } if object_type == 26 # Table
85
+ objects = statement["DROP"]["objects"]
86
+ case statement["DROP"]["removeType"]
87
+ when 26 # Table
88
+ @tables += objects.map {|r| r.join('.') }
89
+ when 23 # Rule
90
+ @tables += objects.map {|r| r[0..-2].join('.') }
91
+ when 28 # Trigger
92
+ @tables += objects.map {|r| r[0..-2].join('.') }
93
+ end
77
94
  end
78
-
95
+
79
96
  where_clause_items << statement.values[0]["whereClause"] if !statement.empty? && statement.values[0]["whereClause"]
80
97
  end
81
-
98
+
82
99
  # Find subselects in WHERE clause
83
100
  if next_item = where_clause_items.shift
84
101
  case next_item.keys[0]
@@ -95,13 +112,13 @@ protected
95
112
  statements << next_item["SUBLINK"]["subselect"]
96
113
  end
97
114
  end
98
-
115
+
99
116
  break if where_clause_items.empty? && statements.empty?
100
117
  end
101
-
118
+
102
119
  loop do
103
120
  break unless next_item = from_clause_items.shift
104
-
121
+
105
122
  case next_item.keys[0]
106
123
  when "JOINEXPR"
107
124
  ["larg", "rarg"].each do |side|
@@ -116,7 +133,7 @@ protected
116
133
  @aliases[rangevar["alias"]["ALIAS"]["aliasname"]] = table if rangevar["alias"]
117
134
  end
118
135
  end
119
-
136
+
120
137
  @tables.uniq!
121
138
  end
122
- end
139
+ end
@@ -1,3 +1,3 @@
1
1
  class PgQuery
2
- VERSION = '0.2.9'
3
- end
2
+ VERSION = '0.3.0'
3
+ end
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_query
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lukas Fittl
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-30 00:00:00.000000000 Z
11
+ date: 2014-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
33
  version: '2.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: '2.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: json
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
47
  version: '1.8'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.8'
55
55
  description: Parses SQL queries using a copy of the PostgreSQL server query parser
@@ -78,12 +78,12 @@ require_paths:
78
78
  - lib
79
79
  required_ruby_version: !ruby/object:Gem::Requirement
80
80
  requirements:
81
- - - ">="
81
+ - - ! '>='
82
82
  - !ruby/object:Gem::Version
83
83
  version: '0'
84
84
  required_rubygems_version: !ruby/object:Gem::Requirement
85
85
  requirements:
86
- - - ">="
86
+ - - ! '>='
87
87
  - !ruby/object:Gem::Version
88
88
  version: '0'
89
89
  requirements: []