From 420272a729239bc15130e4f29c8f93caeeb044cf Mon Sep 17 00:00:00 2001 From: Adrian Salceanu Date: Thu, 22 Sep 2016 11:34:28 +0200 Subject: [PATCH 1/5] updates for Julia v0.5 compatibility (mostly related to Strings warnings) --- deps/build.jl | 2 +- src/dbi_impl.jl | 10 ++++------ src/libpq_common.jl | 2 +- src/types.jl | 22 +++++----------------- 4 files changed, 11 insertions(+), 25 deletions(-) diff --git a/deps/build.jl b/deps/build.jl index e75a4fb..3e8f08d 100644 --- a/deps/build.jl +++ b/deps/build.jl @@ -18,7 +18,7 @@ provides(Yum, "libpq5", libpq) provides(Yum, "postgresql-libs", libpq) provides(Pacman, "postgresql-libs", libpq) -@osx_only begin +@static if is_apple() using Homebrew provides(Homebrew.HB, "postgresql", libpq, os=:Darwin) end diff --git a/src/dbi_impl.jl b/src/dbi_impl.jl index 6c68149..bdbd31e 100644 --- a/src/dbi_impl.jl +++ b/src/dbi_impl.jl @@ -89,16 +89,15 @@ function checkerrclear(result::Ptr{PGresult}) end escapeliteral(db::PostgresDatabaseHandle, value) = value -escapeliteral(db::PostgresDatabaseHandle, value::AbstractString) = escapeliteral(db, bytestring(value)) -function escapeliteral(db::PostgresDatabaseHandle, value::Union{ASCIIString, UTF8String}) +function escapeliteral(db::PostgresDatabaseHandle, value::String) strptr = PQescapeLiteral(db.ptr, value, sizeof(value)) str = bytestring(strptr) PQfreemem(strptr) return str end -function escapeidentifier(db::PostgresDatabaseHandle, value::Union{ASCIIString, UTF8String}) +function escapeidentifier(db::PostgresDatabaseHandle, value::String) strptr = PQescapeIdentifier(db.ptr, value, sizeof(value)) str = bytestring(strptr) PQfreemem(strptr) @@ -115,8 +114,7 @@ function checkcopyreturnval(db::PostgresDatabaseHandle, returnval::Int32) end end -function copy_from(db::PostgresDatabaseHandle, table::AbstractString, - filename::AbstractString, format::AbstractString) +function copy_from(db::PostgresDatabaseHandle, table::AbstractString, filename::AbstractString, format::AbstractString) f = open(filename) try Base.run(db, string("COPY ", escapeidentifier(db, table), " FROM STDIN ", format)) @@ -138,7 +136,7 @@ function getparamtypes(result::Ptr{PGresult}) return @compat [pgtype(OID{Int(PQparamtype(result, i-1))}) for i = 1:nparams] end -LIBC = @windows ? "msvcrt.dll" : :libc +LIBC = @static is_windows() ? "msvcrt.dll" : :libc strlen(ptr::Ptr{UInt8}) = ccall((:strlen, LIBC), Csize_t, (Ptr{UInt8},), ptr) function getparams!(ptrs::Vector{Ptr{UInt8}}, params, types, sizes, lengths::Vector{Int32}, nulls) diff --git a/src/libpq_common.jl b/src/libpq_common.jl index 117808b..02fe849 100644 --- a/src/libpq_common.jl +++ b/src/libpq_common.jl @@ -1,5 +1,5 @@ macro c(ret_type, func, arg_types, lib) - local args_in = Any[ symbol(string('a',x)) for x in 1:length(arg_types.args) ] + local args_in = Any[ Symbol(string('a',x)) for x in 1:length(arg_types.args) ] quote $(esc(func))($(args_in...)) = ccall( ($(string(func)), $(Expr(:quote, lib)) ), $ret_type, $arg_types, $(args_in...) ) diff --git a/src/types.jl b/src/types.jl index 599d396..7d4f0f3 100644 --- a/src/types.jl +++ b/src/types.jl @@ -33,7 +33,7 @@ newpgtype(:int2, 21, (Int16,)) newpgtype(:float8, 701, (Float64,)) newpgtype(:float4, 700, (Float32,)) newpgtype(:bpchar, 1042, ()) -newpgtype(:varchar, 1043, (ASCIIString,UTF8String)) +newpgtype(:varchar, 1043, (String,String)) newpgtype(:text, 25, ()) newpgtype(:numeric, 1700, (BigInt,BigFloat)) newpgtype(:date, 1082, ()) @@ -50,8 +50,8 @@ newpgtype(:_int4, 1007, (Vector{Int32},)) newpgtype(:_int2, 1005, (Vector{Int16},)) newpgtype(:_float8, 1022, (Vector{Float64},)) newpgtype(:_float4, 1021, (Vector{Float32},)) -newpgtype(:_varchar, 1015, (Vector{ASCIIString}, Vector{UTF8String})) -newpgtype(:_text, 1009, (Vector{ASCIIString}, Vector{UTF8String})) +newpgtype(:_varchar, 1015, (Vector{String}, Vector{String})) +newpgtype(:_text, 1009, (Vector{String}, Vector{String})) typealias PGStringTypes Union{Type{PostgresType{:bpchar}}, @@ -151,10 +151,6 @@ function pgdata(::Type{PostgresType{:numeric}}, ptr::Ptr{UInt8}, data::Number) ptr = storestring!(ptr, string(data)) end -function pgdata(::PGStringTypes, ptr::Ptr{UInt8}, data::ByteString) - ptr = storestring!(ptr, data) -end - function pgdata(::PGStringTypes, ptr::Ptr{UInt8}, data::AbstractString) ptr = storestring!(ptr, bytestring(data)) end @@ -212,19 +208,11 @@ function pgdata(::Type{PostgresType{:_float4}}, ptr::Ptr{UInt8}, data::Vector{Fl ptr = storestring!(ptr, string("{", join(data, ','), "}")) end -function pgdata(::Type{PostgresType{:_varchar}}, ptr::Ptr{UInt8}, data::Vector{ASCIIString}) - ptr = storestring!(ptr, string("{", join(data, ','), "}")) -end - -function pgdata(::Type{PostgresType{:_varchar}}, ptr::Ptr{UInt8}, data::Vector{UTF8String}) - ptr = storestring!(ptr, string("{", join(data, ','), "}")) -end - -function pgdata(::Type{PostgresType{:_text}}, ptr::Ptr{UInt8}, data::Vector{ASCIIString}) +function pgdata(::Type{PostgresType{:_varchar}}, ptr::Ptr{UInt8}, data::Vector{String}) ptr = storestring!(ptr, string("{", join(data, ','), "}")) end -function pgdata(::Type{PostgresType{:_text}}, ptr::Ptr{UInt8}, data::Vector{UTF8String}) +function pgdata(::Type{PostgresType{:_text}}, ptr::Ptr{UInt8}, data::Vector{String}) ptr = storestring!(ptr, string("{", join(data, ','), "}")) end From bdc04cc12bf2b6e1d9491f1a4b390a5033c6f59b Mon Sep 17 00:00:00 2001 From: Adrian Salceanu Date: Thu, 22 Sep 2016 11:57:24 +0200 Subject: [PATCH 2/5] updates for Julia v0.5 compatibility (mostly related to Strings warnings) --- src/dbi_impl.jl | 24 ++++++++++++------------ test/connection.jl | 12 ++++++------ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/dbi_impl.jl b/src/dbi_impl.jl index bdbd31e..5038f21 100644 --- a/src/dbi_impl.jl +++ b/src/dbi_impl.jl @@ -10,7 +10,7 @@ function Base.connect(::Type{Postgres}, status = PQstatus(conn) if status != CONNECTION_OK - errmsg = bytestring(PQerrorMessage(conn)) + errmsg = unsafe_string(PQerrorMessage(conn)) PQfinish(conn) error(errmsg) end @@ -36,7 +36,7 @@ function Base.connect(::Type{Postgres}; conn = PQconnectdb(dsn) status = PQstatus(conn) if status != CONNECTION_OK - errmsg = bytestring(PQerrorMessage(conn)) + errmsg = unsafe_string(PQerrorMessage(conn)) PQfinish(conn) error(errmsg) end @@ -60,7 +60,7 @@ function DBI.errcode(db::PostgresDatabaseHandle) end function DBI.errstring(db::PostgresDatabaseHandle) - return bytestring(PQerrorMessage(db.ptr)) + return unsafe_string(PQerrorMessage(db.ptr)) end function DBI.errcode(res::PostgresResultHandle) @@ -68,7 +68,7 @@ function DBI.errcode(res::PostgresResultHandle) end function DBI.errstring(res::PostgresResultHandle) - return bytestring(PQresultErrorMessage(res.ptr)) + return unsafe_string(PQresultErrorMessage(res.ptr)) end DBI.errcode(stmt::PostgresStatementHandle) = DBI.errcode(stmt.result) @@ -79,8 +79,8 @@ function checkerrclear(result::Ptr{PGresult}) try if status == PGRES_FATAL_ERROR - statustext = bytestring(PQresStatus(status)) - errmsg = bytestring(PQresultErrorMessage(result)) + statustext = unsafe_string(PQresStatus(status)) + errmsg = unsafe_string(PQresultErrorMessage(result)) error("$statustext: $errmsg") end finally @@ -92,14 +92,14 @@ escapeliteral(db::PostgresDatabaseHandle, value) = value function escapeliteral(db::PostgresDatabaseHandle, value::String) strptr = PQescapeLiteral(db.ptr, value, sizeof(value)) - str = bytestring(strptr) + str = unsafe_string(strptr) PQfreemem(strptr) return str end function escapeidentifier(db::PostgresDatabaseHandle, value::String) strptr = PQescapeIdentifier(db.ptr, value, sizeof(value)) - str = bytestring(strptr) + str = unsafe_string(strptr) PQfreemem(strptr) return str end @@ -108,8 +108,8 @@ Base.run(db::PostgresDatabaseHandle, sql::AbstractString) = checkerrclear(PQexec function checkcopyreturnval(db::PostgresDatabaseHandle, returnval::Int32) if returnval == -1 - errcode = bytestring(DBI.errcode(db)) - errmsg = bytestring(DBI.errmsg(db)) + errcode = unsafe_string(DBI.errcode(db)) + errmsg = unsafe_string(DBI.errmsg(db)) error("Error $errcode: $errmsg") end end @@ -129,7 +129,7 @@ function copy_from(db::PostgresDatabaseHandle, table::AbstractString, filename:: return checkerrclear(PQgetResult(db.ptr)) end -hashsql(sql::AbstractString) = bytestring(string("__", hash(sql), "__")) +hashsql(sql::AbstractString) = unsafe_string(string("__", hash(sql), "__")) function getparamtypes(result::Ptr{PGresult}) nparams = PQnparams(result) @@ -291,7 +291,7 @@ end function DBI.fetchdf(result::PostgresResultHandle) df = DataFrame() for i = 0:(length(result.types)-1) - df[symbol(bytestring(PQfname(result.ptr, i)))] = unsafe_fetchcol_dataarray(result, i) + df[symbol(unsafe_string(PQfname(result.ptr, i)))] = unsafe_fetchcol_dataarray(result, i) end return df diff --git a/test/connection.jl b/test/connection.jl index 89e8162..74dd9d3 100644 --- a/test/connection.jl +++ b/test/connection.jl @@ -8,9 +8,9 @@ function test_connection() @test conn.status == PostgreSQL.CONNECTION_OK @test errcode(conn) == PostgreSQL.CONNECTION_OK @test !conn.closed - @test bytestring(libpq.PQdb(conn.ptr)) == "julia_test" - @test bytestring(libpq.PQuser(conn.ptr)) == "postgres" - @test bytestring(libpq.PQport(conn.ptr)) == "5432" + @test unsafe_string(libpq.PQdb(conn.ptr)) == "julia_test" + @test unsafe_string(libpq.PQuser(conn.ptr)) == "postgres" + @test unsafe_string(libpq.PQport(conn.ptr)) == "5432" disconnect(conn) @test conn.closed @@ -33,9 +33,9 @@ function test_connection() @test conn.status == PostgreSQL.CONNECTION_OK @test errcode(conn) == PostgreSQL.CONNECTION_OK @test !conn.closed - @test bytestring(libpq.PQdb(conn.ptr)) == "julia_test" - @test bytestring(libpq.PQuser(conn.ptr)) == "postgres" - @test bytestring(libpq.PQport(conn.ptr)) == "5432" + @test unsafe_string(libpq.PQdb(conn.ptr)) == "julia_test" + @test unsafe_string(libpq.PQuser(conn.ptr)) == "postgres" + @test unsafe_string(libpq.PQport(conn.ptr)) == "5432" disconnect(conn) @test conn.closed From 2c4ac457b1b7cec87fd420f8778af02d7844eed8 Mon Sep 17 00:00:00 2001 From: Adrian Salceanu Date: Thu, 22 Sep 2016 13:16:10 +0200 Subject: [PATCH 3/5] updates for Julia v0.5 compatibility (mostly related to Strings warnings) --- src/dbi_impl.jl | 2 +- src/types.jl | 58 ++++++++++++++++++++++++------------------------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/dbi_impl.jl b/src/dbi_impl.jl index 5038f21..b96e9a2 100644 --- a/src/dbi_impl.jl +++ b/src/dbi_impl.jl @@ -291,7 +291,7 @@ end function DBI.fetchdf(result::PostgresResultHandle) df = DataFrame() for i = 0:(length(result.types)-1) - df[symbol(unsafe_string(PQfname(result.ptr, i)))] = unsafe_fetchcol_dataarray(result, i) + df[Symbol(unsafe_string(PQfname(result.ptr, i)))] = unsafe_fetchcol_dataarray(result, i) end return df diff --git a/src/types.jl b/src/types.jl index 7d4f0f3..e98917e 100644 --- a/src/types.jl +++ b/src/types.jl @@ -74,54 +74,54 @@ function decode_bytea_hex(s::AbstractString) return hex2bytes(s[3:end]) end -jldata(::Type{PostgresType{:date}}, ptr::Ptr{UInt8}) = bytestring(ptr) +jldata(::Type{PostgresType{:date}}, ptr::Ptr{UInt8}) = unsafe_string(ptr) -jldata(::Type{PostgresType{:timestamp}}, ptr::Ptr{UInt8}) = bytestring(ptr) +jldata(::Type{PostgresType{:timestamp}}, ptr::Ptr{UInt8}) = unsafe_string(ptr) -jldata(::Type{PostgresType{:timestamptz}}, ptr::Ptr{UInt8}) = bytestring(ptr) +jldata(::Type{PostgresType{:timestamptz}}, ptr::Ptr{UInt8}) = unsafe_string(ptr) -jldata(::Type{PostgresType{:bool}}, ptr::Ptr{UInt8}) = bytestring(ptr) != "f" +jldata(::Type{PostgresType{:bool}}, ptr::Ptr{UInt8}) = unsafe_string(ptr) != "f" -jldata(::Type{PostgresType{:int8}}, ptr::Ptr{UInt8}) = parse(Int64, bytestring(ptr)) +jldata(::Type{PostgresType{:int8}}, ptr::Ptr{UInt8}) = parse(Int64, unsafe_string(ptr)) -jldata(::Type{PostgresType{:int4}}, ptr::Ptr{UInt8}) = parse(Int32, bytestring(ptr)) +jldata(::Type{PostgresType{:int4}}, ptr::Ptr{UInt8}) = parse(Int32, unsafe_string(ptr)) -jldata(::Type{PostgresType{:int2}}, ptr::Ptr{UInt8}) = parse(Int16, bytestring(ptr)) +jldata(::Type{PostgresType{:int2}}, ptr::Ptr{UInt8}) = parse(Int16, unsafe_string(ptr)) -jldata(::Type{PostgresType{:float8}}, ptr::Ptr{UInt8}) = parse(Float64, bytestring(ptr)) +jldata(::Type{PostgresType{:float8}}, ptr::Ptr{UInt8}) = parse(Float64, unsafe_string(ptr)) -jldata(::Type{PostgresType{:float4}}, ptr::Ptr{UInt8}) = parse(Float32, bytestring(ptr)) +jldata(::Type{PostgresType{:float4}}, ptr::Ptr{UInt8}) = parse(Float32, unsafe_string(ptr)) function jldata(::Type{PostgresType{:numeric}}, ptr::Ptr{UInt8}) - s = bytestring(ptr) + s = unsafe_string(ptr) return parse(search(s, '.') == 0 ? BigInt : BigFloat, s) end -jldata(::PGStringTypes, ptr::Ptr{UInt8}) = bytestring(ptr) +jldata(::PGStringTypes, ptr::Ptr{UInt8}) = unsafe_string(ptr) -jldata(::Type{PostgresType{:bytea}}, ptr::Ptr{UInt8}) = bytestring(ptr) |> decode_bytea_hex +jldata(::Type{PostgresType{:bytea}}, ptr::Ptr{UInt8}) = unsafe_string(ptr) |> decode_bytea_hex jldata(::Type{PostgresType{:unknown}}, ptr::Ptr{UInt8}) = Union{} -jldata(::Type{PostgresType{:json}}, ptr::Ptr{UInt8}) = JSON.parse(bytestring(ptr)) +jldata(::Type{PostgresType{:json}}, ptr::Ptr{UInt8}) = JSON.parse(unsafe_string(ptr)) -jldata(::Type{PostgresType{:jsonb}}, ptr::Ptr{UInt8}) = JSON.parse(bytestring(ptr)) +jldata(::Type{PostgresType{:jsonb}}, ptr::Ptr{UInt8}) = JSON.parse(unsafe_string(ptr)) -jldata(::Type{PostgresType{:_bool}}, ptr::Ptr{UInt8}) = map(x -> x != "f", split(bytestring(ptr)[2:end-1], ',')) +jldata(::Type{PostgresType{:_bool}}, ptr::Ptr{UInt8}) = map(x -> x != "f", split(unsafe_string(ptr)[2:end-1], ',')) -jldata(::Type{PostgresType{:_int8}}, ptr::Ptr{UInt8}) = map(x -> parse(Int64, x), split(bytestring(ptr)[2:end-1], ',')) +jldata(::Type{PostgresType{:_int8}}, ptr::Ptr{UInt8}) = map(x -> parse(Int64, x), split(unsafe_string(ptr)[2:end-1], ',')) -jldata(::Type{PostgresType{:_int4}}, ptr::Ptr{UInt8}) = map(x -> parse(Int32, x), split(bytestring(ptr)[2:end-1], ',')) +jldata(::Type{PostgresType{:_int4}}, ptr::Ptr{UInt8}) = map(x -> parse(Int32, x), split(unsafe_string(ptr)[2:end-1], ',')) -jldata(::Type{PostgresType{:_int2}}, ptr::Ptr{UInt8}) = map(x -> parse(Int16, x), split(bytestring(ptr)[2:end-1], ',')) +jldata(::Type{PostgresType{:_int2}}, ptr::Ptr{UInt8}) = map(x -> parse(Int16, x), split(unsafe_string(ptr)[2:end-1], ',')) -jldata(::Type{PostgresType{:_float8}}, ptr::Ptr{UInt8}) = map(x -> parse(Float64, x), split(bytestring(ptr)[2:end-1], ',')) +jldata(::Type{PostgresType{:_float8}}, ptr::Ptr{UInt8}) = map(x -> parse(Float64, x), split(unsafe_string(ptr)[2:end-1], ',')) -jldata(::Type{PostgresType{:_float4}}, ptr::Ptr{UInt8}) = map(x -> parse(Float32, x), split(bytestring(ptr)[2:end-1], ',')) +jldata(::Type{PostgresType{:_float4}}, ptr::Ptr{UInt8}) = map(x -> parse(Float32, x), split(unsafe_string(ptr)[2:end-1], ',')) -jldata(::Type{PostgresType{:_varchar}}, ptr::Ptr{UInt8}) = convert(Vector{AbstractString}, split(bytestring(ptr)[2:end-1], ',')) +jldata(::Type{PostgresType{:_varchar}}, ptr::Ptr{UInt8}) = convert(Vector{AbstractString}, split(unsafe_string(ptr)[2:end-1], ',')) -jldata(::Type{PostgresType{:_text}}, ptr::Ptr{UInt8}) = convert(Vector{AbstractString}, split(bytestring(ptr)[2:end-1], ',')) +jldata(::Type{PostgresType{:_text}}, ptr::Ptr{UInt8}) = convert(Vector{AbstractString}, split(unsafe_string(ptr)[2:end-1], ',')) function pgdata(::Type{PostgresType{:bool}}, ptr::Ptr{UInt8}, data::Bool) ptr = data ? storestring!(ptr, "TRUE") : storestring!(ptr, "FALSE") @@ -152,24 +152,24 @@ function pgdata(::Type{PostgresType{:numeric}}, ptr::Ptr{UInt8}, data::Number) end function pgdata(::PGStringTypes, ptr::Ptr{UInt8}, data::AbstractString) - ptr = storestring!(ptr, bytestring(data)) + ptr = storestring!(ptr, unsafe_string(data)) end function pgdata(::PostgresType{:date}, ptr::Ptr{UInt8}, data::AbstractString) - ptr = storestring!(ptr, bytestring(data)) + ptr = storestring!(ptr, unsafe_string(data)) ptr = Dates.DateFormat(ptr) end function pgdata(::PostgresType{:timestamp}, ptr::Ptr{UInt8}, data::AbstractString) - ptr = storestring!(ptr, bytestring(data)) + ptr = storestring!(ptr, unsafe_string(data)) end function pgdata(::PostgresType{:timestamptz}, ptr::Ptr{UInt8}, data::AbstractString) - ptr = storestring!(ptr, bytestring(data)) + ptr = storestring!(ptr, unsafe_string(data)) end function pgdata(::Type{PostgresType{:bytea}}, ptr::Ptr{UInt8}, data::Vector{UInt8}) - ptr = storestring!(ptr, bytestring("\\x", bytes2hex(data))) + ptr = storestring!(ptr, unsafe_string("\\x", bytes2hex(data))) end function pgdata(::Type{PostgresType{:unknown}}, ptr::Ptr{UInt8}, data) @@ -177,11 +177,11 @@ function pgdata(::Type{PostgresType{:unknown}}, ptr::Ptr{UInt8}, data) end function pgdata{T<:AbstractString}(::Type{PostgresType{:json}}, ptr::Ptr{UInt8}, data::Dict{T,Any}) - ptr = storestring!(ptr, bytestring(JSON.json(data))) + ptr = storestring!(ptr, unsafe_string(JSON.json(data))) end function pgdata{T<:AbstractString}(::Type{PostgresType{:jsonb}}, ptr::Ptr{UInt8}, data::Dict{T,Any}) - ptr = storestring!(ptr, bytestring(JSON.json(data))) + ptr = storestring!(ptr, unsafe_string(JSON.json(data))) end function pgdata(::Type{PostgresType{:_bool}}, ptr::Ptr{UInt8}, data::Vector{Bool}) From 6a20bfcbfd18dac7126261bc354291e021a521a2 Mon Sep 17 00:00:00 2001 From: Adrian Salceanu Date: Thu, 22 Sep 2016 14:11:42 +0200 Subject: [PATCH 4/5] updates for Julia v0.5 compatibility (mostly related to Strings warnings) --- src/types.jl | 58 ++++++++++++++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/src/types.jl b/src/types.jl index e98917e..7d4f0f3 100644 --- a/src/types.jl +++ b/src/types.jl @@ -74,54 +74,54 @@ function decode_bytea_hex(s::AbstractString) return hex2bytes(s[3:end]) end -jldata(::Type{PostgresType{:date}}, ptr::Ptr{UInt8}) = unsafe_string(ptr) +jldata(::Type{PostgresType{:date}}, ptr::Ptr{UInt8}) = bytestring(ptr) -jldata(::Type{PostgresType{:timestamp}}, ptr::Ptr{UInt8}) = unsafe_string(ptr) +jldata(::Type{PostgresType{:timestamp}}, ptr::Ptr{UInt8}) = bytestring(ptr) -jldata(::Type{PostgresType{:timestamptz}}, ptr::Ptr{UInt8}) = unsafe_string(ptr) +jldata(::Type{PostgresType{:timestamptz}}, ptr::Ptr{UInt8}) = bytestring(ptr) -jldata(::Type{PostgresType{:bool}}, ptr::Ptr{UInt8}) = unsafe_string(ptr) != "f" +jldata(::Type{PostgresType{:bool}}, ptr::Ptr{UInt8}) = bytestring(ptr) != "f" -jldata(::Type{PostgresType{:int8}}, ptr::Ptr{UInt8}) = parse(Int64, unsafe_string(ptr)) +jldata(::Type{PostgresType{:int8}}, ptr::Ptr{UInt8}) = parse(Int64, bytestring(ptr)) -jldata(::Type{PostgresType{:int4}}, ptr::Ptr{UInt8}) = parse(Int32, unsafe_string(ptr)) +jldata(::Type{PostgresType{:int4}}, ptr::Ptr{UInt8}) = parse(Int32, bytestring(ptr)) -jldata(::Type{PostgresType{:int2}}, ptr::Ptr{UInt8}) = parse(Int16, unsafe_string(ptr)) +jldata(::Type{PostgresType{:int2}}, ptr::Ptr{UInt8}) = parse(Int16, bytestring(ptr)) -jldata(::Type{PostgresType{:float8}}, ptr::Ptr{UInt8}) = parse(Float64, unsafe_string(ptr)) +jldata(::Type{PostgresType{:float8}}, ptr::Ptr{UInt8}) = parse(Float64, bytestring(ptr)) -jldata(::Type{PostgresType{:float4}}, ptr::Ptr{UInt8}) = parse(Float32, unsafe_string(ptr)) +jldata(::Type{PostgresType{:float4}}, ptr::Ptr{UInt8}) = parse(Float32, bytestring(ptr)) function jldata(::Type{PostgresType{:numeric}}, ptr::Ptr{UInt8}) - s = unsafe_string(ptr) + s = bytestring(ptr) return parse(search(s, '.') == 0 ? BigInt : BigFloat, s) end -jldata(::PGStringTypes, ptr::Ptr{UInt8}) = unsafe_string(ptr) +jldata(::PGStringTypes, ptr::Ptr{UInt8}) = bytestring(ptr) -jldata(::Type{PostgresType{:bytea}}, ptr::Ptr{UInt8}) = unsafe_string(ptr) |> decode_bytea_hex +jldata(::Type{PostgresType{:bytea}}, ptr::Ptr{UInt8}) = bytestring(ptr) |> decode_bytea_hex jldata(::Type{PostgresType{:unknown}}, ptr::Ptr{UInt8}) = Union{} -jldata(::Type{PostgresType{:json}}, ptr::Ptr{UInt8}) = JSON.parse(unsafe_string(ptr)) +jldata(::Type{PostgresType{:json}}, ptr::Ptr{UInt8}) = JSON.parse(bytestring(ptr)) -jldata(::Type{PostgresType{:jsonb}}, ptr::Ptr{UInt8}) = JSON.parse(unsafe_string(ptr)) +jldata(::Type{PostgresType{:jsonb}}, ptr::Ptr{UInt8}) = JSON.parse(bytestring(ptr)) -jldata(::Type{PostgresType{:_bool}}, ptr::Ptr{UInt8}) = map(x -> x != "f", split(unsafe_string(ptr)[2:end-1], ',')) +jldata(::Type{PostgresType{:_bool}}, ptr::Ptr{UInt8}) = map(x -> x != "f", split(bytestring(ptr)[2:end-1], ',')) -jldata(::Type{PostgresType{:_int8}}, ptr::Ptr{UInt8}) = map(x -> parse(Int64, x), split(unsafe_string(ptr)[2:end-1], ',')) +jldata(::Type{PostgresType{:_int8}}, ptr::Ptr{UInt8}) = map(x -> parse(Int64, x), split(bytestring(ptr)[2:end-1], ',')) -jldata(::Type{PostgresType{:_int4}}, ptr::Ptr{UInt8}) = map(x -> parse(Int32, x), split(unsafe_string(ptr)[2:end-1], ',')) +jldata(::Type{PostgresType{:_int4}}, ptr::Ptr{UInt8}) = map(x -> parse(Int32, x), split(bytestring(ptr)[2:end-1], ',')) -jldata(::Type{PostgresType{:_int2}}, ptr::Ptr{UInt8}) = map(x -> parse(Int16, x), split(unsafe_string(ptr)[2:end-1], ',')) +jldata(::Type{PostgresType{:_int2}}, ptr::Ptr{UInt8}) = map(x -> parse(Int16, x), split(bytestring(ptr)[2:end-1], ',')) -jldata(::Type{PostgresType{:_float8}}, ptr::Ptr{UInt8}) = map(x -> parse(Float64, x), split(unsafe_string(ptr)[2:end-1], ',')) +jldata(::Type{PostgresType{:_float8}}, ptr::Ptr{UInt8}) = map(x -> parse(Float64, x), split(bytestring(ptr)[2:end-1], ',')) -jldata(::Type{PostgresType{:_float4}}, ptr::Ptr{UInt8}) = map(x -> parse(Float32, x), split(unsafe_string(ptr)[2:end-1], ',')) +jldata(::Type{PostgresType{:_float4}}, ptr::Ptr{UInt8}) = map(x -> parse(Float32, x), split(bytestring(ptr)[2:end-1], ',')) -jldata(::Type{PostgresType{:_varchar}}, ptr::Ptr{UInt8}) = convert(Vector{AbstractString}, split(unsafe_string(ptr)[2:end-1], ',')) +jldata(::Type{PostgresType{:_varchar}}, ptr::Ptr{UInt8}) = convert(Vector{AbstractString}, split(bytestring(ptr)[2:end-1], ',')) -jldata(::Type{PostgresType{:_text}}, ptr::Ptr{UInt8}) = convert(Vector{AbstractString}, split(unsafe_string(ptr)[2:end-1], ',')) +jldata(::Type{PostgresType{:_text}}, ptr::Ptr{UInt8}) = convert(Vector{AbstractString}, split(bytestring(ptr)[2:end-1], ',')) function pgdata(::Type{PostgresType{:bool}}, ptr::Ptr{UInt8}, data::Bool) ptr = data ? storestring!(ptr, "TRUE") : storestring!(ptr, "FALSE") @@ -152,24 +152,24 @@ function pgdata(::Type{PostgresType{:numeric}}, ptr::Ptr{UInt8}, data::Number) end function pgdata(::PGStringTypes, ptr::Ptr{UInt8}, data::AbstractString) - ptr = storestring!(ptr, unsafe_string(data)) + ptr = storestring!(ptr, bytestring(data)) end function pgdata(::PostgresType{:date}, ptr::Ptr{UInt8}, data::AbstractString) - ptr = storestring!(ptr, unsafe_string(data)) + ptr = storestring!(ptr, bytestring(data)) ptr = Dates.DateFormat(ptr) end function pgdata(::PostgresType{:timestamp}, ptr::Ptr{UInt8}, data::AbstractString) - ptr = storestring!(ptr, unsafe_string(data)) + ptr = storestring!(ptr, bytestring(data)) end function pgdata(::PostgresType{:timestamptz}, ptr::Ptr{UInt8}, data::AbstractString) - ptr = storestring!(ptr, unsafe_string(data)) + ptr = storestring!(ptr, bytestring(data)) end function pgdata(::Type{PostgresType{:bytea}}, ptr::Ptr{UInt8}, data::Vector{UInt8}) - ptr = storestring!(ptr, unsafe_string("\\x", bytes2hex(data))) + ptr = storestring!(ptr, bytestring("\\x", bytes2hex(data))) end function pgdata(::Type{PostgresType{:unknown}}, ptr::Ptr{UInt8}, data) @@ -177,11 +177,11 @@ function pgdata(::Type{PostgresType{:unknown}}, ptr::Ptr{UInt8}, data) end function pgdata{T<:AbstractString}(::Type{PostgresType{:json}}, ptr::Ptr{UInt8}, data::Dict{T,Any}) - ptr = storestring!(ptr, unsafe_string(JSON.json(data))) + ptr = storestring!(ptr, bytestring(JSON.json(data))) end function pgdata{T<:AbstractString}(::Type{PostgresType{:jsonb}}, ptr::Ptr{UInt8}, data::Dict{T,Any}) - ptr = storestring!(ptr, unsafe_string(JSON.json(data))) + ptr = storestring!(ptr, bytestring(JSON.json(data))) end function pgdata(::Type{PostgresType{:_bool}}, ptr::Ptr{UInt8}, data::Vector{Bool}) From 0fa9e58ad64b1856950f024f4c4a95dfaa4b2331 Mon Sep 17 00:00:00 2001 From: Adrian Salceanu Date: Thu, 22 Sep 2016 14:16:34 +0200 Subject: [PATCH 5/5] updates for Julia v0.5 compatibility (mostly related to Strings warnings) --- src/dbi_impl.jl | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/dbi_impl.jl b/src/dbi_impl.jl index b96e9a2..47f09a1 100644 --- a/src/dbi_impl.jl +++ b/src/dbi_impl.jl @@ -10,7 +10,7 @@ function Base.connect(::Type{Postgres}, status = PQstatus(conn) if status != CONNECTION_OK - errmsg = unsafe_string(PQerrorMessage(conn)) + errmsg = bytestring(PQerrorMessage(conn)) PQfinish(conn) error(errmsg) end @@ -36,7 +36,7 @@ function Base.connect(::Type{Postgres}; conn = PQconnectdb(dsn) status = PQstatus(conn) if status != CONNECTION_OK - errmsg = unsafe_string(PQerrorMessage(conn)) + errmsg = bytestring(PQerrorMessage(conn)) PQfinish(conn) error(errmsg) end @@ -60,7 +60,7 @@ function DBI.errcode(db::PostgresDatabaseHandle) end function DBI.errstring(db::PostgresDatabaseHandle) - return unsafe_string(PQerrorMessage(db.ptr)) + return bytestring(PQerrorMessage(db.ptr)) end function DBI.errcode(res::PostgresResultHandle) @@ -68,7 +68,7 @@ function DBI.errcode(res::PostgresResultHandle) end function DBI.errstring(res::PostgresResultHandle) - return unsafe_string(PQresultErrorMessage(res.ptr)) + return bytestring(PQresultErrorMessage(res.ptr)) end DBI.errcode(stmt::PostgresStatementHandle) = DBI.errcode(stmt.result) @@ -79,8 +79,8 @@ function checkerrclear(result::Ptr{PGresult}) try if status == PGRES_FATAL_ERROR - statustext = unsafe_string(PQresStatus(status)) - errmsg = unsafe_string(PQresultErrorMessage(result)) + statustext = bytestring(PQresStatus(status)) + errmsg = bytestring(PQresultErrorMessage(result)) error("$statustext: $errmsg") end finally @@ -92,14 +92,14 @@ escapeliteral(db::PostgresDatabaseHandle, value) = value function escapeliteral(db::PostgresDatabaseHandle, value::String) strptr = PQescapeLiteral(db.ptr, value, sizeof(value)) - str = unsafe_string(strptr) + str = bytestring(strptr) PQfreemem(strptr) return str end function escapeidentifier(db::PostgresDatabaseHandle, value::String) strptr = PQescapeIdentifier(db.ptr, value, sizeof(value)) - str = unsafe_string(strptr) + str = bytestring(strptr) PQfreemem(strptr) return str end @@ -108,8 +108,8 @@ Base.run(db::PostgresDatabaseHandle, sql::AbstractString) = checkerrclear(PQexec function checkcopyreturnval(db::PostgresDatabaseHandle, returnval::Int32) if returnval == -1 - errcode = unsafe_string(DBI.errcode(db)) - errmsg = unsafe_string(DBI.errmsg(db)) + errcode = bytestring(DBI.errcode(db)) + errmsg = bytestring(DBI.errmsg(db)) error("Error $errcode: $errmsg") end end @@ -129,7 +129,7 @@ function copy_from(db::PostgresDatabaseHandle, table::AbstractString, filename:: return checkerrclear(PQgetResult(db.ptr)) end -hashsql(sql::AbstractString) = unsafe_string(string("__", hash(sql), "__")) +hashsql(sql::AbstractString) = bytestring(string("__", hash(sql), "__")) function getparamtypes(result::Ptr{PGresult}) nparams = PQnparams(result) @@ -291,7 +291,7 @@ end function DBI.fetchdf(result::PostgresResultHandle) df = DataFrame() for i = 0:(length(result.types)-1) - df[Symbol(unsafe_string(PQfname(result.ptr, i)))] = unsafe_fetchcol_dataarray(result, i) + df[Symbol(bytestring(PQfname(result.ptr, i)))] = unsafe_fetchcol_dataarray(result, i) end return df