from ..base import BaseView
from median.database import mysql_db
import logging

logger = logging.getLogger('median')


class Emplacements(BaseView):

    # TODO convertior en requete proproe, pas de table temporaire
    #      au pire utilsier une vue SQL
    def affichage(self, v_orderby_column="", v_dir=""):
        query = """
                drop table if exists t_demi_taquin
            """
        mysql_db.execute_sql(query)

        query = """
            CREATE TABLE t_demi_taquin as select x_adr, 2 AS x_demi_taquin from f_adr
            WHERE x_format<>'BAC' group by left(x_adr,length(x_adr)-4)
            having count(*)=2 And max(x_contenant)!='' and min(x_contenant)='' order by x_adr
            """
        mysql_db.execute_sql(query)
