Outils pour utilisateurs

Outils du site


dev:api:python:db_common

Ceci est une ancienne révision du document !


db_common

dbgenericselectindict

generic function to select multiple records and return them in a dict

ret=db_common.dbgenericselectindict(session,“test”,“test_id”,[“fld1”,“fld2”,“fldx”],“fld”,“A”,“fld2”,“D”,“fld2”,2,“>”)

Execute query : select fld1,fld2,fldx,test_id from test where fld2 > 2 order by fldx ASC, fld2 DESC; and put results in a dict

print ret

[8 :[“fld1” : “foo”, “fld2” : 4, “fldx” : “bar”],9 :[“fld1” : “foox”, “fld2” : 3, “fldx” : “cbar”],….] keys 8,9 are test_id values

Paramètres

Paramètre Type Default Description
usession session None NCHP Session
itbl string None table to fetch
ifldkey string None fields that wil be key for return dict
iflds list None fields to put values in
iorder string None Field for default sort
isens “A” or “D” A sort ascendant or descendant
iorderother string optional second sort
isensother “A” or “D” A sort ascendant or descendant for second sort
ifldcond string optional field to check in where clause
ifldcondval undefined optional value for field to check in where clause
ifldop string = optional operator for field to check in where clause
ifldcond2 string optional second field to check in where clause
ifldcondval2 undefined optional second value for field to check in where clause
ifldop2 string = optional second operator for field to check in where clause
dbtype None
ifldcond3
ifldcondval3
ifldop3 =

Retour

Type de retour Valeur de retour
dict dictionary containing recordset

Ne vous fiez pas aux paramètres d'ordre car le résultat étant un dictionnaire, l'ordre des clés/valeurs dans un dictionnaire en Python est arbitraire (et vous ne pourrez pas le connaitre).

Exemples

Par exemple si l'on veut sélectionner tout les enregistrements de la table facture sans spécifier d'ordre ou de conditions:

vdict = db_common.dbgenericselectindict(gses, "facture", "FACTURE_ID", ["FACTURE_NUM","FACTURE_DATE","FACTURE_TTC"])
print vdict

On obtiendra

{"7":{"FACTURE_NUM":"F001013",FACTURE_DATE:"2017-08-28 00:00:00","FACTURE_TTC":2450.30}, 
 "8":{"FACTURE_NUM":"F001027",FACTURE_DATE:"2017-08-31 00:00:00","FACTURE_TTC":1370.0}}

dbgenericselect

generic function to fetch record in a system table on a primary key

ret=db_common.dbgenericselect(session,“test”,32,“fld1”,“fld2”,“fldx”)

Execute query : select fld1,fld2,fldx from test where test_id=32;

Paramètres

Paramètre Type Default Description
usession session None NCHP Session
itbl string None table to fetch
iidval long None Primary Key of record to get
itblfld string multiple None fields to get

Retour

Type de retour Valeur de retour
list,description row selected , description of fields (datatype etc) : see description in db modules (db_mysql,db_postgres etc….)
dev/api/python/db_common.1505123935.txt.gz · Dernière modification: 2023/03/17 09:56 (modification externe)