Hi everyone,
I am writing a python program using PyADO to add some data to an 'mdb'
database. For example,
filename = UserObjs.mdb
table I am working with = Lines
fields I am working with = ID and Metrics
The 'ID' field is just a number field. The 'Metrics' filed is an OLE object.
In this OLE object assigned in Microsoft Access, I need to include a series
of latitude/longitude numbers as in an array.
The problem I have is that, let's suppose I want to add this array:
[(23.00000,56.5897),(23.4569,58),(244569,60)]. I can add it with no problem to the OLE field, but...when I read the database (SELECT etc..), what I get is something like
this: [ *(*2*3*.*0*,...) ]
(Note: Here, I used the * to symbolize spaces.)
What I wanted was to store the array as a byte stream. How can I do that?
I'd appreciate any help I could get on this!
Thank you so much!!!
Regards,
Michel
PS: Below is the code I am using to insert / read the data:
****To insert: -
import PyADO
-
import win32com.client
-
import sys
-
-
id_number = raw_input("ID? ")
-
-
id_metrics = [(23.00000,56.5897),(23.4569,58),(244569,60)]
-
-
conn = win32com.client.Dispatch(r'ADODB.Connection')
-
DSN = 'PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA
-
SOURCE=C:\msm_test\OLE_project\UserObjs.mdb;'
-
sql_statement = "INSERT INTO Lines (ID,Metrics) VALUES ('%s','%s');"
-
%(id_number,id_metrics)
-
-
conn.Open(DSN)
-
conn.Execute(sql_statement)
-
conn.Close()
*** To read the data -
import PyADO
-
-
conn =
-
PyADO.connect(None,user='admin',password='',host=None,database='C:\\msm_test\OLE_project\UserObjs.mdb',provider='Microsoft.Jet.OLEDB.4.0')
-
-
curs = conn.cursor()
-
-
curs.execute("select * from Lines")
-
-
result = curs.fetchall()
-
descr = curs.description
-
for row in result:
-
for col in row:
-
print col
-
-
curs.close()
-
conn.close()
5 1676 bvdet 2,851
Expert Mod 2GB
Try storing the data as str objects.
I have tried that and I get the same thing.
How do I convert my array to byte stream?
bvdet 2,851
Expert Mod 2GB
I know next to nothing about DB/Python interfaces, so I am mostly guessing. Why not try parsing the returned string? If you want to store the data as a byte stream, you may need a different field type in the DB.
Example data parse using eval(): - >>> returned_data = "[ (2 3 . 0 0 0 0 0 , 5 6 . 5 8 9 7 ) , ( 2 3 . 4 5 6 9 , 5 8 ) , (2 4 4 5 6 9 , 6 0 ) ]"
-
>>> eval(returned_data.replace(" ", ""))
-
[(23.0, 56.589700000000001), (23.456900000000001, 58), (244569, 60)]
Even by including your suggestion, that is, using eval and replace, it still adds spaces between the data. And because of the spaces, I can't access the data correctly in another program.
The same thing happens if I Pickle the data before adding to the database.
There's another test you can make:
test = (2,3)
import cPickle
testpickle = cPickle.dumps(test,2)
testpickle
print testpickle
The last two commands are very different. When you type just testpickle, you get something like:
'\x80\x02K\x02K\x03\x86q\x01.'
when you type 'print testpickle', you get:
€ K K † q .
There are spaces between the elements. These are the spaces I am mentioning here. This is how the dataset is being stored in the mdb database. How do I get rid of these 'null bytes'?
Thanks!
Mike
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Federico G. Babelis |
last post by:
Hi All:
I have this line of code, but the syntax check in VB.NET 2003 and also in
VB.NET 2005 Beta 2 shows as unknown:
Dim local4 As Byte
Fixed(local4 = AddressOf dest(offset))
...
|
by: justanotherguy63 |
last post by:
Hi,
I am designing an application where to preserve the hierachy and for
code substitability, I need to pass an array of derived class object in
place of an array of base class object. Since I...
|
by: ritchie |
last post by:
Hi,
I am writing to ask if anyone can see why my array is not being sorted
correctly?
It's an array of 4 elements(ints 1,2,3,4) but after calling the
selection sort
it comes back sorted as...
|
by: Gerald |
last post by:
I have a problem with an array of pointers.
In a program I'm writing, I have to read a file, containing thousands
of short lines. The content of another file will be compared against
each line...
|
by: arkobose |
last post by:
my earlier post titled:
"How to input strings of any lengths into arrays of type: char
*array ?"
seems to have created a confusion. therefore i paraphrase my problem
below.
consider the...
|
by: Alexei A. Frounze |
last post by:
Hi all,
I have a question regarding the gcc behavior (gcc version 3.3.4).
On the following test program it emits a warning:
#include <stdio.h>
int aInt2 = {0,1,2,4,9,16};
int aInt3 =...
|
by: intrepid_dw |
last post by:
Hello, all.
I've created a C# dll that contains, among other things, two functions
dealing with byte arrays. The first is a function that returns a byte
array, and the other is intended to...
|
by: Leszek |
last post by:
Hi.
Is it possible in javascript to operate on an array without knowing how mamy
elements it has?
What i want to do is sending an array to a script, and this script should
add all values from...
|
by: sandy |
last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory',
within my class Directory (Can you already smell disaster?)
Each Directory can have subdirectories so I thought to put these...
|
by: assgar |
last post by:
Hi
Seasons Greetings
Its back, I am being haunted.
I thought I had resolved this problem but I am intermittently
the receving the warnings below.
This code consist of a 1) HTML form, 2)...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |