chiark
/
gitweb
/
~naath
/
familyTree.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
refactoring SELECTs
[familyTree.git]
/
familyTree
/
askQuestion.py
diff --git
a/familyTree/askQuestion.py
b/familyTree/askQuestion.py
index 9135befc362e277a064735879f9d2851148bb895..c6273cc77c14b59e731d0ef53e04bfe81654c0c0 100755
(executable)
--- a/
familyTree/askQuestion.py
+++ b/
familyTree/askQuestion.py
@@
-103,6
+103,8
@@
def name_html(row,html):
if row[0] == None:
return row[1]
if row[0] == None:
return row[1]
+ elif row[1]==0:
+ return row[0]
else:
if html==1:
script = "person.py?ID=" + str(row[1])
else:
if html==1:
script = "person.py?ID=" + str(row[1])
@@
-229,10
+231,8
@@
def list_people_parents():
[parents, parentIDs,parentNames] = find_parents(ID)
[spouses,spousesID,spousesNames] = find_spouses(ID)
[parents, parentIDs,parentNames] = find_parents(ID)
[spouses,spousesID,spousesNames] = find_spouses(ID)
-
- myName = row[0]
- myID = str(row[1])
- output.append([myName+ ','+ myID,parents,spouses])
+ [self,myID,myName] = find_person(ID)
+ output.append([self,parents,spouses])
return output
return output
@@
-369,7
+369,7
@@
def search_name(name,newLine):
def people_with_name(name,newLine):
s = "SELECT name, ID"\
+" FROM people"\
def people_with_name(name,newLine):
s = "SELECT name, ID"\
+" FROM people"\
- +" WHERE firstname
LIKE
?;"
+ +" WHERE firstname
=
?;"
out = ''
out = ''
@@
-480,19
+480,13
@@
def people_died_at_age(age,newLine):
def all_ancestors(personID,newLine):
#find parents
def all_ancestors(personID,newLine):
#find parents
- s = "SELECT people.Name,parents.parentID FROM"\
- +" parents LEFT JOIN people"\
- +" ON parents.parentID = people.ID"\
- +" WHERE parents.ID = ?"\
- +" AND parents.parentID <> '.';"
-
ancestors = [personID]
allAncestors = [personID]
trackLevel = [0]
level = 0
ancestors = [personID]
allAncestors = [personID]
trackLevel = [0]
level = 0
- t = "SELECT name,id FROM people WHERE id=
=
?"
+ t = "SELECT name,id FROM people WHERE id=?"
id = (personID,)
out = "Ancestors of "
id = (personID,)
out = "Ancestors of "
@@
-507,14
+501,17
@@
def all_ancestors(personID,newLine):
thisout = newLine + parent_level(level,'parent') +\
':' + newLine
for ancestor in ancestors:
thisout = newLine + parent_level(level,'parent') +\
':' + newLine
for ancestor in ancestors:
- id = (ancestor,)
- for row in run_query(s,id):
+ [parents, parentIDs,parentNames] \
+ = find_parents(ancestor)
+ for i in range(len(parents)):
+ r = [parentNames[i],parentIDs[i]]
thisout = thisout + \
thisout = thisout + \
- name_html(row,newLine)+newLine
- if row[1] not in allAncestors\
- and is_number(row[1]):
- newA.append(row[1])
- allAncestors.append(row[1])
+ name_html(r,newLine)+newLine
+
+ if r[1] not in allAncestors\
+ and r[1]!=0:
+ newA.append(r[1])
+ allAncestors.append(r[1])
trackLevel.append(level)
ancestors = newA
trackLevel.append(level)
ancestors = newA
@@
-575,8
+572,6
@@
def common_ancestors(IDA, IDB,newLine):
s = s+ "?,"
if len(common)>0:
s = s[:-1]
s = s+ "?,"
if len(common)>0:
s = s[:-1]
-
-
s = s+") ORDER BY bornyear;"
s = s+") ORDER BY bornyear;"
@@
-734,6
+729,15
@@
def rulers_of(aTerritory,newLine):
return out
return out
+def find_person(ID):
+ s = "SELECT name || ','||ID, name, ID FROM people WHERE ID=?"
+ t = (ID,)
+
+ for row in run_query(s,t):
+ Self = row[0]
+ selfName = row[1]
+ selfID = row[2]
+ return [Self, selfID,selfName]
def find_parents(ID):
s = "SELECT name, parentID"\
def find_parents(ID):
s = "SELECT name, parentID"\
@@
-758,7
+762,7
@@
def find_parents(ID):
parents.append(p)
parentIDs.append(pID)
parentNames.append(pN)
parents.append(p)
parentIDs.append(pID)
parentNames.append(pN)
-
+
if parents[1]==parents[0]:
parents[1] = parents[1] + ' 2'
if parents[1]==parents[0]:
parents[1] = parents[1] + ' 2'
@@
-820,7
+824,7
@@
def find_children(ID):
otherparentsNames=[]
for row in run_query(s,t):
otherparentsNames=[]
for row in run_query(s,t):
- c = row[0] + ',
' + str(row[1])
+ c = row[0] + ',' + str(row[1])
cID = row[1]
cName = row[0]
born = row[4]
cID = row[1]
cName = row[0]
born = row[4]
@@
-829,7
+833,7
@@
def find_children(ID):
childrenNames.append(cName)
childrenBorn.append(born)
if row[3]!=None:
childrenNames.append(cName)
childrenBorn.append(born)
if row[3]!=None:
- op = row[3] + ',
' + str(row[2])
+ op = row[3] + ',' + str(row[2])
opID = row[2]
opN = row[3]
else:
opID = row[2]
opN = row[3]
else: