加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Julia: SQLite库升级带来的变化

发布时间:2020-12-12 19:36:26 所属栏目:百科 来源:网络整理
导读:随着Julia0.4版本的升级,SQLite库也有不小的变化。特别是引入了DataStreams,CSV等库在其中。在一些接口用法上有一些改变。 1、返回类型是Data.Table julia using HDF5,JLD ; WARNING: using HDF5 .file in module Main conflicts with an existing identif

随着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:sqlitetest.db" 
"E:sqlitetest.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]]

是不行的。 因此这类格式,需要转换:

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读