Ci-dessous, les différences entre deux révisions de la page.
| Prochaine révision | Révision précédente | ||
| dev:api:python:db_common [2017/08/25 14:12] – créée florian | dev:api:python:db_common [2023/06/13 13:46] (Version actuelle) – [Exemples] florian | ||
|---|---|---|---|
| Ligne 3: | Ligne 3: | ||
| ===== dbgenericselectindict ===== | ===== dbgenericselectindict ===== | ||
| + | generic function to select multiple records and return them in a dict | ||
| + | |||
| + | >>> | ||
| + | Execute query : select fld1, | ||
| + | >>> | ||
| + | [8 : | ||
| + | |||
| + | ==== Paramètres ==== | ||
| + | |||
| + | ^ Paramètre ^ Type ^ Default ^ Description ^ | ||
| + | | **usession** | session | ||
| + | | **itbl** | string | ||
| + | | **ifldkey** | string | ||
| + | | **iflds** | list | None | fields to put values in | | ||
| + | | **iorder** | string | ||
| + | | **isens** | " | ||
| + | | **iorderother** | string | ||
| + | | **isensother** | " | ||
| + | | **ifldcond** | string | ||
| + | | **ifldcondval** | undefined | ||
| + | | **ifldop** | string | ||
| + | | **ifldcond2** | string | ||
| + | | **ifldcondval2** | undefined | ||
| + | | **ifldop2** | string | ||
| + | | **dbtype** | | None | | | ||
| + | | **ifldcond3** | | | | | ||
| + | | **ifldcondval3** | | | | | ||
| + | | **ifldop3** | | = | | | ||
| + | |||
| + | |||
| + | ==== Retour ==== | ||
| + | |||
| + | ^ Type de retour ^ Valeur de retour ^ | ||
| + | | dict | dictionary containing recordset | | ||
| + | |||
| + | {{: | ||
| + | |||
| + | ==== Exemples ==== | ||
| + | |||
| + | Par exemple si l'on veut sélectionner tout les enregistrements de la table facture sans spécifier d' | ||
| + | <code python> | ||
| + | vdict = db_common.dbgenericselectindict(gses, | ||
| + | print vdict | ||
| + | </ | ||
| + | |||
| + | On obtiendra | ||
| + | <code python> | ||
| + | {" | ||
| + | " | ||
| + | </ | ||
| + | |||
| + | |||
| + | ===== dbgenericselect ===== | ||
| + | |||
| + | generic function to fetch record in a system table on a primary key | ||
| + | |||
| + | >>> | ||
| + | Execute query : select fld1, | ||
| + | |||
| + | ==== Paramètres ==== | ||
| + | |||
| + | ^ Paramètre ^ Type ^ Default ^ Description ^ | ||
| + | | **usession** | session | ||
| + | | **itbl** | string | ||
| + | | **iidval** | long | None | Primary Key of record to get | | ||
| + | | **itblfld** | string multiple | ||
| + | |||
| + | |||
| + | ==== Retour ==== | ||
| + | |||
| + | ^ Type de retour ^ Valeur de retour ^ | ||
| + | | list, | ||
| + | |||
| + | ===== dbgenericgetvalue ===== | ||
| + | |||
| + | Retourne la valeur de la colonne souhaitée du premier enregistrement qui satisfait les filtres. | ||
| + | |||
| + | ==== Paramètres ==== | ||
| + | |||
| + | ^ Paramètre ^ Type ^ Default ^ Description ^ | ||
| + | | **usession** | session | ||
| + | | **itbl** | string | ||
| + | | **ifldkey** | string | ||
| + | | **ifldkeyval** | value | None | Valeur du premier filtre | ||
| + | | **ifldtoreturn** | string | ||
| + | | **ifldkey2** | string | ||
| + | | **ifldkeyval2** | value | | Valeur du deuxième filtre | ||
| + | | **ifldkey3** | string | ||
| + | | **ifldkeyval3** | value | ||
| + | | **ifldkey4** | string | ||
| + | | **ifldkeyval4** | value | ||
| + | |||
| + | |||
| + | ==== Retour ==== | ||
| + | |||
| + | ^ Type de retour ^ Valeur de retour ^ | ||
| + | | | La valeur trouvée ou None | | ||
| + | |||
| + | ==== Exemples ==== | ||
| + | |||
| + | Par exemple si l'on veut obtenir le nom du client dont le numéro est 1005: | ||
| <code python> | <code python> | ||
| - | dbgenericselectindict(usession, | + | nomclient = db_common.dbgenericgetvalue( |
| - | itbl, | + | usession |
| - | ifldkey, | + | itbl = "facture", |
| - | iflds, | + | ifldkey |
| - | iorder, | + | ifldkeyval |
| - | isens="A", | + | ifldkey2 |
| - | | + | ifldkeyval2 |
| - | | + | ifldtoreturn |
| - | | + | ) |
| - | | + | |
| - | | + | |
| - | | + | |
| - | ifldcondval2="", | + | |
| - | ifldop2=" | + | |
| - | dbtype=None, | + | |
| - | ifldcond3="", | + | |
| - | ifldcondval3="", | + | |
| - | ifldop3=" | + | |
| </ | </ | ||
| - | === Paramètres === | ||
| - | * usession => L' | ||
| - | * itbl => Nom de la table source | ||
| - | * ifldkey => Champ de la table qui servira de clé au dictionnaire résultat | ||
| - | * iflds => Liste des champs à inclure dans le résultat | ||
| - | * iorder => Champ | ||
| - | * isens=" | ||
| - | * iorderother="" | ||
| - | * isensother=" | ||
| - | * ifldcond="" | ||
| - | * ifldcondval="" | ||
| - | * ifldop=" | ||
| - | * ifldcond2="" | ||
| - | * ifldcondval2="" | ||
| - | * ifldop2=" | ||
| - | * dbtype=None => | ||
| - | * ifldcond3="" | ||
| - | * ifldcondval3="" | ||
| - | * ifldop3=" | ||