Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed deprecated functions (bytestring, is, symbol) #48

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ end
## Requirements

* [DBI.jl](https://github.com/JuliaDB/DBI.jl)
* [DataFrames.jl](https://github.com/JuliaStats/DataFrames.jl) >= v0.5.7
* [DataArrays.jl](https://github.com/JuliaStats/DataArrays.jl) >= v0.1.2
* [DataFrames.jl](https://github.com/JuliaStats/DataFrames.jl) >= v0.8.0
* [DataArrays.jl](https://github.com/JuliaStats/DataArrays.jl) >= v0.3.4 for Julia 0.4, v0.3.8 for Julia 0.5
* libpq shared library (comes with a standard PostgreSQL client installation)
* Julia 0.4

Expand Down
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
julia 0.4
DataFrames 0.6.6
DataFrames 0.8.0
DataArrays
Compat
JSON
Expand Down
3 changes: 2 additions & 1 deletion deps/build.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BinDeps
import Compat: @static, is_apple

@BinDeps.setup

Expand All @@ -18,7 +19,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
Expand Down
47 changes: 23 additions & 24 deletions src/dbi_impl.jl
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import Compat: Libc, @compat
import Compat: Libc, @static, is_windows

function Base.connect(::Type{Postgres},
host::AbstractString="",
user::AbstractString="",
passwd::AbstractString="",
db::AbstractString="",
host::AbstractString,
user::AbstractString,
passwd::AbstractString,
db::AbstractString,
port::AbstractString="")
conn = PQsetdbLogin(host, port, C_NULL, C_NULL, db, user, passwd)
status = PQstatus(conn)

if status != CONNECTION_OK
errmsg = bytestring(PQerrorMessage(conn))
errmsg = unsafe_string(PQerrorMessage(conn))
PQfinish(conn)
error(errmsg)
end
Expand All @@ -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
Expand All @@ -60,15 +60,15 @@ 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)
return PQresultStatus(res.ptr)
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)
Expand All @@ -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
Expand All @@ -89,18 +89,17 @@ 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::AbstractString)
strptr = PQescapeLiteral(db.ptr, value, sizeof(value))
str = bytestring(strptr)
str = unsafe_string(strptr)
PQfreemem(strptr)
return str
end

function escapeidentifier(db::PostgresDatabaseHandle, value::Union{ASCIIString, UTF8String})
function escapeidentifier(db::PostgresDatabaseHandle, value::AbstractString)
strptr = PQescapeIdentifier(db.ptr, value, sizeof(value))
str = bytestring(strptr)
str = unsafe_string(strptr)
PQfreemem(strptr)
return str
end
Expand All @@ -109,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
Expand All @@ -131,14 +130,14 @@ function copy_from(db::PostgresDatabaseHandle, table::AbstractString,
return checkerrclear(PQgetResult(db.ptr))
end

hashsql(sql::AbstractString) = bytestring(string("__", hash(sql), "__"))
hashsql(sql::AbstractString) = String(string("__", hash(sql), "__"))

function getparamtypes(result::Ptr{PGresult})
nparams = PQnparams(result)
return @compat [pgtype(OID{Int(PQparamtype(result, i-1))}) for i = 1:nparams]
return [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)
Expand Down Expand Up @@ -281,9 +280,9 @@ function unsafe_fetchrow(result::PostgresResultHandle, rownum::Integer)
end

function unsafe_fetchcol_dataarray(result::PostgresResultHandle, colnum::Integer)
return @data([PQgetisnull(result.ptr, i, colnum) == 1 ? NA :
return Any[PQgetisnull(result.ptr, i, colnum) == 1 ? NA :
jldata(result.types[colnum+1], PQgetvalue(result.ptr, i, colnum))
for i = 0:(PQntuples(result.ptr)-1)])
for i = 0:(PQntuples(result.ptr)-1)]
end

function DBI.fetchall(result::PostgresResultHandle)
Expand All @@ -293,7 +292,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
Expand Down
41 changes: 25 additions & 16 deletions src/libpq_common.jl
Original file line number Diff line number Diff line change
@@ -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...) )
Expand Down Expand Up @@ -50,14 +50,14 @@ const PGF_BINARY = 1
# Skipping MacroDefinition: PQsetdb(M_PGHOST,M_PGPORT,M_PGOPT,M_PGTTY,M_DBNAME)PQsetdbLogin(M_PGHOST,M_PGPORT,M_PGOPT,M_PGTTY,M_DBNAME,NULL,NULL)
# Skipping MacroDefinition: PQfreeNotify(ptr)PQfreemem(ptr)
const PQnoPasswordSupplied = "fe_sendauth: no password supplied\n"
typealias _IO_lock_t Union{}
typealias va_list Cint
const _IO_lock_t = Union{}
const va_list = Cint
# typealias off_t __off_t
# typealias ssize_t __ssize_t
# typealias fpos_t _G_fpos_t
typealias Oid UInt32
const Oid = UInt32
# begin enum ConnStatusType
typealias ConnStatusType UInt32
const ConnStatusType = UInt32
const CONNECTION_OK = 0
const CONNECTION_BAD = 1
const CONNECTION_STARTED = 2
Expand All @@ -69,15 +69,15 @@ const CONNECTION_SSL_STARTUP = 7
const CONNECTION_NEEDED = 8
# end enum ConnStatusType
# begin enum PostgresPollingStatusType
typealias PostgresPollingStatusType UInt32
const PostgresPollingStatusType = UInt32
const PGRES_POLLING_FAILED = 0
const PGRES_POLLING_READING = 1
const PGRES_POLLING_WRITING = 2
const PGRES_POLLING_OK = 3
const PGRES_POLLING_ACTIVE = 4
# end enum PostgresPollingStatusType
# begin enum ExecStatusType
typealias ExecStatusType UInt32
const ExecStatusType = UInt32
const PGRES_EMPTY_QUERY = 0
const PGRES_COMMAND_OK = 1
const PGRES_TUPLES_OK = 2
Expand All @@ -90,29 +90,38 @@ const PGRES_COPY_BOTH = 8
const PGRES_SINGLE_TUPLE = 9
# end enum ExecStatusType
# begin enum PGTransactionStatusType
typealias PGTransactionStatusType UInt32
const PGTransactionStatusType = UInt32
const PQTRANS_IDLE = 0
const PQTRANS_ACTIVE = 1
const PQTRANS_INTRANS = 2
const PQTRANS_INERROR = 3
const PQTRANS_UNKNOWN = 4
# end enum PGTransactionStatusType
# begin enum PGVerbosity
typealias PGVerbosity UInt32
const PGVerbosity = UInt32
const PQERRORS_TERSE = 0
const PQERRORS_DEFAULT = 1
const PQERRORS_VERBOSE = 2
# end enum PGVerbosity
# begin enum PGPing
typealias PGPing UInt32
const PGPing = UInt32
const PQPING_OK = 0
const PQPING_REJECT = 1
const PQPING_NO_RESPONSE = 2
const PQPING_NO_ATTEMPT = 3
# end enum PGPing
typealias PQnoticeReceiver Ptr{Void}
typealias PQnoticeProcessor Ptr{Void}
typealias pqbool UInt8
typealias pgthreadlock_t Ptr{Void}
typealias PGconn Void
typealias PGresult Void
const PQnoticeReceiver = Ptr{Void}
const PQnoticeProcessor = Ptr{Void}
const pqbool = UInt8
const pgthreadlock_t = Ptr{Void}
const PGconn = Void
const PGresult = Void

const _IO_FILE = Void
const FILE = Void
const PQconninfoOption = Void
const PGcancel = Void
const PGnotify = Void
const PQArgBlock = Void
const PGresAttDesc = Void
const PQprintOpt = Void
5 changes: 0 additions & 5 deletions src/libpq_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ module libpq_interface
@c Cint _IO_vfprintf (Ptr{_IO_FILE}, Ptr{UInt8}, Cint) libpq
# @c __ssize_t _IO_padn (Ptr{_IO_FILE}, Cint, __ssize_t) libpq
@c Cint _IO_sgetn (Ptr{_IO_FILE}, Ptr{Void}, Cint) libpq
@c __off64_t _IO_seekoff (Ptr{_IO_FILE}, __off64_t, Cint, Cint) libpq
@c __off64_t _IO_seekpos (Ptr{_IO_FILE}, __off64_t, Cint) libpq
@c Void _IO_free_backup_area (Ptr{_IO_FILE},) libpq
@c Cint remove (Ptr{UInt8},) libpq
@c Cint rename (Ptr{UInt8}, Ptr{UInt8}) libpq
Expand Down Expand Up @@ -124,9 +122,6 @@ module libpq_interface
@c Cint fscanf (Ptr{FILE}, Ptr{UInt8}) libpq
@c Cint scanf (Ptr{UInt8},) libpq
@c Cint sscanf (Ptr{UInt8}, Ptr{UInt8}) libpq
@c Cint fscanf (Ptr{FILE}, Ptr{UInt8}) libpq
@c Cint scanf (Ptr{UInt8},) libpq
@c Cint sscanf (Ptr{UInt8}, Ptr{UInt8}) libpq
@c Cint fgetc (Ptr{FILE},) libpq
@c Cint getc (Ptr{FILE},) libpq
@c Cint getchar () libpq
Expand Down
Loading