working on it ...

Filters

Explore Public Snippets

Sort by

Found 6,653 snippets matching: query

    public by fabiopagoti modified Apr 22, 2011  194945  0  4  0

    Post: Object Services - Parte 3 - Query Service (Serviço de Consulta)

    Post: Object Services - Parte 3 - Query Service (Serviço de Consulta): Z_ABAP101_OS_QUERY
    **&---------------------------------------------------------------------*
    *& Report  Z_ABAP101_OS_PERSISTENCE
    *&
    *&---------------------------------------------------------------------*
    *& Este programa busca os horários de voos de uma dada compania area
    *& utilizando o serviço de consulta (query service)
    *& Classes Persistente:  ZCL_AIRLINE e ZCL_FLIGHT_SCHEDULE
    *& Classes Agente:       ZCA_AIRLINE e ZCA_FLIGHT_SCHEDULE
    *& Tabelas Base:         SCARR e SPFLI
    *&---------------------------------------------------------------------*
    
    REPORT  z_abap101_os_query MESSAGE-ID z_abap101_os.
    
    " Agentes
    DATA: o_airline_agent TYPE REF TO zca_airline,
          o_flight_schedule_agent TYPE REF TO zca_flight_schedule.
    
    " Objetos persistentes
    DATA: o_airline TYPE REF TO zcl_airline,
          o_flight_schedule TYPE REF TO zcl_flight_schedule.
    
    " Objects of Query Service
    DATA: o_query_manager TYPE REF TO cl_os_query_manager,
          o_query TYPE REF TO if_os_query,
          o_ref TYPE osref,
          i_o_ref TYPE osreftab.
    
    " Auxiliar for getters
    DATA: v_connid    TYPE spfli-connid,
          v_countryfr TYPE spfli-countryfr,
          v_countryto TYPE spfli-countryto.
    
    **********************************************************************
    * Selection Screen
    **********************************************************************
    SELECTION-SCREEN BEGIN OF BLOCK block_1 WITH FRAME TITLE text-001.
    
    SELECTION-SCREEN SKIP 1.
    
    SELECTION-SCREEN BEGIN OF LINE.
    
    SELECTION-SCREEN POSITION 1.
    SELECTION-SCREEN COMMENT 2(7) text-002.
    SELECTION-SCREEN POSITION 9.
    PARAMETERS: lb_airli TYPE s_carr_id AS LISTBOX VISIBLE LENGTH 25 USER-COMMAND listbox.
    SELECTION-SCREEN COMMENT 35(8) text-003. " Currency
    SELECTION-SCREEN COMMENT 44(30) v_currco.
    
    SELECTION-SCREEN END OF LINE.
    
    SELECTION-SCREEN BEGIN OF LINE.
    
    SELECTION-SCREEN COMMENT 35(8) text-004. " Website
    SELECTION-SCREEN COMMENT 44(30) v_url.
    
    SELECTION-SCREEN END OF LINE.
    
    SELECTION-SCREEN SKIP 1.
    
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN POSITION 1.
    PARAMETERS: ch_inter AS CHECKBOX DEFAULT abap_true USER-COMMAND dest_internal.
    SELECTION-SCREEN COMMENT 3(8) text-005. " Internal Flights
    SELECTION-SCREEN POSITION 12.
    SELECTION-SCREEN COMMENT 13(4) v_inter. " Number of Internal Flights
    
    SELECTION-SCREEN END OF LINE.
    
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN POSITION 1.
    PARAMETERS: ch_exter AS CHECKBOX DEFAULT abap_true USER-COMMAND dest_external.
    SELECTION-SCREEN COMMENT 3(8) text-006. " External Flights
    SELECTION-SCREEN POSITION 12.
    SELECTION-SCREEN COMMENT 13(4) v_exter. " Number of Internal Flights
    SELECTION-SCREEN END OF LINE.
    
    SELECTION-SCREEN END OF BLOCK block_1.
    
    
    INITIALIZATION.
      " Get Agent Instance (it uses a singleton)
      o_airline_agent = zca_airline=>agent.
    
    AT SELECTION-SCREEN.
    *  o_airline_agent = zca_airline=>agent. (Wow! Not needed!)
      TRY.
          CALL METHOD o_airline_agent->get_persistent
            EXPORTING
              i_carrid = lb_airli
            RECEIVING
              result   = o_airline.
    
          v_currco = o_airline->get_currcode( ).
          v_url = o_airline->get_url( ).
    
        CATCH cx_os_object_not_found .
    
      ENDTRY.
    
    START-OF-SELECTION.
    
      " Get Agent Instance (it uses a singleton)
      o_flight_schedule_agent = zca_flight_schedule=>agent.
      o_query_manager = cl_os_query_manager=>get_query_manager( ).
    
      TRY.
          CALL METHOD o_query_manager->if_os_query_manager~create_query
            EXPORTING
              i_filter     = `CARRID = PAR1`
    *      i_ordering   =
    *      i_parameters =
            RECEIVING
              result       = o_query
              .
        CATCH cx_os_class_not_found .
      ENDTRY.
    
      TRY.
          CALL METHOD o_flight_schedule_agent->if_os_ca_persistency~get_persistent_by_query
            EXPORTING
              i_query         = o_query
    *    i_parameter_tab =
        i_par1          = lb_airli
    *    i_par2          =
    *    i_par3          =
    *    i_subclasses    = OSCON_FALSE
    *    i_upto          = 0
            RECEIVING
              result          = i_o_ref
              .
        CATCH cx_os_object_not_found .
        CATCH cx_os_query_error .
      ENDTRY.
    
      IF i_o_ref IS INITIAL.
        MESSAGE s005. " No flights shedules match selection
      ENDIF.
    
    **********************************************************************
    * output
    **********************************************************************
    
        FORMAT COLOR 7.
        WRITE:
          AT 1 'Airline',
          AT 10 'I/E',
          AT 15 'Conn No',
          AT 25 'From',
          AT 30 'To'.
    
        NEW-LINE.
        FORMAT RESET.
    
    
      IF ch_inter = abap_true.
        WRITE: AT 1 lb_airli COLOR 1.
        WRITE: /.
    
        WRITE: AT 10 'I' COLOR 2.
        NEW-LINE.
    
        LOOP AT i_o_ref INTO o_ref.
          o_flight_schedule ?= o_ref.
    
          IF o_flight_schedule->get_countryfr( ) = o_flight_schedule->get_countryto( ).
            v_connid    = o_flight_schedule->get_connid( ).
            v_countryfr = o_flight_schedule->get_countryfr( ).
            v_countryto = o_flight_schedule->get_countryto( ).
    
            WRITE: AT 15 v_connid, AT 25 v_countryfr, AT 30 v_countryto.
            NEW-LINE.
          ENDIF.
    
        ENDLOOP.
    
    
        WRITE: AT 1(30) sy-uline, /.
    
      ENDIF.
    
      IF ch_exter = abap_true.
        WRITE: AT 1 lb_airli COLOR 1.
        WRITE: /.
    
        WRITE: AT 10 'E' COLOR 2.
        NEW-LINE.
    
        LOOP AT i_o_ref INTO o_ref.
    
          o_flight_schedule ?= o_ref.
    
          IF o_flight_schedule->get_countryfr( ) <> o_flight_schedule->get_countryto( ).
            v_connid    = o_flight_schedule->get_connid( ).
            v_countryfr = o_flight_schedule->get_countryfr( ).
            v_countryto = o_flight_schedule->get_countryto( ).
    
            WRITE: AT 15 v_connid, AT 25 v_countryfr, AT 30 v_countryto.
            NEW-LINE.
          ENDIF.
    
        ENDLOOP.
    
      ENDIF.
    
    

    public by lbottaro modified Mar 26, 2015  172501  10  6  0

    curl to send a GET HTTP request with query parameters

    Try to perform a GET HTTP to snip2code server, to list the public snippets in Channels. URL example to get: https://www.snip2code.com/Explore/InChannel?q=test&sort=0&direction=1 Options: -d: list all query parameters -G: perform GET verb
    curl -v -L -G -d "q=test&sort=0&direction=1" https://www.snip2code.com/Explore/InChannel                               

    public by JaredNeil modified Jan 23, 2015  142630  0  4  0

    MySQL Query

    MySQL Query: gistfile1.sql
    SELECT *
    FROM 
    (
    	SELECT id, sort_column, numbers_column
    	FROM table_1, table_2
    	WHERE table_1.this_column = table_2.that_column
    	ORDER BY sort_column
    ) as results
    UNION ALL
    SELECT *
    FROM
    (
    	SELECT "Total" as id, "" as sort_column, SUM(numbers_column) as numbers_column
    	FROM table_1, table_2
    	WHERE table_1.this_column = table_2.that_column
    ) as total;
    
    

    public by boxshadow modified Oct 14, 2012  83027  0  3  0

    SQL Query ordering by character length.

    SQL Query ordering by character length.: charLength.sql
    SELECT 
      * 
    FROM
       badwords 
    ORDER BY CHAR_LENGTH(strBadWord) DESC 
    
    

    public by Peter Johnson a.k.a. insertcoffee modified Mar 25, 2015  75012  0  3  0

    pelias category query

    pelias category query: query.json
    GET /pelias/_search
    {
       "query": {
          "filtered": {
             "query": {
                "match": {
                   "category": {
                      "query": "food retail",
                      "analyzer": "simple", 
                      "operator" : "or"
                   }
                }
             },
             "filter": {
                "bool": {
                   "must": [
                      {
                         "geo_distance": {
                            "distance": "50km",
                            "distance_type": "plane",
                            "optimize_bbox": "indexed",
                            "_cache": true,
                            "center_point": {
                               "lat": 40.74454,
                               "lon": -73.99023
                            }
                         }
                      }
                   ]
                }
             }
          }
       },
       "size": 100,
       "sort": [
          {
             "_geo_distance": {
                "center_point": {
                   "lat": 40.74454,
                   "lon": -73.99023
                },
                "order": "asc",
                "unit": "km"
             }
          }
       ],
       "fields": ["name.default","category"],
       "track_scores": true
    }
    
    

    public by lbottaro modified Apr 4, 2014  2475  0  7  2

    How to execute a simple JPQL query in JPA

    The code shows a simple JPQL query in java. You need to instance an EntityManager object and invoke its createQuery method. This will manage a JPQL statement, where the parameters are passed using colon (:) format. Query setParameter method is used to set such parameters and getSingleResult returns the single record.
    private static final String PERSISTENCE_UNIT_NAME = "User";
    private static EntityManagerFactory factory;
    
    factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
    EntityManager em = factory.createEntityManager();
    Query q = em.createQuery("SELECT u FROM User u WHERE u.Name = :name AND u.Password = :pass");
    q.setParameter("name", userName);
    q.setParameter("pass", password);
    User user = (User) q.getSingleResult();

    public by lbottaro modified May 17, 2014  4366  10  8  3

    CSS media query for responsive web site

    Using @media you can specify which style to be applied to the page, depending on certain conditions. In this example I check the actual screen resolution, applying different styles when screen width is below a max value. This comes in hand for responsive web site (mobile or desktop applications)
    <style>
    .left{ 	
    	width: 50%; 
    	float: left
    }
    .right{ 
    	width: 50%; 
    	float: left 
    }
    
    @media (max-width: 320px){
        .left{ 
    		width: 100%; 
    		color: red; 
    	}
    	.right{ 
    		width: 100%; 
    		color: yellow; 
    		border: 2px solid green;
    		border-radius: 5px;
    	}
    }
    </style>
    <div class="left">
    <p>Using @media tag I can detect when screen resolution change to a minimum value and then switch to another specific style. When the screen gets too small, it will turn red.</p>
    </div>
    <div class="right">
    <p>Using @media tag I can detect when screen resolution change to a minimum value and then switch to another specific style. When the screen gets too small, it will turn yellow with a rounded border.</p>
    </div>

    public by cghersi modified Sep 18, 2013  5389  2  7  0

    Object Query Language for Eclipse memory analyzer

    Memory Analyzer is a tool that helps the analysis of Hprof HEAP Dumps. Using OQL you can query the information you need in a SQL-like language! Here is an example of the use. Other information can be found here: http://eclipsesource.com/blogs/2013/01/21/10-tips-for-using-the-eclipse-memory-analyzer/
    SELECT toString(l.connectionId) FROM org.apache.activemq.command.ProducerId l WHERE (toString(l.connectionId) LIKE "ID:vm.*")

    public by cghersi modified Mar 17, 2016  4128  7  7  0

    Check the missing indexes in SQL Server

    This query returns the list of missing indexes for the queries that are currently running on the server
    SELECT 
    	er.session_id,
    	er.blocking_session_id,
    	er.start_time,
    	er.status,
    	dbName = DB_NAME(er.database_id),
    	er.wait_type,
    	er.wait_time,
    	er.last_wait_type,
    	er.granted_query_memory,
    	er.reads,
    	er.logical_reads,
    	er.writes,
    	er.row_count,
    	er.total_elapsed_time,
    	er.cpu_time,
    	er.open_transaction_count,
    	s.text,
    	qp.query_plan,
    	logDate = CONVERT(DATE,GETDATE()),
    	logTime = CONVERT(TIME,GETDATE())
    FROM sys.dm_exec_requests er 
    CROSS APPLY sys.dm_exec_sql_text(er.sql_handle) s
    CROSS APPLY sys.dm_exec_query_plan(er.plan_handle) qp
    WHERE 
    	CONVERT(VARCHAR(MAX), qp.query_plan) LIKE '%<missing%'            

    public by cghersi modified Nov 20, 2014  4098  4  6  0

    Query XML fields' content in MS SQL Server

    This is the right syntax to perform XQuery queries for XML columns in a SQL Server table
    SELECT MyField.query('
      declare namespace s2c="http://www.snip2code.com/namespaces/s2c";
    	(/s2c:myroot/myelem/fieldIwant[1]/text())')
    FROM  MyTable
    • Public Snippets
    • Channels Snippets