Mercurial > hg > ChinaGisRestApi
comparison RestDbInterface.py @ 58:5ed0769f5ad3
more cleanup in kml generation
points can be sorted now
| author | casties |
|---|---|
| date | Thu, 21 Oct 2010 19:38:41 +0200 |
| parents | 2f4c427dec44 |
| children | 9fdadb60529f |
comparison
equal
deleted
inserted
replaced
| 57:b47314bcff37 | 58:5ed0769f5ad3 |
|---|---|
| 177 if hasResult: | 177 if hasResult: |
| 178 # get all data in an array | 178 # get all data in an array |
| 179 data = cur.fetchall() | 179 data = cur.fetchall() |
| 180 cur.close() | 180 cur.close() |
| 181 #logging.debug("fields: %s"%repr(fields)) | 181 #logging.debug("fields: %s"%repr(fields)) |
| 182 logging.debug("rows: %s"%repr(data)) | 182 #logging.debug("rows: %s"%repr(data)) |
| 183 return {"fields":fields, "rows":data} | 183 return {"fields":fields, "rows":data} |
| 184 else: | 184 else: |
| 185 cur.close() | 185 cur.close() |
| 186 return None | 186 return None |
| 187 | 187 |
| 314 return "ERROR!! template %s_schema_table not found"%resultFormat | 314 return "ERROR!! template %s_schema_table not found"%resultFormat |
| 315 | 315 |
| 316 #data = self.getTable(schema,table) | 316 #data = self.getTable(schema,table) |
| 317 return pt(schema=schema,table=table) | 317 return pt(schema=schema,table=table) |
| 318 | 318 |
| 319 def getTable(self,schema='public',table=None,username='guest'): | 319 def getTable(self,schema='public',table=None,sortBy=1,username='guest'): |
| 320 """return table data""" | 320 """return table data""" |
| 321 logging.debug("gettable") | 321 logging.debug("gettable") |
| 322 data = self.executeSQL('select * from "%s"."%s"'%(schema,table)) | 322 if sortBy: |
| 323 data = self.executeSQL('select * from "%s"."%s" order by %s'%(schema,table,sortBy)) | |
| 324 else: | |
| 325 data = self.executeSQL('select * from "%s"."%s"'%(schema,table)) | |
| 323 return data | 326 return data |
| 324 | 327 |
| 325 def hasTable(self,schema='public',table=None,username='guest'): | 328 def hasTable(self,schema='public',table=None,username='guest'): |
| 326 """return if table exists""" | 329 """return if table exists""" |
| 327 logging.debug("hastable") | 330 logging.debug("hastable") |
| 349 logging.debug("getlistoftables") | 352 logging.debug("getlistoftables") |
| 350 # get list of fields and types of db table | 353 # get list of fields and types of db table |
| 351 qstr="""SELECT c.relname AS tablename FROM pg_catalog.pg_class c | 354 qstr="""SELECT c.relname AS tablename FROM pg_catalog.pg_class c |
| 352 LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace | 355 LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace |
| 353 WHERE c.relkind IN ('r','') AND n.nspname NOT IN ('pg_catalog', 'pg_toast') | 356 WHERE c.relkind IN ('r','') AND n.nspname NOT IN ('pg_catalog', 'pg_toast') |
| 354 AND pg_catalog.pg_table_is_visible(c.oid)""" | 357 AND pg_catalog.pg_table_is_visible(c.oid) ORDER BY 1""" |
| 355 #qstr="select attname, format_type(pg_attribute.atttypid, pg_attribute.atttypmod) from pg_attribute, pg_class where attrelid = pg_class.oid and pg_attribute.attnum > 0" | 358 #qstr="select attname, format_type(pg_attribute.atttypid, pg_attribute.atttypmod) from pg_attribute, pg_class where attrelid = pg_class.oid and pg_attribute.attnum > 0" |
| 356 data=self.executeSQL(qstr) | 359 data=self.executeSQL(qstr) |
| 357 return data | 360 return data |
| 358 | 361 |
| 359 def showListOfSchemas(self,resultFormat='XML',REQUEST=None,RESPONSE=None): | 362 def showListOfSchemas(self,resultFormat='XML',REQUEST=None,RESPONSE=None): |
