/** * Obtient le nom de la table ainsi que sa ou ses clés primaires * * @param string $type * Table sur laquelle s'applique le crayon. * Ce type peut contenir le nom d'un connecteur distant tel que `{connect}__{table}` * * @return array|bool * - false si on ne trouve pas de table ou de table ayant de clé primaire * - liste : * - - nom de la table sql * - - tableau des noms de clés primaires **/ function crayons_get_table_name_and_primary($type) { static $types = array(); if (isset($types[$type])) { return $types[$type]; } $nom_table = ''; if ($tabref =& crayons_get_table($type, $nom_table) and $tabid = explode(',', $tabref['key']['PRIMARY KEY'])) { return $types[$type] = array($nom_table, $tabid); } spip_log('crayons: table ' . $type . ' inconnue'); return $types[$type] = false; }
function table_where($type, $id, $where_en_tableau = false) { list($distant,$table) = distant_table($type); $nom_table = ''; if (!(($tabref = &crayons_get_table($type, $nom_table)) && ($tabid = explode(',', $tabref['key']['PRIMARY KEY'])))) { spip_log('crayons: table ' . $table . ' inconnue'); return array(false, false); } if (is_scalar($id)) { $id = explode('-', $id); } // sortie tableau pour sql_updateq if ($where_en_tableau) { $where = array(); foreach ($id as $idcol => $idval) { $where[] = '`' . (is_int($idcol) ? trim($tabid[$idcol]) : $idcol) . '`=' . sql_quote($idval); } // sinon sortie texte pour sql_query } else { $where = $and = ''; foreach ($id as $idcol => $idval) { $where .= $and . '`' . (is_int($idcol) ? trim($tabid[$idcol]) : $idcol) . '`=' . _q($idval); $and = ' AND '; } } return array($nom_table, $where); }