|
| 1 | +#!/usr/bin/python |
| 2 | + |
| 3 | +import griddb_python as griddb |
| 4 | +import sys |
| 5 | + |
| 6 | +factory = griddb.StoreFactory.get_instance() |
| 7 | + |
| 8 | +argv = sys.argv |
| 9 | + |
| 10 | +blob = bytearray([65, 66, 67, 68, 69, 70, 71, 72, 73, 74]) |
| 11 | +update = True |
| 12 | + |
| 13 | +try: |
| 14 | + #Get GridStore object |
| 15 | + gridstore = factory.get_store(host=argv[1], port=int(argv[2]), cluster_name=argv[3], username=argv[4], password=argv[5]) |
| 16 | + |
| 17 | + #Create Collection |
| 18 | + conInfo = griddb.ContainerInfo("col01", |
| 19 | + [["name", griddb.GS_TYPE_STRING], |
| 20 | + ["status", griddb.GS_TYPE_BOOL], |
| 21 | + ["count", griddb.GS_TYPE_LONG], |
| 22 | + ["lob", griddb.GS_TYPE_BLOB]], |
| 23 | + griddb.GS_CONTAINER_COLLECTION, True) |
| 24 | + col = gridstore.put_container(conInfo) |
| 25 | + |
| 26 | + #Change auto commit mode to false |
| 27 | + col.set_auto_commit(False) |
| 28 | + |
| 29 | + #Set an index on the Row-key Column |
| 30 | + col.create_index("name", griddb.GS_INDEX_FLAG_DEFAULT) |
| 31 | + |
| 32 | + #Set an index on the Column |
| 33 | + col.create_index("count", griddb.GS_INDEX_FLAG_DEFAULT) |
| 34 | + |
| 35 | + #Put row: RowKey is "name01" |
| 36 | + ret = col.put(["name01", False, 1, blob]) |
| 37 | + #Remove row with RowKey "name01" |
| 38 | + col.remove("name01") |
| 39 | + |
| 40 | + #Put row: RowKey is "name02" |
| 41 | + col.put(["name02", False, 1, blob]) |
| 42 | + col.commit(); |
| 43 | + |
| 44 | + mlist = col.get("name02") |
| 45 | + #print(mlist) |
| 46 | + |
| 47 | + #Create normal query |
| 48 | + query=col.query("select * where name = 'name02'") |
| 49 | + |
| 50 | + #Execute query |
| 51 | + rs = query.fetch(update) |
| 52 | + while rs.has_next(): |
| 53 | + data = rs.next() |
| 54 | + |
| 55 | + data[2] = data[2] + 1 |
| 56 | + print("Person: name={0} status={1} count={2} lob=[{3}]".format(data[0], data[1], data[2], ', '.join(str(e) for e in data[3]))) |
| 57 | + |
| 58 | + #Update row |
| 59 | + rs.update(data) |
| 60 | + |
| 61 | + #End transaction |
| 62 | + col.commit() |
| 63 | + |
| 64 | +except griddb.GSException as e: |
| 65 | + for i in range(e.get_error_stack_size()): |
| 66 | + print("[", i, "]") |
| 67 | + print(e.get_error_code(i)) |
| 68 | + print(e.get_location(i)) |
| 69 | + print(e.get_message(i)) |
0 commit comments