test.lua 1.2 KB
Newer Older
1
local driver = require "luaconnector"
2 3 4 5 6 7 8 9

local host="127.0.0.1"
local user="root"
local password="taosdata"
local db =nil
local port=6030
local conn

10
local res = driver.connect(host,user,password,db,port)
11 12 13 14 15 16 17
if res.code ~=0 then
   print(res.error)
   return
else
   conn = res.conn
end

18
local res = driver.query(conn,"drop database demo")
19

20
res = driver.query(conn,"create database demo")
21 22 23 24 25
if res.code ~=0 then
   print(res.error)
   return
end

26
res = driver.query(conn,"use demo")
27 28 29 30 31
if res.code ~=0 then
   print(res.error)
   return
end

32
res = driver.query(conn,"create table m1 (ts timestamp, speed int,owner binary(20))")
33 34 35 36 37
if res.code ~=0 then
   print(res.error)
   return
end

38 39 40 41 42
res = driver.query(conn,"insert into m1 values (1592222222222,0,'robotspace'), (1592222222223,1,'Hilink'),(1592222222224,2,'Harmony')")
if res.code ~=0 then
   print(res.error)
   return
end
43

44
res = driver.query(conn,"select * from m1")
45

46 47 48 49
if res.code ~=0 then
   print("select error:"..res.error)
   return
else
50
   print("in lua, result:")
51 52 53 54
   for i = 1, #(res.item) do
      print("timestamp:"..res.item[i].ts)
      print("speed:"..res.item[i].speed)
      print("owner:"..res.item[i].owner)
55 56
   end
end
57 58

driver.close(conn)