同步操作将从 taosdata/TDengine 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
"""This is the sample code for TDengine python2 client."""import taosimport sysimport datetimeimport randomdef exitProgram(conn):conn.close()sys.exit()if __name__ == '__main__':start_time = datetime.datetime(2019, 7, 1)time_interval = datetime.timedelta(seconds=60)# Connect to TDengine server.## parameters:# @host : TDengine server IP address# @user : Username used to connect to TDengine server# @password : Password# @database : Database to use when connecting to TDengine server# @config : Configuration directoryif len(sys.argv)>1:hostname=sys.argv[1]conn = taos.connect(host=hostname, user="root", password="taosdata", config="/etc/taos")else:conn = taos.connect(host="127.0.0.1", user="root", password="taosdata", config="/etc/taos")# Generate a cursor object to run SQL commandsc1 = conn.cursor()# Create a database named dbtry:c1.execute('create database if not exists db ')except Exception as err:conn.close()raise(err)# use databasetry:c1.execute('use db')except Exception as err:conn.close()raise(err)# create tabletry:c1.execute('create table if not exists t (ts timestamp, a int, b float, c binary(20))')except Exception as err:conn.close()raise(err)# insert datafor i in range(10):try:value = c1.execute("insert into t values ('%s', %d, %f, '%s')" % (start_time, random.randint(1,10), random.randint(1,10)/10.0, 'hello'))#if insert, value is the affected rowsprint(value)except Exception as err:conn.close()raise(err)start_time += time_interval# query data and return data in the form of listtry:c1.execute('select * from db.t')except Exception as err:conn.close()raise(err)# Column names are in c1.description listcols = c1.description# Use fetchall to fetch data in a listdata = c1.fetchall()for col in data:print(col)print('Another query method ')try:c1.execute('select * from db.t')except Exception as err:conn.close()raise(err)# Use iterator to go through the retreived datafor col in c1:print(col)conn.close()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。