Permalink
Browse files

add support for multibyte character(N)

  • Loading branch information...
1 parent 7fd23f9 commit 57b963ba6e93f929fa0a871e5487fb37d931ac14 @wg committed May 29, 2009
Showing with 12 additions and 7 deletions.
  1. +1 −1 Makefile
  2. +1 −1 README
  3. +1 −1 src/epgsql.app
  4. +1 −0 src/pgsql.erl
  5. +2 −1 src/pgsql_binary.erl
  6. +2 −2 test_data/test_schema.sql
  7. +4 −1 test_src/pgsql_tests.erl
View
@@ -1,5 +1,5 @@
NAME := epgsql
-VERSION := 1.1
+VERSION := 1.2
ERL := erl
ERLC := erlc
View
2 README
@@ -85,7 +85,7 @@ Erlang PostgreSQL Database Client
null = null
bool = true | false
- char = $A
+ char = $A | binary
intX = 1
floatX = 1.0
date = {Year, Month, Day}
View
@@ -1,6 +1,6 @@
{application, epgsql,
[{description, "PostgreSQL Client"},
- {vsn, "1.1"},
+ {vsn, "1.2"},
{modules, [pgsql, pgsql_binary, pgsql_connection, pgsql_fdatetime,
pgsql_idatetime, pgsql_sock, pgsql_types]},
{registered, []},
View
@@ -1,4 +1,5 @@
%%% Copyright (C) 2008 - Will Glozer. All rights reserved.
+
-module(pgsql).
-export([connect/2, connect/3, connect/4, close/1]).
View
@@ -10,12 +10,13 @@
encode(_Any, null) -> <<-1:?int32>>;
encode(bool, true) -> <<1:?int32, 1:1/big-signed-unit:8>>;
encode(bool, false) -> <<1:?int32, 0:1/big-signed-unit:8>>;
-encode(bpchar, C) -> <<1:?int32, C:1/big-unsigned-unit:8>>;
encode(int2, N) -> <<2:?int32, N:1/big-signed-unit:16>>;
encode(int4, N) -> <<4:?int32, N:1/big-signed-unit:32>>;
encode(int8, N) -> <<8:?int32, N:1/big-signed-unit:64>>;
encode(float4, N) -> <<4:?int32, N:1/big-float-unit:32>>;
encode(float8, N) -> <<8:?int32, N:1/big-float-unit:64>>;
+encode(bpchar, C) when is_integer(C) -> <<1:?int32, C:1/big-unsigned-unit:8>>;
+encode(bpchar, B) when is_binary(B) -> <<(byte_size(B)):?int32, B/binary>>;
encode(Type, B) when Type == time; Type == timetz -> ?datetime:encode(Type, B);
encode(Type, B) when Type == date; Type == timestamp -> ?datetime:encode(Type, B);
encode(Type, B) when Type == timestamptz; Type == interval -> ?datetime:encode(Type, B);
@@ -23,8 +23,8 @@ CREATE USER epgsql_test_md5 WITH PASSWORD 'epgsql_test_md5';
CREATE USER epgsql_test_cleartext WITH PASSWORD 'epgsql_test_cleartext';
CREATE USER epgsql_test_cert;
-CREATE DATABASE epgsql_test_db1;
-CREATE DATABASE epgsql_test_db2;
+CREATE DATABASE epgsql_test_db1 WITH ENCODING 'UTF8';
+CREATE DATABASE epgsql_test_db2 WITH ENCODING 'UTF8';
GRANT ALL ON DATABASE epgsql_test_db1 to epgsql_test;
GRANT ALL ON DATABASE epgsql_test_db1 to epgsql_test_md5;
View
@@ -367,7 +367,10 @@ numeric_type_test() ->
check_type(float8, "1.0", 1.0, [0.0, 1.23456789012345, -1.23456789012345]).
character_type_test() ->
- check_type(bpchar, "'A'", $A, [1, $1, 255], "c_char"),
+ Alpha = unicode:characters_to_binary([16#03B1]),
+ Ka = unicode:characters_to_binary([16#304B]),
+ One = unicode:characters_to_binary([16#10D360]),
+ check_type(bpchar, "'A'", $A, [1, $1, 16#7F, Alpha, Ka, One], "c_char"),
check_type(text, "'hi'", <<"hi">>, [<<"">>, <<"hi">>]),
check_type(varchar, "'hi'", <<"hi">>, [<<"">>, <<"hi">>]).

0 comments on commit 57b963b

Please sign in to comment.