Erro buscando dados SQL

Discussão em 'Progress 4GL' iniciado por DFResmer, Junho 20, 2011.

  1. kirchner

    kirchner Membro Participativo Moderador

    Na verdade eu queria dar uma olhada na definição da View. Consegue enviar?
  2. DFResmer

    DFResmer Membro Participativo

    Vou te passar o programa todo para analisar.

    Código:
    &ANALYZE-SUSPEND _VERSION-NUMBER UIB_v8r12 GUI
    &ANALYZE-RESUME
    &Scoped-define WINDOW-NAME W-Win
    &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _DEFINITIONS W-Win 
    /*------------------------------------------------------------------------
    
      File: 
    
      Description: from cntnrwin.w - ADM SmartWindow Template
    
      Input Parameters:
          <none>
    
      Output Parameters:
          <none>
    
      History: 
              
    ------------------------------------------------------------------------*/
    /*          This .W file was created with the Progress UIB.             */
    /*----------------------------------------------------------------------*/
    
    /* Create an unnamed pool to store all the widgets created 
         by this procedure. This is a good default which assures
         that this procedure's triggers and internal procedures 
         will execute in this procedure's storage, and that proper
         cleanup will occur on deletion of the procedure. */
    
    CREATE WIDGET-POOL.
    
    /* ***************************  Definitions  ************************** */
    
    
      /*******DBO***********/
       def var ado-null as character no-undo.
       def var ado-recordcont as integer no-undo.
       def var ado-registro as integer no-undo.
       Def var Cnxn0 as com-handle no-undo.
       Def var rs0 as com-handle no-undo.
       Def var ObjCommand0 as com-handle no-undo.
       Def var odbc-query as character no-undo.
       /*********************/
    
       DEF VAR ch-vlrent AS CHAR.
       DEF VAR ch-vlrsai AS CHAR.
       DEF VAR i-vlrent AS DEC no-undo.
       DEF VAR i-vlrsai AS DEC no-undo.
       DEF VAR i-codigo AS CHAR.
       DEF VAR i-dtaemi AS DATE.
    
    /* Parameters Definitions ---                                           */
    
    /* Local Variable Definitions ---                                       */
    
    /* _UIB-CODE-BLOCK-END */
    &ANALYZE-RESUME
    
    
    &ANALYZE-SUSPEND _UIB-PREPROCESSOR-BLOCK 
    
    /* ********************  Preprocessor Definitions  ******************** */
    
    &Scoped-define PROCEDURE-TYPE SmartWindow
    
    &Scoped-define ADM-CONTAINER WINDOW
    
    /* Name of first Frame and/or Browse and/or first Query                 */
    &Scoped-define FRAME-NAME fr-001
    
    /* Standard List Definitions                                            */
    &Scoped-Define ENABLED-OBJECTS fi-item fi-saldo BUTTON-1 fi-conta 
    &Scoped-Define DISPLAYED-OBJECTS fi-item fi-saldo fi-conta 
    
    /* Custom List Definitions                                              */
    /* List-1,List-2,List-3,List-4,List-5,List-6                            */
    
    /* _UIB-PREPROCESSOR-BLOCK-END */
    &ANALYZE-RESUME
    
    
    
    /* ***********************  Control Definitions  ********************** */
    
    /* Define the widget handle for the window                              */
    DEFINE VAR W-Win AS WIDGET-HANDLE NO-UNDO.
    
    /* Definitions of the field level widgets                               */
    DEFINE BUTTON BUTTON-1 
         LABEL "Calcular" 
         SIZE 15 BY 1.14.
    
    DEFINE VARIABLE fi-conta AS INTEGER FORMAT "->,>>>,>>9":U INITIAL 0 
         LABEL "Conta" 
         VIEW-AS FILL-IN 
         SIZE 14 BY 1.14 NO-UNDO.
    
    DEFINE VARIABLE fi-item AS CHARACTER FORMAT "X(256)":U 
         LABEL "Codigo" 
         VIEW-AS FILL-IN 
         SIZE 16 BY 1.14 NO-UNDO.
    
    DEFINE VARIABLE fi-saldo AS DECIMAL FORMAT "->>,>>9.99":U INITIAL 0 
         LABEL "Saldo" 
         VIEW-AS FILL-IN 
         SIZE 16 BY 1 NO-UNDO.
    
    
    /* ************************  Frame Definitions  *********************** */
    
    DEFINE FRAME fr-001
         fi-item AT ROW 2.67 COL 29 COLON-ALIGNED
         fi-saldo AT ROW 4.1 COL 29 COLON-ALIGNED
         BUTTON-1 AT ROW 5.76 COL 31
         fi-conta AT ROW 9.33 COL 29 COLON-ALIGNED
        WITH 1 DOWN NO-BOX KEEP-TAB-ORDER OVERLAY 
             SIDE-LABELS NO-UNDERLINE THREE-D 
             AT COL 1 ROW 1
             SIZE 80 BY 17
             FONT 11.
    
    
    /* *********************** Procedure Settings ************************ */
    
    &ANALYZE-SUSPEND _PROCEDURE-SETTINGS
    /* Settings for THIS-PROCEDURE
       Type: SmartWindow
       Allow: Basic,Browse,DB-Fields,Query,Smart,Window
     */
    &ANALYZE-RESUME _END-PROCEDURE-SETTINGS
    
    /* *************************  Create Window  ************************** */
    
    &ANALYZE-SUSPEND _CREATE-WINDOW
    IF SESSION:DISPLAY-TYPE = "GUI":U THEN
      CREATE WINDOW W-Win ASSIGN
             HIDDEN             = YES
             TITLE              = "<insert SmartWindow title>"
             HEIGHT             = 17
             WIDTH              = 80
             MAX-HEIGHT         = 17
             MAX-WIDTH          = 80
             VIRTUAL-HEIGHT     = 17
             VIRTUAL-WIDTH      = 80
             RESIZE             = no
             SCROLL-BARS        = no
             STATUS-AREA        = no
             BGCOLOR            = ?
             FGCOLOR            = ?
             THREE-D            = yes
             MESSAGE-AREA       = no
             SENSITIVE          = yes.
    ELSE {&WINDOW-NAME} = CURRENT-WINDOW.
    /* END WINDOW DEFINITION                                                */
    &ANALYZE-RESUME
    
    
    /* ***************  Runtime Attributes and UIB Settings  ************** */
    
    &ANALYZE-SUSPEND _RUN-TIME-ATTRIBUTES
    /* SETTINGS FOR WINDOW W-Win
      VISIBLE,,RUN-PERSISTENT                                               */
    /* SETTINGS FOR FRAME fr-001
                                                                            */
    IF SESSION:DISPLAY-TYPE = "GUI":U AND VALID-HANDLE(W-Win)
    THEN W-Win:HIDDEN = yes.
    
    /* _RUN-TIME-ATTRIBUTES-END */
    &ANALYZE-RESUME
    
     
    
    
    &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _INCLUDED-LIB W-Win 
    /* ************************* Included-Libraries *********************** */
    
    {src/adm/method/containr.i}
    
    /* _UIB-CODE-BLOCK-END */
    &ANALYZE-RESUME
    
    
    
    
    /* ************************  Control Triggers  ************************ */
    
    &Scoped-define SELF-NAME W-Win
    &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL W-Win W-Win
    ON END-ERROR OF W-Win /* <insert SmartWindow title> */
    OR ENDKEY OF {&WINDOW-NAME} ANYWHERE DO:
      /* This case occurs when the user presses the "Esc" key.
         In a persistently run window, just ignore this.  If we did not, the
         application would exit. */
      IF THIS-PROCEDURE:PERSISTENT THEN RETURN NO-APPLY.
    END.
    
    /* _UIB-CODE-BLOCK-END */
    &ANALYZE-RESUME
    
    
    &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL W-Win W-Win
    ON WINDOW-CLOSE OF W-Win /* <insert SmartWindow title> */
    DO:
      /* This ADM code must be left here in order for the SmartWindow
         and its descendents to terminate properly on exit. */
      APPLY "CLOSE":U TO THIS-PROCEDURE.
      RETURN NO-APPLY.
    END.
    
    /* _UIB-CODE-BLOCK-END */
    &ANALYZE-RESUME
    
    
    &Scoped-define SELF-NAME BUTTON-1
    &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL BUTTON-1 W-Win
    ON CHOOSE OF BUTTON-1 IN FRAME fr-001 /* Calcular */
    DO:
    
    
    ado-registro = 0.
    fi-saldo     = 0.
    
    Create "ADODB.Connection" Cnxn0.
    Create "ADODB.RecordSet" rs0.
    Create "ADODB.Command" ObjCommand0. 
    
    assign odbc-query = "Select * from vSaldoItemDia WHERE cd_item = '" + INPUT FRAME fr-001 fi-item + "' AND cd_deposito = 1".
        
                        
                        /*****comando tabelas***/
    Cnxn0:Open ( "data source=Everest_1;server=192.168.0.1\everest2", "everest", "ever", -1).
    
    assign ObjCommand0:ActiveConnection = Cnxn0.
    assign ObjCommand0:CommandText = odbc-query.
    assign objCommand0:CommandType = 1.
    assign Cnxn0:CursorLocation = 3.
    assign rs0:CursorType = 1.
    assign rs0:LockType = 3.
    assign rs0 = ObjCommand0:EXECUTE(OUTPUT ado-null,"",32).
    assign ado-recordcont = rs0:RecordCount.
    
    do transaction:
    if (ado-recordcont > 0) and not (ado-recordcont = ?) then do:
    rs0:MoveFirst no-error.
    
    do while ado-registro < ado-recordcont:
         i-vlrent = DEC(string(rs0:FIELDS("qt_entrada"):value)).
         i-vlrsai = DEC(string(rs0:FIELDS("qt_saida"):value)).
         i-codigo = (STRING(rs0:FIELDS("cd_item"):value)).
         i-dtaemi = DATE(STRING(rs0:FIELDS("dt_saldo"):value)).
         fi-conta = fi-conta + 1.
         IF i-vlrent = ? THEN i-vlrent = 0.
         IF i-vlrsai = ? THEN i-vlrsai = 0.
         fi-saldo = fi-saldo + i-vlrent - i-vlrsai.
                 
    assign ado-registro = ado-registro + 1.
    rs0:MoveNext.
    end.
    
    end.
    else
    message "Não Encontrado Lançamentos".
    end.
    
    ObjCommand0:CLOSE no-error.
    release OBJECT Cnxn0 no-error.
    release OBJECT ObjCommand0 no-error.
    release OBJECT rs0 no-error.
    assign Cnxn0 = ? ObjCommand0 = ? rs0 = ?.
    
      DISPLAY fi-saldo fi-conta WITH FRAME fr-001.
    
      
    END.
    
    /* _UIB-CODE-BLOCK-END */
    &ANALYZE-RESUME
    
    
    &UNDEFINE SELF-NAME
    
    &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _MAIN-BLOCK W-Win 
    
    
    /* ***************************  Main Block  *************************** */
    
    /* Include custom  Main Block code for SmartWindows. */
    {src/adm/template/windowmn.i}
    
    /* _UIB-CODE-BLOCK-END */
    &ANALYZE-RESUME
    
    
    /* **********************  Internal Procedures  *********************** */
    
    &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE adm-create-objects W-Win _ADM-CREATE-OBJECTS
    PROCEDURE adm-create-objects :
    /*------------------------------------------------------------------------------
      Purpose:     Create handles for all SmartObjects used in this procedure.
                   After SmartObjects are initialized, then SmartLinks are added.
      Parameters:  <none>
    ------------------------------------------------------------------------------*/
    
    END PROCEDURE.
    
    /* _UIB-CODE-BLOCK-END */
    &ANALYZE-RESUME
    
    
    &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE adm-row-available W-Win _ADM-ROW-AVAILABLE
    PROCEDURE adm-row-available :
    /*------------------------------------------------------------------------------
      Purpose:     Dispatched to this procedure when the Record-
                   Source has a new row available.  This procedure
                   tries to get the new row (or foriegn keys) from
                   the Record-Source and process it.
      Parameters:  <none>
    ------------------------------------------------------------------------------*/
    
      /* Define variables needed by this internal procedure.             */
      {src/adm/template/row-head.i}
    
      /* Process the newly available records (i.e. display fields,
         open queries, and/or pass records on to any RECORD-TARGETS).    */
      {src/adm/template/row-end.i}
    
    END PROCEDURE.
    
    /* _UIB-CODE-BLOCK-END */
    &ANALYZE-RESUME
    
    
    &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE disable_UI W-Win _DEFAULT-DISABLE
    PROCEDURE disable_UI :
    /*------------------------------------------------------------------------------
      Purpose:     DISABLE the User Interface
      Parameters:  <none>
      Notes:       Here we clean-up the user-interface by deleting
                   dynamic widgets we have created and/or hide 
                   frames.  This procedure is usually called when
                   we are ready to "clean-up" after running.
    ------------------------------------------------------------------------------*/
      /* Delete the WINDOW we created */
      IF SESSION:DISPLAY-TYPE = "GUI":U AND VALID-HANDLE(W-Win)
      THEN DELETE WIDGET W-Win.
      IF THIS-PROCEDURE:PERSISTENT THEN DELETE PROCEDURE THIS-PROCEDURE.
    END PROCEDURE.
    
    /* _UIB-CODE-BLOCK-END */
    &ANALYZE-RESUME
    
    
    &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE enable_UI W-Win _DEFAULT-ENABLE
    PROCEDURE enable_UI :
    /*------------------------------------------------------------------------------
      Purpose:     ENABLE the User Interface
      Parameters:  <none>
      Notes:       Here we display/view/enable the widgets in the
                   user-interface.  In addition, OPEN all queries
                   associated with each FRAME and BROWSE.
                   These statements here are based on the "Other 
                   Settings" section of the widget Property Sheets.
    ------------------------------------------------------------------------------*/
      DISPLAY fi-item fi-saldo fi-conta 
          WITH FRAME fr-001 IN WINDOW W-Win.
      ENABLE fi-item fi-saldo BUTTON-1 fi-conta 
          WITH FRAME fr-001 IN WINDOW W-Win.
      {&OPEN-BROWSERS-IN-QUERY-fr-001}
      VIEW W-Win.
    END PROCEDURE.
    
    /* _UIB-CODE-BLOCK-END */
    &ANALYZE-RESUME
    
    
    &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE local-exit W-Win 
    PROCEDURE local-exit :
    /* -----------------------------------------------------------
      Purpose:  Starts an "exit" by APPLYing CLOSE event, which starts "destroy".
      Parameters:  <none>
      Notes:    If activated, should APPLY CLOSE, *not* dispatch adm-exit.   
    -------------------------------------------------------------*/
       APPLY "CLOSE":U TO THIS-PROCEDURE.
       
       RETURN.
           
    END PROCEDURE.
    
    /* _UIB-CODE-BLOCK-END */
    &ANALYZE-RESUME
    
    
    &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE send-records W-Win _ADM-SEND-RECORDS
    PROCEDURE send-records :
    /*------------------------------------------------------------------------------
      Purpose:     Send record ROWID's for all tables used by
                   this file.
      Parameters:  see template/snd-head.i
    ------------------------------------------------------------------------------*/
    
      /* SEND-RECORDS does nothing because there are no External
         Tables specified for this SmartWindow, and there are no
         tables specified in any contained Browse, Query, or Frame. */
    
    END PROCEDURE.
    
    /* _UIB-CODE-BLOCK-END */
    &ANALYZE-RESUME
    
    
    &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE state-changed W-Win 
    PROCEDURE state-changed :
    /* -----------------------------------------------------------
      Purpose:     
      Parameters:  <none>
      Notes:       
    -------------------------------------------------------------*/
      DEFINE INPUT PARAMETER p-issuer-hdl AS HANDLE NO-UNDO.
      DEFINE INPUT PARAMETER p-state AS CHARACTER NO-UNDO.
    END PROCEDURE.
    
    /* _UIB-CODE-BLOCK-END */
    &ANALYZE-RESUME
  3. kirchner

    kirchner Membro Participativo Moderador

    Cara, adaptei teu código para rodar aqui e não tive problemas.
    A única incógnita é o teu SELECT *.

    Me manda a definição/estrutura do objeto vSaldoItemDia.
  4. DFResmer

    DFResmer Membro Participativo

    Não consigo anexar o banco de dados que estou tentando fazer a conexão, coloquei em access.
    Tem algum email que possa te passar?
    Att,
    Diogo

Compartilhe esta Página