-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Follow ltree's example by prepending a version and using the pg_msg functions. Add tests. A little hinky to use `\copy` to write to a file and then read it back in, but it is the only way I could figure out to test the receive function, which binary COPY FROM uses. Increment to v0.32.0, update the copyright date, and test on Postgres 15.
- Loading branch information
Showing
12 changed files
with
133 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,5 @@ regression.out | |
/semver-* | ||
/latest-changes.md | ||
/src/*.bc | ||
/semver_binary_copy.bin | ||
/.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
"name": "semver", | ||
"abstract": "A semantic version data type", | ||
"description": "A Postgres data type for the Semantic Version format with support for btree and hash indexing.", | ||
"version": "0.31.2", | ||
"version": "0.32.0", | ||
"maintainer": [ | ||
"David E. Wheeler <[email protected]>", | ||
"Sam Vilain <[email protected]>", | ||
|
@@ -15,7 +15,7 @@ | |
"abstract": "A semantic version data type", | ||
"file": "sql/semver.sql", | ||
"docfile": "doc/semver.mmd", | ||
"version": "0.31.2" | ||
"version": "0.32.0" | ||
} | ||
}, | ||
"prereqs": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# semver extension | ||
comment = 'Semantic version data type' | ||
default_version = '0.31.2' | ||
default_version = '0.32.0' | ||
module_pathname = '$libdir/semver' | ||
relocatable = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
CREATE OR REPLACE FUNCTION semver_recv(internal) | ||
RETURNS semver | ||
AS 'semver' | ||
LANGUAGE C STRICT IMMUTABLE; | ||
|
||
CREATE OR REPLACE FUNCTION semver_send(semver) | ||
RETURNS bytea | ||
AS 'semver' | ||
LANGUAGE C STRICT IMMUTABLE; | ||
|
||
ALTER TYPE semver SET | ||
RECEIVE = semver_recv, | ||
SEND = semver_send; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
* + Tom Davis <[email protected]> | ||
* + Xavier Caron <[email protected]> | ||
* | ||
* Copyright 2010-2021 The pg-semver Maintainers. This program is Free | ||
* Copyright 2010-2022 The pg-semver Maintainers. This program is Free | ||
* Software; see the LICENSE file for the license conditions. | ||
*/ | ||
|
||
|
@@ -343,42 +343,58 @@ semver_out(PG_FUNCTION_ARGS) { | |
PG_RETURN_CSTRING(result); | ||
} | ||
|
||
PG_FUNCTION_INFO_V1(semver_recv); | ||
/* | ||
* semver type send function | ||
* | ||
* The type is sent as text in binary mode, so this is almost the same as the | ||
* output function, but it's prefixed with a version number so we can change the | ||
* binary format sent in future if necessary. For now, only version 1 is | ||
* supported. | ||
*/ | ||
PG_FUNCTION_INFO_V1(semver_send); | ||
Datum | ||
semver_recv(PG_FUNCTION_ARGS) { | ||
StringInfo buf = (StringInfo) PG_GETARG_POINTER(0); | ||
const int len = buf->len - buf->cursor; | ||
char* str = palloc(len + 1); | ||
bool bad = false; | ||
semver* result; | ||
|
||
pq_copymsgbytes(buf, str, len); | ||
str[len] = 0; | ||
|
||
result = parse_semver(str, false, true, &bad); | ||
semver_send(PG_FUNCTION_ARGS) { | ||
semver *result = PG_GETARG_SEMVER_P(0); | ||
char *str = emit_semver(result); | ||
char version = 1; | ||
|
||
StringInfoData buf; | ||
pq_begintypsend(&buf); | ||
pq_sendbyte(&buf, version); | ||
pq_sendtext(&buf, str, strlen(str)); | ||
pfree(str); | ||
if (!result) PG_RETURN_NULL(); | ||
|
||
PG_RETURN_POINTER(result); | ||
PG_RETURN_BYTEA_P(pq_endtypsend(&buf)); | ||
} | ||
|
||
PG_FUNCTION_INFO_V1(semver_send); | ||
/* | ||
* semver type recv function | ||
* | ||
* The type is sent as text in binary mode, so this is almost the same as the | ||
* input function, but it's prefixed with a version number so we can change the | ||
* binary format sent in future if necessary. For now, only version 1 is | ||
* supported. | ||
*/ | ||
PG_FUNCTION_INFO_V1(semver_recv); | ||
Datum | ||
semver_send(PG_FUNCTION_ARGS) { | ||
bytea* output; | ||
|
||
semver* version = PG_GETARG_SEMVER_P(0); | ||
char* str = emit_semver(version); | ||
int len = strlen(str); | ||
|
||
output = palloc(VARHDRSZ + len); | ||
|
||
memcpy(VARDATA(output), str, len); | ||
SET_VARSIZE(output, VARHDRSZ + len); | ||
semver_recv(PG_FUNCTION_ARGS) { | ||
StringInfo buf = (StringInfo) PG_GETARG_POINTER(0); | ||
char version = pq_getmsgbyte(buf); | ||
char *str; | ||
int nbytes; | ||
bool bad = false; | ||
semver *result; | ||
|
||
if (version != 1) { | ||
elog(ERROR, "unsupported semver type version number %d", version); | ||
} | ||
|
||
str = pq_getmsgtext(buf, buf->len - buf->cursor, &nbytes); | ||
result = parse_semver(str, false, true, &bad); | ||
pfree(str); | ||
|
||
PG_RETURN_BYTEA_P(output); | ||
if (!result) PG_RETURN_NULL(); | ||
PG_RETURN_POINTER(result); | ||
} | ||
|
||
PG_FUNCTION_INFO_V1(text_to_semver); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters