-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question regarding reading SQLite recorded data #37
Comments
First, I'm assuming you installed my other OOT module gr-sqlite, correct? Are you trying to "replay" the recorded ADS-B packets in another GNU Radio flowgraph like described here? Regarding reading the BLOB type, I describe here how the SQLite Sink stores data. The "PDU vector" ( import pmt
# pdu_bin is the binary BLOB, read from the database
pdu = pmt.deserialize_str(pdu_bin) # Convert from PDU binary string to PDU python object
packet_bin = pmt.to_python(pmt.car(pdu)) # Take the CAR portion (PDU vector) and convert to python bytearray (?, I think) |
Yes, you're right, I meant your OOT module of SQLite.
Any ideas how to deal with this? |
Ok, I know what's going wrong. The issue is you're reading all the rows at the same time with You could just read the first row, like this: def run_query(query=''):
conn = sqlite3.connect('adsb.db')
c = conn.cursor()
c.execute(query)
if query.upper().startswith('SELECT'):
data1 = c.fetchone()
print(type(data1), data1) # This is either a sqlite3.Row object or a byte string, see what it is
data2py = pmt.deserialize_str(data1)
# data2py = pmt.deserialize_str(data1[0]) # You may need to index the "data" column from the data1 row object
data = pmt.to_python(pmt.car(data2py))
else:
conn.commit()
data= None
c.close()
conn.close()
return data
query = "SELECT data FROM Info"
result = run_query(query)
print(result) Alternately, you can iterate through all the rows and populate a list or 2D array or something. def run_query(query=''):
conn = sqlite3.connect('adsb.db')
c = conn.cursor()
c.execute(query)
if query.upper().startswith('SELECT'):
data = []
for data1 in c.fetchall():
data2py = pmt.deserialize_str(data1)
# data2py = pmt.deserialize_str(data1[0]) # You may need to index the "data" column from the data1 row object
data.append(pmt.to_python(pmt.car(data2py)))
else:
conn.commit()
data= None
c.close()
conn.close()
return data
query = "SELECT data FROM Info"
result = run_query(query)
print(result) If this doesn't work for you, print out some of the variable types and values and we can debug it. |
Hi again, first, thank for all your help.
Trying this one out, the first print says: "(<type 'tuple'>, (<read-write buffer ptr 0x7f347ec395b0, size 120 at 0x7f347ec39570>,)) Any thoughts? |
What version of python is this? Python 2.7? Try changing the "text factory" of the database connection to string, like below. I'm guessing this is the difference between my code and yours. conn = sqlite3.connect('adsb.db')
conn.text_factory = str
c = conn.cursor() Also, it may be helpful to reference my python SQLite source blocks from If this doesn't work, please provide the outputs to these print statements. data1 = c.fetchone()
print(type(data1))
print(len(data1))
print(type(data1[0]))
print(data1[0]) |
Yes, it's Python 2.7, I thought it was better to avoid compatibility problems. So the outputs to the prints that you suggested are the ones in the yellowish color (in the very same order): I didn't have the time to check the SQLite source blocks but I'll surely do it later! |
Ok, try this. I'm pretty sure this will work (although I've thought that a few times). We're zeroing in on the issue, though. This converts the buffer object of data1 = c.fetchone()
print(type(data1))
print(len(data1))
print(type(data1[0]))
print(data1[0])
data2py = pmt.deserialize_str(str(data1[0]))
print(type(data2py))
print(data2py)
data = pmt.to_python(pmt.car(data2py))
print(type(data))
print(data) |
This it's working! thank you so much for taking your time. |
Hello,
I have some burst recorded in a sqlite database, with the block of sqlite that you provided. The thing is, I'd like to send this data to another user and ideally, he would store it and represent it at the same time that I am getting more data into this db. So I was doing a python script that would be able to read this database and send the data recorded (latitude, longitude...). But the field data is in BLOB type and I am not able to read it. Is there any way to do it?
Maybe this solution is a bit complicated, but I didnt find a way to send this data with gnuradio blocks, is there any?
Thanks for your time!
The text was updated successfully, but these errors were encountered: