0

I am working on a project that requires me to get data from a SAP HANA database. I utilized SAP Cloud Connector and PyHDB for the job. I execute my select statement and obtain the result data. One of the fields is a TEXT type, containing large articles. While iterating each row I need to somehow get the data from the TEXT field into a string. However I am only able to get the first 1024 characters. The object that stores the TEXT appears to be a StringIO type. How can I read the entire text data instead of the first 1024 characters only?

import pyhdb

connection_from = pyhdb.connect(
host="localhost",
port=00000,
user="user",
password="password"
)
cursor_from = connection_from.cursor()

cursor_from.execute('SELECT * FROM SCHEMA.TABLE')
results= cursor_from.fetchall()

for row in results:
    text = row[2].data.getvalue()

connection_from.close()

This is the what the object looks like: NClob

I need to get the whole text into a string then print it. Thank you.

spdasilv
  • 101
  • 1
  • 1
  • 7
  • Could you post the data here or into a gist instead? https://gist.github.com/ I can't access imgur for some reason. – spookylukey Dec 09 '17 at 08:06

1 Answers1

0

According to the docs, you need to call .read() on the returned object, passing in the number of bytes you want to get. This is not a very friendly interface, but I guess if you pass in a number that is definitely bigger than all your objects, you'll get everything. Or you could do a small loop that iterates with bigger values until you have it all - when the length of string returned by .getvalue() does increase.

spookylukey
  • 6,380
  • 1
  • 31
  • 34