Select to view content in your preferred language

Problems with MakeQueryTable_management in code

561
2
Jump to solution
04-05-2013 10:30 AM
JimW
by
Frequent Contributor
I am having trouble getting the code below to execute succesfully:

import arcpy  tableList = ['Database Connections\\Metering_Data.odc\\tblFlowMeters', \              'Database Connections\\Metering_Data.odc\\tblDataCollectionPeriods', \              'Database Connections\\Metering_Data.odc\\tblFlowMeterDataCollectionPeriods', \              'Database Connections\\Metering_Data.odc\\tblMeteringData']  fieldList = [['tblFlowMeters.MeterName'], ['tblDataCollectionPeriods.StartDate', \               'tblDataCollectionPeriods.EndDate'], ['tblMeteringData.MeteringDataId', \               'tblMeteringData.MeteringDateTime', 'tblMeteringData.DepthInches', \               'tblMeteringData.VelocityFTperSec', 'tblMeteringData.FlowMGD', \               'tblMeteringData.RainInches','tblMeteringData.DebrisInches']]  whereClause = "(tblFlowMeters.FlowMeterId = tblFlowMeterDataCollectionPeriods.FlowMeterId \                AND tblFlowMeterDataCollectionPeriods.DataCollectionPeriodsId =  \                tblDataCollectionPeriods.DataCollectionPeriodsId AND \                tblDataCollectionPeriods.DataCollectionPeriodsId = \                tblMeteringData.DataCollectionPeriodId AND \                tblFlowMeterDataCollectionPeriods.FlowMeterIdDataCollectionPeriodsId \                = tblMeteringData.FlowMeterDataCollectionPeriodsId ) AND \                (tblFlowMeters.MeterName = 'RH2A')"  arcpy.MakeQueryTable_management(tableList, "tblFlowMetersTest7", "USE_KEY_FIELDS", "tblMeteringData.MeteringDataId", fieldList, whereClause)


I get the following error message when I run it:
Traceback (most recent call last):   File "<string>", line 73, in execInThread   File "C:\Program Files\PyScripter\Lib\rpyc.zip\rpyc\core\netref.py", line 196, in __call__   File "C:\Program Files\PyScripter\Lib\rpyc.zip\rpyc\core\netref.py", line 71, in syncreq   File "C:\Program Files\PyScripter\Lib\rpyc.zip\rpyc\core\protocol.py", line 431, in sync_request   File "C:\Program Files\PyScripter\Lib\rpyc.zip\rpyc\core\protocol.py", line 379, in serve   File "C:\Program Files\PyScripter\Lib\rpyc.zip\rpyc\core\protocol.py", line 337, in _recv   File "C:\Program Files\PyScripter\Lib\rpyc.zip\rpyc\core\channel.py", line 50, in recv   File "C:\Program Files\PyScripter\Lib\rpyc.zip\rpyc\core\stream.py", line 166, in read EOFError: [Errno 10054] An existing connection was forcibly closed by the remote host


If I run the code without the fieldList variable, the code runs succesfully.  Is there something wrong with my fieldList variable that I am not seeing?

I can run the MakeQueryTable_managment toolbox in ArcMap with all the same values successfully.  It also runs if I do it via a model.  When I export the model to a script it also runs successfully.

Anyone have an idea why my fieldList variable wont' allow it to run?
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
curtvprice
MVP Alum
Anyone have an idea why my fieldList variable wont' allow it to run?


I think you have a syntax problem -- extra brackets. Here's a suggested fix. Note you don't need line continuations in the middle of a list (Python knows to keep reading to the end.)

fieldList = ['tblFlowMeters.MeterName', 'tblDataCollectionPeriods.StartDate',                'tblDataCollectionPeriods.EndDate', 'tblMeteringData.MeteringDataId',                'tblMeteringData.MeteringDateTime', 'tblMeteringData.DepthInches',                'tblMeteringData.VelocityFTperSec', 'tblMeteringData.FlowMGD',                'tblMeteringData.RainInches','tblMeteringData.DebrisInches']

View solution in original post

0 Kudos
2 Replies
curtvprice
MVP Alum
Anyone have an idea why my fieldList variable wont' allow it to run?


I think you have a syntax problem -- extra brackets. Here's a suggested fix. Note you don't need line continuations in the middle of a list (Python knows to keep reading to the end.)

fieldList = ['tblFlowMeters.MeterName', 'tblDataCollectionPeriods.StartDate',                'tblDataCollectionPeriods.EndDate', 'tblMeteringData.MeteringDataId',                'tblMeteringData.MeteringDateTime', 'tblMeteringData.DepthInches',                'tblMeteringData.VelocityFTperSec', 'tblMeteringData.FlowMGD',                'tblMeteringData.RainInches','tblMeteringData.DebrisInches']
0 Kudos
JimW
by
Frequent Contributor
Thank you Curtis!  That was the problem.

I borrowed the code from the online help  for the Make Query Table (Data Management) tool.  The in_field argument is a multivalue parameter. I didn't know you could represent a multivalue parameter three different ways:  as a list, a string with values separated by a colon or a value table.  As I wasn't including any field aliases I thought I could just eliminate the alias portion of the argument and keep everything else the same hence the extra brackets and my code not running.  I am good to go now!  Thank you again.
0 Kudos