Question

I'm recreating data that's stored in format that's rather difficult to access. Most of the data has successfully been moved and converted. This Python script is meant to identify the parent of each object against the old database and update it's parent (currently null) in the new database.

I have:

# skip the Alpha
for x in range(2, i+1):
    on_level = 'ORG_LEVEL' + str(x)
    parent_level =  'ORG_LEVEL' + str(x-1)

    cur.execute('''SELECT ?, ?
                        FROM OsuOrgs
                        WHERE ORG_LEVEL= ? ''', 
                        [ on_level, parent_level, x ])

    for row in cur.fetchall():
        members.append( { "unv_id":str(row[0]), "parent":str(row[1]) } )

for member in members:
    print(member)

The problem I'm running into is that my members[] object is being filled with the litteral value of on_level and parent_level. My assumption is that is related to how pyodbc is passing the arguments, but I'm a bit stumped as why exactly it's happening.

Example:

{'parent': 'ORG_LEVEL7', 'unv_id': 'ORG_LEVEL8'}
{'parent': 'ORG_LEVEL7', 'unv_id': 'ORG_LEVEL8'}
{'parent': 'ORG_LEVEL7', 'unv_id': 'ORG_LEVEL8'}
{'parent': 'ORG_LEVEL7', 'unv_id': 'ORG_LEVEL8'}
{'parent': 'ORG_LEVEL7', 'unv_id': 'ORG_LEVEL8'}
{'parent': 'ORG_LEVEL7', 'unv_id': 'ORG_LEVEL8'}
{'parent': 'ORG_LEVEL7', 'unv_id': 'ORG_LEVEL8'}
{'parent': 'ORG_LEVEL7', 'unv_id': 'ORG_LEVEL8'}
Was it helpful?

Solution

You probably need to change

cur.execute('''SELECT ?, ?
                    FROM OsuOrgs
                    WHERE ORG_LEVEL= ? ''', 
                    [ on_level, parent_level, x ])

to

cur.execute('''SELECT {0}, {1} 
                    FROM OsuOrgs
                    WHERE ORG_LEVEL= ? '''.format(on_level, parent_level), 
                    x )
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top