Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

OpenOffice & LibreOffice Discussion :

Unexpected token dans requête INSERT INTO


Sujet :

OpenOffice & LibreOffice

  1. #1
    Membre régulier
    Unexpected token dans requête INSERT INTO
    Bonjour,
    Suite à le création d' une requête INSERT INTO et lors de son exécution, une erreur et relevé.
    Auriez-vous,dans un premier, l' amabilité de vérifier le code ci dessous afin de relever d' éventuelles erreurs de code.
    Code :Sélectionner tout -Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
     
        Sub SvgDnXf()
     
           Dim DBContext as object, DB as object,DBase as Object, Statement as object, Rqt As Object
           Dim RqtSql as string, Fch as string
     
           Fch = ConvertToURL("file:///media/elfouste/El_Casot/Yvon/Phototeque/Phototeque_HSQL.odb")
           DBContext = CreateUnoService("com.sun.star.sdb.DatabaseContext")
           DB = DBContext.getbyName(Fch)
     
           DBase = DB.getConnection("","") 
           Statement = DBase.createStatement() 
     
           RqtSql = "INSERT INTO ""T_Pht_01""(""ChmPht"",""NmPht"",""XtnPht"",""Fbc""," &_
                    """Mdl"",""TpBjc"",""DtPht"",""HrPht"",""DmsPht"",""TmpXps""," &_
                    """Fcl"",""LngFcl"",""Iso"",""Lmn"",""PstFls"",""ChmCmpPht"")" &_
                    " Values(""ChmPht"",""NmPht"",""XtnPht"",""Fbc"",""MdlApp"",""Bjc""," &_
                    """DtPht"",""HrPht"",""DmsPht"",""TmpXps"",""Fcl"",""LngFcl"",""Snc""," &_
                    """Lmn"",""PstFls"",""ChmCmpPht"" FROM ""Tp_Pht"")"
     
           Rqt = Statement.executeQuery(RqtSqL) 
     
        End sub
     
    [Base]-Unexpected tokem dans requete INSERT INTO
     
    Messagepar Ernest » 06 Sep 2019 09:31
    Bonjour,
    Suite à le création d' une requête INSERT INTO et lors de son exécution, une erreur et relevé.
    Auriez-vous,dans un premier, l' amabilité de vérifier le code ci dessous afin de relever d' éventuelles erreurs de code.
     
    Code : Tout sélectionner   Agrandir
        Sub SvgDnXf()
     
           Dim DBContext as object, DB as object,DBase as Object, Statement as object, Rqt As Object
           Dim RqtSql as string, Fch as string
     
           Fch = ConvertToURL("file:///media/elfouste/El_Casot/Yvon/Phototeque/Phototeque_HSQL.odb")
           DBContext = CreateUnoService("com.sun.star.sdb.DatabaseContext")
           DB = DBContext.getbyName(Fch)
     
           DBase = DB.getConnection("","") 
           Statement = DBase.createStatement() 
     
           RqtSql = "INSERT INTO ""T_Pht_01""(""ChmPht"",""NmPht"",""XtnPht"",""Fbc""," &_
                    """Mdl"",""TpBjc"",""DtPht"",""HrPht"",""DmsPht"",""TmpXps""," &_
                    """Fcl"",""LngFcl"",""Iso"",""Lmn"",""PstFls"",""ChmCmpPht"")" &_
                    " Values(""ChmPht"",""NmPht"",""XtnPht"",""Fbc"",""MdlApp"",""Bjc""," &_
                    """DtPht"",""HrPht"",""DmsPht"",""TmpXps"",""Fcl"",""LngFcl"",""Snc""," &_
                    """Lmn"",""PstFls"",""ChmCmpPht"" FROM ""Tp_Pht"")"
     
           Rqt = Statement.executeQuery(RqtSqL) 
     
        End sub
     
    [Base]-Unexpected tokem dans requete INSERT INTO
     
    Messagepar Ernest » 06 Sep 2019 09:31
    Bonjour,
    Suite à le création d' une requête INSERT INTO et lors de son exécution, une erreur et relevé.
    Auriez-vous,dans un premier, l' amabilité de vérifier le code ci dessous afin de relever d' éventuelles erreurs de code.
     
    Code : Tout sélectionner   Agrandir
        Sub SvgDnXf()
     
           Dim DBContext as object, DB as object,DBase as Object, Statement as object, Rqt As Object
           Dim RqtSql as string, Fch as string
     
           Fch = ConvertToURL("file:///media/elfouste/El_Casot/Yvon/Phototeque/Phototeque_HSQL.odb")
           DBContext = CreateUnoService("com.sun.star.sdb.DatabaseContext")
           DB = DBContext.getbyName(Fch)
     
           DBase = DB.getConnection("","") 
           Statement = DBase.createStatement() 
     
           RqtSql = "INSERT INTO ""T_Pht_01""(""ChmPht"",""NmPht"",""XtnPht"",""Fbc""," &_
                    """Mdl"",""TpBjc"",""DtPht"",""HrPht"",""DmsPht"",""TmpXps""," &_
                    """Fcl"",""LngFcl"",""Iso"",""Lmn"",""PstFls"",""ChmCmpPht"")" &_
                    " Values(""ChmPht"",""NmPht"",""XtnPht"",""Fbc"",""MdlApp"",""Bjc""," &_
                    """DtPht"",""HrPht"",""DmsPht"",""TmpXps"",""Fcl"",""LngFcl"",""Snc""," &_
                    """Lmn"",""PstFls"",""ChmCmpPht"" FROM ""Tp_Pht"")"
     
           Rqt = Statement.executeQuery(RqtSqL) 
     
        End sub


    L' erreur renvoyée est:
    Type: cum.sun.star.Sdbc.SQL Exception
    Message: Unexpected token : From in statement [INSERT INTO ""T_Pht_01""(""ChmPht"",""NmPht"",""XtnPht"",""Fbc""," &_ """Mdl"",""TpBjc"",""DtPht"",""HrPht"",""DmsPht"",""TmpXps""," &_ """Fcl"",""LngFcl"",""Iso"",""Lmn"",""PstFls"",""ChmCmpPht"")" &_ " Values(""ChmPht"",""NmPht"",""XtnPht"",""Fbc"",""MdlApp"",""Bjc""," &_ """DtPht"",""HrPht"",""DmsPht"",""TmpXps"",""Fcl"",""LngFcl"",""Snc""," &_ """Lmn"",""PstFls"",""ChmCmpPht"" FROM]


    Ce qui me parait bizarre, c' est que le code de l' erreur me renvoie la presque totalité de la requête mais omet la partie après le "FROM".

    Pour info, je suis sous Xubuntu 18.04 et Libreoffice 6.02. Le moteur de la base est en HSQL.

    Cordialement

  2. #2
    Membre régulier
    Pas de From dans INSERT INTO
    Bonsoir,

    Le problème est que l ' on ne peut pas utiliser FROM dans une requête INSERT INTO. Voici donc le code modifié qui, lui, me permet d' enregistrer les données d' une table dans une autre table.
    Code :Sélectionner tout -Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    RqtSql = "INSERT INTO ""T_Pht""(""ChmPht"",""NmPht"",""XtnPht"",""Fbc"","&_
    				"""Mdl"",""TpBjc"",""DtPht"",""HrPht"",""DmsPht"",""TmpXps"","&_
    				"""Fcl"",""LngFcl"",""Iso"",""Lmn"",""PstFls"",""ChmCmpPht"")"&_
    				" SELECT ""ChmPht"",""NmPht"",""XtnPht"",""Fbc"",""MdlApp"",""Bjc"","&_
    				"""DtPht"",""HrPht"",""DmsPht"",""TmpXps"",""Fcl"",""LngFcl"",""Iso"","&_
    				"""Lmn"",""PstFls"",""ChmCmp"" FROM ""Tp_Pht"""

    Comme vous le voyez, il faut passer par un Select ..... From....

    Cordialement

###raw>template_hook.ano_emploi###