Skip to content

Commit 9948bcd

Browse files
committed
Derive Type from pg_type.h and pg_range.h
1 parent 501b79b commit 9948bcd

File tree

8 files changed

+1124
-438
lines changed

8 files changed

+1124
-438
lines changed

Cargo.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ repository = "https://github.com/sfackler/rust-postgres"
88
documentation = "https://sfackler.github.io/rust-postgres/doc/v0.11.3/postgres"
99
readme = "README.md"
1010
keywords = ["database", "postgres", "postgresql", "sql"]
11-
build = "build.rs"
12-
include = ["src/*", "build.rs", "errcodes.txt", "Cargo.toml", "LICENSE", "README.md", "THIRD_PARTY"]
11+
build = "build/main.rs"
12+
include = ["src/*", "build/*", "Cargo.toml", "LICENSE", "README.md", "THIRD_PARTY"]
1313

1414
[lib]
1515
name = "postgres"
@@ -23,6 +23,7 @@ path = "tests/test.rs"
2323

2424
[build-dependencies]
2525
phf_codegen = "0.7"
26+
regex = "0.1"
2627

2728
[dependencies]
2829
bufstream = "0.1"
File renamed without changes.

build/main.rs

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
extern crate phf_codegen;
2+
extern crate regex;
3+
4+
use std::ascii::AsciiExt;
5+
6+
mod sqlstate;
7+
mod types;
8+
9+
fn main() {
10+
sqlstate::build();
11+
types::build();
12+
13+
println!("cargo:rerun-if-changed=build");
14+
}
15+
16+
fn snake_to_camel(s: &str) -> String {
17+
let mut out = String::new();
18+
19+
let mut upper = true;
20+
for ch in s.chars() {
21+
if ch == '_' {
22+
upper = true;
23+
} else {
24+
let ch = if upper {
25+
upper = false;
26+
ch.to_ascii_uppercase()
27+
} else {
28+
ch
29+
};
30+
out.push(ch);
31+
}
32+
}
33+
34+
out
35+
}

build/pg_range.h

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* pg_range.h
4+
* definition of the system "range" relation (pg_range)
5+
* along with the relation's initial contents.
6+
*
7+
*
8+
* Portions Copyright (c) 1996-2015, PostgreSQL Global Development Group
9+
* Portions Copyright (c) 1994, Regents of the University of California
10+
*
11+
* src/include/catalog/pg_range.h
12+
*
13+
* NOTES
14+
* the genbki.pl script reads this file and generates .bki
15+
* information from the DATA() statements.
16+
*
17+
* XXX do NOT break up DATA() statements into multiple lines!
18+
* the scripts are not as smart as you might think...
19+
*
20+
*-------------------------------------------------------------------------
21+
*/
22+
#ifndef PG_RANGE_H
23+
#define PG_RANGE_H
24+
25+
#include "catalog/genbki.h"
26+
27+
/* ----------------
28+
* pg_range definition. cpp turns this into
29+
* typedef struct FormData_pg_range
30+
* ----------------
31+
*/
32+
#define RangeRelationId 3541
33+
34+
CATALOG(pg_range,3541) BKI_WITHOUT_OIDS
35+
{
36+
Oid rngtypid; /* OID of owning range type */
37+
Oid rngsubtype; /* OID of range's element type (subtype) */
38+
Oid rngcollation; /* collation for this range type, or 0 */
39+
Oid rngsubopc; /* subtype's btree opclass */
40+
regproc rngcanonical; /* canonicalize range, or 0 */
41+
regproc rngsubdiff; /* subtype difference as a float8, or 0 */
42+
} FormData_pg_range;
43+
44+
/* ----------------
45+
* Form_pg_range corresponds to a pointer to a tuple with
46+
* the format of pg_range relation.
47+
* ----------------
48+
*/
49+
typedef FormData_pg_range *Form_pg_range;
50+
51+
/* ----------------
52+
* compiler constants for pg_range
53+
* ----------------
54+
*/
55+
#define Natts_pg_range 6
56+
#define Anum_pg_range_rngtypid 1
57+
#define Anum_pg_range_rngsubtype 2
58+
#define Anum_pg_range_rngcollation 3
59+
#define Anum_pg_range_rngsubopc 4
60+
#define Anum_pg_range_rngcanonical 5
61+
#define Anum_pg_range_rngsubdiff 6
62+
63+
64+
/* ----------------
65+
* initial contents of pg_range
66+
* ----------------
67+
*/
68+
DATA(insert ( 3904 23 0 1978 int4range_canonical int4range_subdiff));
69+
DATA(insert ( 3906 1700 0 3125 - numrange_subdiff));
70+
DATA(insert ( 3908 1114 0 3128 - tsrange_subdiff));
71+
DATA(insert ( 3910 1184 0 3127 - tstzrange_subdiff));
72+
DATA(insert ( 3912 1082 0 3122 daterange_canonical daterange_subdiff));
73+
DATA(insert ( 3926 20 0 3124 int8range_canonical int8range_subdiff));
74+
75+
76+
/*
77+
* prototypes for functions in pg_range.c
78+
*/
79+
80+
extern void RangeCreate(Oid rangeTypeOid, Oid rangeSubType, Oid rangeCollation,
81+
Oid rangeSubOpclass, RegProcedure rangeCanonical,
82+
RegProcedure rangeSubDiff);
83+
extern void RangeDelete(Oid rangeTypeOid);
84+
85+
#endif /* PG_RANGE_H */

0 commit comments

Comments
 (0)