未验证 提交 8e30e30a 编写于 作者: S Shengliang Guan 提交者: GitHub

Merge pull request #2775 from taosdata/feature/pyconn

Feature/pyconn
...@@ -26,7 +26,6 @@ if __name__ == '__main__': ...@@ -26,7 +26,6 @@ if __name__ == '__main__':
# Generate a cursor object to run SQL commands # Generate a cursor object to run SQL commands
c1 = conn.cursor() c1 = conn.cursor()
# Create a database named db # Create a database named db
try: try:
c1.execute('create database if not exists db ') c1.execute('create database if not exists db ')
...@@ -50,9 +49,11 @@ if __name__ == '__main__': ...@@ -50,9 +49,11 @@ if __name__ == '__main__':
raise(err) raise(err)
# insert data # insert data
for i in range(10000): for i in range(10):
try: try:
c1.execute("insert into t values ('%s', %d, %f, '%s')" % (start_time, random.randint(1,10), random.randint(1,10)/10.0, 'hello')) 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 rows
print(value)
except Exception as err: except Exception as err:
conn.close() conn.close()
raise(err) raise(err)
...@@ -70,6 +71,11 @@ if __name__ == '__main__': ...@@ -70,6 +71,11 @@ if __name__ == '__main__':
# Use fetchall to fetch data in a list # Use fetchall to fetch data in a list
data = c1.fetchall() data = c1.fetchall()
for col in data:
print(col)
print('Another query method ')
try: try:
c1.execute('select * from db.t') c1.execute('select * from db.t')
except Exception as err: except Exception as err:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册