cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Neo4j Driver - Query result to pyQT5 comboBox

I am trying to get a query result using NEO4j driver to populate a PyQt5 comboBox.

I believe I am on the right track, however run in the challenge to convert the query result to a list that can be loaded in self.comboBox.addItems(list).

this is what I got sofar:
main.py


DatabaseConn.py

I tried str and list to return result. but end up with a method issue and now this one

any help to put me in the right direction is appreciated.

3 REPLIES 3

MuddyBootsCode
Graph Steward

Have you tried to see what you're getting back from the query? Like the type that it returns? You might be getting an object back rather than something you can just make into a string. Check that out and see.

Have tried the NEO4j driver, unfortunately was not able to produce a return value. However swapped to py2neo and was more successful to get a record back. The code.

this returns this.

2X_1_133cb1e1f900d211e8d0f9acc8948a25d66fab5c.png

correct me if I am wrong, but I believe this is a list containing a dict?

anyway managed to get it down to a list. but now having a challange getting this in the pyQT5 combobox. I guess I will try their forum to help me out here. if somebody here has a idea on how to convert a python list to Qtstringlist I am all ears.

many thanks

MuddyBootsCode
Graph Steward

OK after playing around with this for a bit it looks like where you're running into problems is how you've structured your query by just returning the name or even as name you're returning something a little different than you think. What you need to do is return the entire member so:

match (m:Member) return m

and then you can pull the name off the record object returned. Now bear in mind I'm doing with the neo4j python driver and not the py2neo driver but on a similar query this is what happens for me. In my use case I'm querying a list of wells so I do this, I have a function I call:

def get_wells(tx):
    wells = []
    for record in tx.run('MATCH (w:Well)'
                         'return w'):
        wells.append(record)
    return wells

which returns a neo4j record object. I can then loop through the resulting records by doing:

for well in wells:
    print(well['w']['name'])

This works because it returns a full record object from neo4j. When I tried it your way:

def get_well_names(tx):
    wells = []
    for record in tx.run(
        '''
            MATCH (w:Well)
            return w.name as name
        '''
    ):
        wells.append(record)
    return wells

I received a different object back that had the key of w.name but not actually the name itself. So maybe give that a try just remember that whatever you return from the function the starting key of that record object will be that. In my case when I say return

w

then that's the key for the record. I can then get the properties:

print(well['w'].__dict__)
_graph': <neo4j.types.graph.Graph object at 0x10b5c3190>,
 '_id': 36885,
 '_labels': {'Well'},
 '_properties': {'OGL': 'Adobe 1967-12-26',
                 'abstract': '1025',
                 'checkString': '{"api_number": "4247536868", "Field": '
                                '"PHANTOM", "producing_date": '
                                '"2016-06-01T00:00:00Z", "Operator": '
                                '"CONCHOOPERATING", "Entities": "129529900", '
                                '"reported_operator": "COGOPERATINGLLC", '
                                '"target_formation": "WOLFCAMP", '
                                '"well_status": "ACTIVE"}',
                 'completionDate': '2015-05-24',
                 'county': 'Ward',
                 'dateInPay': '2017-03-01',
                 'dateProducing': '2016-06-01',
                 'dpu': 'V1052 P753',
                 'drillType': 'H',
                 'familyID': '1305-00',
                 'id': '42-475-36868',
                 'inService': True,
                 'inactive': False,
                 'landId': 'TX-W-B33-S35',
                 'latitude': '31.443879',
                 'latitudeBottom': '31.4328446',
                 'lengthOfLateral': '4955 ft, 0.94 miles',
                 'lmsltDOI': '0.00275953',
                 'longitude': '-103.3354631',
                 'longitudeBottom': '-103.3472174',
                 'lowerPerf': '15890',
                 'mesDOI': '0.00275953',
                 'mpiDivOrder': '2017-05-30',
                 'name': 'Barstow 33-34 1H',
                 'notes': 'Commingle Permit 7604',
                 'ogl': 'Adobe 1967-12-26',
                 'oilPayor': 'COG Operatig LLC.',
                 'operator': 'COG OPERATING LLC',
                 'p12': '2014-10-02',
                 'payor': 'COG',
                 'perfLength': '4890',
                 'permitDate': '2015-10-30',
                 'permitNumber': '797594',
                 'plat': '',
                 'platURL': 'http://monroeprop.ddns.net/WELLS/2014-10-01-Plat-Jetta-Barstow_33-34_1H_notes.pdf',
                 'producingFormation': 'WOLFCAMP',
                 'productionFormation': 'Cherry Canyon',
                 'rccField': 'Two Georges(Bone Springs) ',
                 'rigRelease': '2015-05-24',
                 'rigReleaseDate': '2015-05-24',
                 'rrcField': 'PHANTOM',
                 'rrcLeaseNumber': '47050',
                 'spudDate': '2015-04-27',
                 'state': 'Texas',
                 'status': 'Active',
                 'totalDepth': '16108',
                 'trueVerticalDepth': '10670.19',
                 'type': 'Oil',
                 'upperPerf': '11000'}}

Sorry for the long rambling post but I think the answer is in what's getting returned back to you with the method you're using. I don't think it's the name at all. I hope that helps.