Forum Stats

  • 3,770,460 Users
  • 2,253,117 Discussions
  • 7,875,465 Comments

Discussions

No values for varchar in cx_Oracle

limor
limor Member Posts: 38
edited Aug 3, 2016 4:44AM in Python

Hi,

I have a column inside my orace database with type varchar2(256Byte).

And now I wrote a webserver with web.py and cx_Oracle to do a query and fetch the result.

The problem is I get no values for this column. But curiously it works for another column with the same type.

code:

import cx_Oracle

import json

import web

urls = (

    "/", "index",

    "/grid", "grid",

)

app = web.application(urls, globals())

web.config.debug = True

connection = cx_Oracle.Connection("TEST_3D/[email protected]:1521/sdetest")

typeObj = connection.gettype("MDSYS.SDO_GEOMETRY")

class index:

    def GET(self):

        return "hallo moritz "

class grid:

    def GET(self):

        web.header('Access-Control-Allow-Origin', '*')

        web.header('Access-Control-Allow-Credentials', 'true')

        web.header('Content-Type', 'application/json')

        cursor = connection.cursor()

        cursor.arraysize = 100000  # default = 50

        cursor.execute(

            """SELECT a.id , a.json2, d.Classname FROM   building a, THEMATIC_SURFACE b, SURFACE_GEOMETRY c, OBJECTCLASS d  WHERE  a.grid_id_500 = 2728 AND a.id = b.BUILDING_ID AND b.LOD2_MULTI_SURFACE_ID = c.ROOT_ID AND c.GEOMETRY IS NOT NULL           AND b.OBJECTCLASS_ID = d.ID""")

       obj = cursor.fetchone()

       print obj

        result = []

        for id, json2, classname in cursor:

            result.append({

                "building_nr":id,"geometry": {

                  "type":"polygon","coordinates":json2,}, "polygon_typ":classname,})

  return result

if __name__ == "__main__":

    app.run(web.profiler)

For json2 I get no values:

[{'building_nr': 1314867, 'geometry': {'type': 'polygon', 'coordinates': None}, 'polygon_typ': 'BuildingWallSurface'},....

What is wrong?

Answers

  • Gaz in Oz
    Gaz in Oz Member Posts: 3,785 Bronze Crown
    edited Aug 2, 2016 9:24PM

    Hi limor,

    what does the query return if you run it in sqlplus or sqldeveloper?

    Does the column "a.json2" hold a value?

    Cheers,

    Gaz.

  • limor
    limor Member Posts: 38
    edited Aug 3, 2016 4:44AM

    Hey Gaz,

    if I run the query :  SELECT a.id , a.json2, d.Classname FROM   building a, THEMATIC_SURFACE b, SURFACE_GEOMETRY c, OBJECTCLASS d  WHERE  a.grid_id_500 = 2728 AND a.id = b.BUILDING_ID AND b.LOD2_MULTI_SURFACE_ID = c.ROOT_ID AND c.GEOMETRY IS NOT NULL AND b.OBJECTCLASS_ID = d.ID

    I get this result in sqldeveloper: type=VARCHAR:

    IDJSON2CLASSNAME
    1314867{"type":"Polygon","coordinates":[[[3481982,51,5384100,92,622,59],[3481984,51,5384091,11,626,54],[3482009,33,5384095,9,626,46],[3482007,21,5384106,12,622,34],[3481982,51,5384100,92,622,59]]]}BuildingWallSurface
    1314867{"type":"Polygon","coordinates":[[[3481982,51,5384100,92,622,59],[3481984,51,5384091,11,626,54],[3482009,33,5384095,9,626,46],[3482007,21,5384106,12,622,34],[3481982,51,5384100,92,622,59]]]}BuildingWallSurface

    But in cx_Oracle I get NONE vaules!!!

This discussion has been closed.