Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

Finding multiple tables and setting them to a variable

$
0
0
There is something that just isn't right with this and I can figure it out. Here is the code:

Code:

  import sys, string, os, cx_Oracle, arcpy, datetime

  LRName = "RSID_"+num
  LRName1 = "RSID"+num
  last_year = str(now.year -1)       
  Two_years = str(now.year -2)

  orcl = cx_Oracle.connect('xxxxx/xxxxx@xxx')
  curs = orcl.cursor()
  sqllr1 = "select * from cat where table_name like '" +str(LRName1)+"%'"
  sqllr2 = "select * from cat where table_name like '" +str(LRName)+"%'"
  curs.execute(sqllr1)

  tables = curs.fetchall()
  for table in tables:
      if last_year in table:
        LastRun_Table = table
        break
      elif Two_years in table:
        LastRun = table
        break
      else:
        curs.execute(sqllr2)
        tables1 = curs.fetchall()
        for table1 in tables1:
            if last_year in table1:
              LastRun_Table = table1
              break
            elif Two_years in table1:
              LastRun_Table = table1
              break
            else:
              LastRun_Table = ""

  curs.close()
  orcl.close()

Basically I am trying to look for certain tables from previous years that match with what I am running now, set that table name to a variable that I will use later. This runs through but I am pretty sure that it is not going through the "for" statement. If I put in "fetchone" instead of "fetchall", it will go through the script once and than I get this for an error:

TypeError: 'NoneType' object is not iterable

This is just a small part of a large script that I am trying to get to work. The large script loops through several feature classes and within each feature class it does this portion (plus other things). I am kind of confused on the ".fetch" thing but it seem to be the only way that I could put the table name into a variable. I would think that there is an easier way to do this but I don't know. Any help would appreciated. Thanks in advance.

Viewing all articles
Browse latest Browse all 2485

Trending Articles