473,394 Members | 1,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Array Problem

4
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:
Expand|Select|Wrap|Line Numbers
  1. import PyADO
  2. import win32com.client
  3. import sys
  4.  
  5. id_number = raw_input("ID? ")
  6.  
  7. id_metrics = [(23.00000,56.5897),(23.4569,58),(244569,60)]
  8.  
  9. conn = win32com.client.Dispatch(r'ADODB.Connection')
  10. DSN = 'PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA
  11. SOURCE=C:\msm_test\OLE_project\UserObjs.mdb;'
  12. sql_statement = "INSERT INTO Lines (ID,Metrics) VALUES ('%s','%s');"
  13. %(id_number,id_metrics)
  14.  
  15. conn.Open(DSN)
  16. conn.Execute(sql_statement)
  17. conn.Close()
*** To read the data
Expand|Select|Wrap|Line Numbers
  1. import PyADO
  2.  
  3. conn =
  4. PyADO.connect(None,user='admin',password='',host=None,database='C:\\msm_test\OLE_project\UserObjs.mdb',provider='Microsoft.Jet.OLEDB.4.0')
  5.  
  6. curs = conn.cursor()
  7.  
  8. curs.execute("select * from Lines")
  9.  
  10. result = curs.fetchall()
  11. descr = curs.description
  12. for row in result:
  13.     for col in row:
  14.         print col
  15.  
  16. curs.close()
  17. conn.close()
Mar 24 '09 #1
5 1676
bvdet
2,851 Expert Mod 2GB
Try storing the data as str objects.
Mar 24 '09 #2
mikesm
4
I have tried that and I get the same thing.

How do I convert my array to byte stream?
Mar 25 '09 #3
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():
Expand|Select|Wrap|Line Numbers
  1. >>> 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 ) ]"
  2. >>> eval(returned_data.replace(" ", ""))
  3. [(23.0, 56.589700000000001), (23.456900000000001, 58), (244569, 60)]
Mar 25 '09 #4
mikesm
4
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.
Mar 25 '09 #5
mikesm
4
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
Mar 25 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

7
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)) ...
9
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...
5
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...
8
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...
12
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...
204
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 =...
8
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...
104
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...
23
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...
4
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)...
0
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...
0
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...
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
0
Oralloy
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,...
0
jinu1996
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.