Skip to content

The function juliatype not cover fully? The type name completely follows the table creating statement. #219

@biluohc

Description

@biluohc
# src/SQLite.jl:257

function juliatype(handle, col)
    t = SQLite.sqlite3_column_decltype(handle, col)
    if t != C_NULL
        T = juliatype(unsafe_string(t))
        T !== Any && return T
    end
    x = SQLite.sqlite3_column_type(handle, col)
    if x == SQLite.SQLITE_BLOB
        val = SQLite.sqlitevalue(Any, handle, col)
        return typeof(val)
    else
        return juliatype(x)
    end
end

juliatype(x::Integer) = x == SQLITE_INTEGER ? Int : x == SQLITE_FLOAT ? Float64 : x == SQLITE_TEXT ? String : Any
juliatype(x::String) = x == "INTEGER" ? Int : x in ("NUMERIC","REAL") ? Float64 : x == "TEXT" ? String : Any
CREATE TABLE prices (
    id  INTEGER primary key AUTOINCREMENT not null,
    name Text,
    price Float NOT NULL,
    create_dt datetime not null default  (datetime('now','localtime'))
)
julia> 

julia> SQLite.sqlite3_column_decltype(sqq.stmt.handle, 1) |> unsafe_string
"INTEGER"

julia> SQLite.sqlite3_column_decltype(sqq.stmt.handle, 2) |> unsafe_string
"Text"

julia> SQLite.sqlite3_column_decltype(sqq.stmt.handle, 3) |> unsafe_string
"Float"

julia> SQLite.sqlite3_column_decltype(sqq.stmt.handle, 4) |> unsafe_string
"datetime"


julia> SQLite.sqlite3_column_type(sqq.stmt.handle, 0)
5

julia> SQLite.sqlite3_column_type(sqq.stmt.handle, 1)
5

julia> SQLite.sqlite3_column_type(sqq.stmt.handle, 2)
5

julia> SQLite.sqlite3_column_type(sqq.stmt.handle, 3)
5

julia> SQLite.sqlite3_column_type(sqq.stmt.handle, 4)
5

julia> SQLite.sqlite3_column_type(sqq.stmt.handle, 5)
5
julia> sqct |> print
CREATE TABLE prices (
    id  INTEGER primary key AUTOINCREMENT not null,
    name text,
    price float NOT NULL,
    create_dt datetime not null default  (datetime('now','localtime'))
)
julia> SQLite.sqlite3_column_decltype(sqf.stmt.handle, 1) |> unsafe_string
"INTEGER"

julia> SQLite.sqlite3_column_decltype(sqf.stmt.handle, 2) |> unsafe_string
"text"

julia> SQLite.sqlite3_column_decltype(sqf.stmt.handle, 3) |> unsafe_string
"float"

julia> SQLite.sqlite3_column_decltype(sqf.stmt.handle, 4) |> unsafe_string
"datetime"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions