随着Julia0.4版本的升级,sqlite库也有不小的变化。特别是引入了DataStreams,CSV等库在其中。在一些接口用法上有一些改变。
1、返回类型是Data.Table
julia> using HDF5,JLD;
WARNING: using HDF5.file in module Main conflicts with an existing identifier.
julia> a =[1 2]
1x2 Array{Int64,2}:
1 2
julia> b =[1 2;3 4]
2x2 Array{Int64,2}:
1 2
3 4
julia> using DataStreams.Data
julia> Data.Table(a)
Data.Table:
1x2 Data.Schema:
Column1,Column2
Int64,Int64
NullableArrays.NullableArray{T,1}[NullableArrays.NullableArray{Int64,1}[1],Nulla
bleArrays.NullableArray{Int64,1}[2]]
julia> Data.Table(b)
Data.Table:
2x2 Data.Schema:
Column1,1}[1,3],Nul
lableArrays.NullableArray{Int64,1}[2,4]]
2、sqlite 的一些基本操作
(1)建表
julia> using sqlite
julia> DBPath = "E:\\sqlite\\test.db"
"E:\\sqlite\\test.db"
julia> db = sqlite.DB(DBPath)
julia> strsql1=" CREATE TABLE ";
julia> strsql2=" (
Code CHAR NOT NULL,TradeDay INT NOT NULL,TradeTime INT NOT NULL,Open Decimal NOT NULL,High Decimal NOT NULL,Low Decimal NOT NULL,Close Decimal NOT NULL,Volume Decimal NOT NULL,Amount Decimal NOT NULL,OpenInterest Decimal NOT NULL
) ";
julia> strsql= string(strsql1," SH600036 ",strsql2);
julia> sqlite.query(db,strsql);
(2)INSERT
这部分很奇怪的,和原来不一样。
julia> val =Any(["600036",20150606,0931,10.6,11.6,11.2,12.6,123666.0,125,445.6,124])
11-element Array{Any,1}:
"600036"
20150606
931
10.6
11.6
11.2
12.6
123666.0
125
445.6
124
julia> sqlite.query(db,"Insert into SH600036 Values (?1,?2,?3,?4,?5,?6,?7,?8,?9,?10)",val);
注意,如果 val格式是 Array{Any,2},比如
val =Any(["600036" 20150606 0931 10.6 11.6 11.2 12.6 123666.0 125 445.6 124])
在INSERT时是会发生报错的。
更准确地说,类似于这样的数据格式
julia> a=["a" 1.0; "b" 0.2]
2x2 Array{Any,2}:
"a" 1.0
"b" 0.2
julia> Data.Table(a)
Data.Table:
2x2 Data.Schema:
Column1,Column2
ASCIIString,Float64
NullableArrays.NullableArray{T,1}[NullableArrays.NullableArray{ASCIIString,1}["a","b"],NullableArrays.NullableArray{Float64,1}[1.0,0.2]]
是不行的。 因此这类格式,需要转换: