Complex query using 'sql like' statement.

Given the following basic class structure.
public class Project {
     private String name;
     private Architecture architecture;
     private Resources resources;
     public Architecture getArchitecture();
     public void setArchitecture(Architecture architecture);
     public Resources getResources();
     public void setResources();
     public String getName();
     public void setName(String name);
public Architecture {
     private String name;
     public String getName();
     public void setName(String name);
public Resources {
     private String name;
     public String getName();
     public void setName(String name);
we want to be able to do a query like:
     find all Projects where (Project.name.indexOf("a") > 0) &&
(Project.architecture.name.indexof("b") > 0)
In essence a "like" comparison across String properties of the JDO objects.
Is it supported in KODO?? Anyone tried it out? Also, is it possible to
generate SQL type query in KODO?
rgds
NK

Note that this relies on a current bug in Kodo -- we should escape out the
'%' character, but we don't.
Some day, we'll fix that bug. But, before then, we will introduce a proper,
supported mechanism for finding records that have a string field that
contains some substring.
-Patrick
On 5/30/02 6:12 PM, "Andrew" <[email protected]> wrote:
Hi,
I wanted to perform a LIKE statement to get records where the partial string
existed in a field -> eg. select a where a.field LIKE "SPRING" - 2 records,
SpringSteen & MindSprings
I did it like this:
setFieldName("Spring");
String sFilter = "field.startsWith(%\" + getFieldName() + \"%)"; -
Extent anExtent = pm.getExtent(this.getClass(), true);
Query aQuery = pm.newQuery(this.getClass(), anExtent, sFilter);
return (Collection) aQuery.execute();
Hope it helps. oh, don't know about the generating sql query.
Nitin Kanani wrote:
Given the following basic class structure.
public class Project {
private String name;
private Architecture architecture;
private Resources resources;
public Architecture getArchitecture();
public void setArchitecture(Architecture architecture);
public Resources getResources();
public void setResources();
public String getName();
public void setName(String name);
public Architecture {
private String name;
public String getName();
public void setName(String name);
public Resources {
private String name;
public String getName();
public void setName(String name);
we want to be able to do a query like:
find all Projects where (Project.name.indexOf("a") > 0) &&
(Project.architecture.name.indexof("b") > 0)
In essence a "like" comparison across String properties of the JDO
objects.
Is it supported in KODO?? Anyone tried it out? Also, is it possible to
generate SQL type query in KODO?
rgds
NK
Patrick Linskey [email protected]
SolarMetric Inc. http://www.solarmetric.com

Similar Messages

  • Matching apostrophe's using sql LIKE

    heh anyone,
    Does anyone know how to match a string that has more than one apostrophe in it under SQL using the LIKE statement..
    eg. finding the data string "Surprise Me Bits 'N' Baskets '" in a database table?
    ...WHERE store LIKE 'Sur%' <- this doesn't work of course as it throws an SQL exception because of the '.
    regards
    JK

    It's ok, solved it. The answer if you are using it in a JSP and feeding in the string to search on is:
    String sur = from where ever...
    WHERE store LIKE " + "\"" + Sur + "%\"";
    cheers
    JK

  • Complex Query using DPL ?

    how can i do a complex Query using DPL ?
    i.e.
    select * from employee where age>25 and managerId=3 and salary>=6000 and salary <= 10000 order by id desc
    thx in advace!!
    zhangbin

    Hi zhangbin,
    This message may be useful.
    Re: How can I make queries to DB?
    --mark                                                                                                                                                                                                                                                               

  • SQL LIKE statement in JSP

    I tried to write a query in jsp page using LIKE statement. However, Apache Tomcat report back an error in the query string. I tried to run the same query style in MS Access and it works. Can someone please tell me where is the error in jsp code:
    JSP Code:
    sql = "SELECT tblStudent.firstName, tblStudent.lastName, tblStudent.studentID FROM tblStudent WHERE (((tblStudent.firstName) LIKE '%" + g_firstNameInput + "%')) ORDER BY tblStudent.firstName";
    MS Acccess:
    SELECT tblStudent.firstName, tblStudent.lastName, *
    FROM tblStudent
    WHERE (((tblStudent.firstName) Like '*e*'))
    ORDER BY tblStudent.firstName;
    PS: I tried changing from '%' to '*' already, but still does not work
    Thanks

    Don't use JSP for SQL querries... to complicated.
    1) Write a Java application that does what you want (as far as interacting with the database
    2) Isolate the database access code into its own class/classes
    3) Double check that you can then use those isolated classes inside a command line application
    4) Adapt the code you used in 3) to use those same classes from a JSP - preferrably using Java Beans and DTOs

  • Complex Query using findUsers()

    I have not run across any posting where the findUsers() or findUsersFiltered() methods were doing anything other than a simple query. Is it possible to do a complex query? For instance, find all users whose status is NOT Deleted. Or all users with a date attribute that is before a given date. Or all users with an attribute value of 'X' OR 'Y'. These are simple SQL queries. I can see how to do a series of simple queries and deal with merging or filtering the results. But wouldn't it be way more efficient to do it in the original query?
    If it is possible, can you point me to an example?
    Thanks,
    Bill

    Hi zhangbin,
    This message may be useful.
    Re: How can I make queries to DB?
    --mark                                                                                                                                                                                                                                                               

  • Complex Query using ViewCriteria tag??

    Hi
    I would like to know whether a query with combination of "And" and "Or" conditions can be achieved using ViewCriteria, CriteriaRow and Criteria tags.
    For eg: the SQL query should look like this
    select * from <table name>
    where column1 = x
    and (column2=y or column3=z);
    I tried couple of combinations using the tags but could get either "AND" or "OR" but not combination of both.
    Any suggestions would help.
    Thanks

    With the built in ViewCriteria implementation you cannot do and/or as per your example. But an equivalent query:
    where (column1 = x and column2 = y) or (column1 = x and column3 = z)
    is doable.

  • Sql Like statement

    how can i get all records starting with % ?

    Something that I found here (
    SQL Tutorial) might
    help:
    The optional ESCAPE sub-clause specifies an escape character for
    the pattern, allowing the pattern to use '%' and '_' (and the
    escape character) for matching. The ESCAPE value must be a single
    character string. In the pattern, the ESCAPE character precedes any
    character to be escaped.
    For example, to match a string ending with '%', use:
    x LIKE '%/%' ESCAPE '/'
    ..or here
    Using
    SQL Escape Sequences
    ... or here
    How
    to escape a wildcard in an SQL order with ORACLE.
    Phil

  • Can CR 2008 with XML ODBC driver using SQL CASE statement?

    Hi:
    when i use SQL Command to provide data to the report from XML file connection. I can not use CASE statement , CR always has error message about "CASE" word.
    I test the same Statement in SQL client connected to Oracle, it runs fine.
    So.. Is it driver's limitation that XML datasource can not use CASE statement inside SQL command window?
    Thanks anyone's reply in advance.
    Johnnychi

    Hi Johnny,
    CR supports what every the ODBC driver supports. The error you are getting is from the XML driver, CR is just passing it through.
    Try using an ODBC to XML driver and then a stand-alone ODBC test tool to see if your SQL works.
    If not you'll have to find another way to use the CASE statement.
    Thank you
    Don

  • Named query problem with "like" statement

    I'm having issues with a named query that contains a 'like' statement in it. I have other named queries that have like statements that have hardcoded like values in them that work fine.
    (i.e. select * from foo where foo.col1 like 'foo%' )
    But when the like value to be tested is a parameter, it doesn't seem to work at all, no matter what variation i've tried, other than no wildcards.
    (i.e.
    this DOES work
    select * from foo where foo.col1 like #fooParm
    this DOES NOT work
    select * from foo where foo.col1 like '%#fooParm%'
    Any suggestions on how to get this to work?
    Thanks in advance

    Try building your select statement in a different way.
    Instead of:
    select * from foo where foo.col1 like '%#fooParm%'
    Try something like:
    select * from foo where foo.col1 like '#fooParm'
    And include the wild cards in the parameter.
    i.e. if fooParam was 'abc', make fooParm = '%abc%'

  • SQL LIKE statement to text field fomr CF MX 6.1

    Hi.
    Here's my scenario. I am running SQL Server 2000 SP4 on a
    Windows 2003 Server running IIS 6. Using ColdFusion MX 6.1 Updater
    version.
    I am storing HTML page code (some complete, some just clips)
    in a text type field.
    I need to check to see if someone has already saved that
    exact code already before. So I do the following query:
    <cfquery name="checkforexisting"
    datasource="mydatasource">
    SELECT smallfieldtogetareturn
    FROM MyTable
    WHERE MyTextField LIKE '%#mystringoflongdata#%'
    </cfquery>
    Then to see if it posted:
    <cfif checkforexisting.RecordCount GT 0>
    do the don't clip optional processing
    </cfif>
    What is killing me is that it finds the match SOMETIMES. Just
    not ALL the time. I have tried no percent signs when passing the
    ColdFusion variable, only one on the right (which has solved these
    types of problems before).
    If I pull the record back OUT of the database in a page by
    itself (retrieving it by key field), it finds every other copy of
    the code EVERY time.
    I have put this into a stored procedure, which seemed to help
    I even have resorted to creating a temp table first with the
    clip, then running a query to retrieve the record that was just put
    in, and comparing THAT to my primary table (both have text type
    fields). The reason for this, is that if I write a single page that
    has just the retrieval of the temp record, and that compare is run,
    it finds EVERY copy of it in the primary table. I also thought that
    maybe there was a strong problem (I had tried HTMLEditFormat,
    HTMLCodeFormat, JavaCast since it was coming from a java program on
    the browser end).
    I am not terribly familiar with using large text fields, or
    dealing with these large pieces of HTML code as something to
    compare!
    - Mike

    MichaelSJudd wrote:
    As Dan indicated your most likely issue is slight differences
    in
    capitalization and|or white space or other 'invisible'
    difference
    between your strings. One can have nearly infinite variety in
    HTML code
    that will display identically in a browser, the standard is
    very
    forgiving of formatting differences.
    Something I have done in the past to compare HTML content is
    to use the
    hash() function. It will not help you eliminate the
    differences but it
    would show when something is different then it appears to be.
    #hash(mystringoflongdata)# will return a hexadecimal number
    representing
    the string. Two *exactly* the same strings will produce the
    same
    number. Then it is very easy to compare these numbers to see
    if two
    long strings are the same.
    To use this with your database data, you would probably have
    to store
    the hash value of the string in a field when you store the
    HTML data.
    HTH
    Ian

  • SQL "LIKE" statement isn't working right -- help please!

    Good day everyone,
    I thought about putting this in the "SQL on Oracle" forum, but it looked like those messages were geared more toward the Oracle platform itself, so here I am.  I apologize if this isn't the best forum.
    I have the following SQL statement:
      SELECT zzreporting_ut1
             zzreporting_ut2
             zzreporting_ut3
             zzreporting_ut4
             zzreporting_ut5
          UP TO 1000 ROWS
          INTO TABLE it_gmia_gmgrresp_data
            FROM gmspprogram
       WHERE ( ( zzreporting_ut1 LIKE '4011%'   OR
                 zzreporting_ut1 LIKE '4012%'   OR
                 zzreporting_ut1 LIKE '4013%' ) OR
               ( zzreporting_ut2 LIKE '4011%'   OR
                 zzreporting_ut2 LIKE '4012%'   OR
                 zzreporting_ut2 LIKE '4013%' ) OR
               ( zzreporting_ut3 LIKE '4011%'   OR
                 zzreporting_ut3 LIKE '4012%'   OR
                 zzreporting_ut3 LIKE '4013%' ) OR
               ( zzreporting_ut4 LIKE '4011%'   OR
                 zzreporting_ut4 LIKE '4012%'   OR
                 zzreporting_ut4 LIKE '4013%' ) OR
               ( zzreporting_ut5 LIKE '4011%'   OR
                 zzreporting_ut5 LIKE '4012%'   OR
                 zzreporting_ut5 LIKE '4013%' ) ).
    All I want to do is bring back the rows where one of those 5 "ut" fields begins with 4011, 4012, or 4013.  However, when I run it, it brings back anything:  rows where all 5 "ut" fields are empty, where the ut1 field begins with 4014, etc.
    Does anyone know what I'm doing wrong in my SQL statement?
    Thank you!  And as always, points awarded for ALL HELPFUL answers!
    Dave
    Edited by: Dave Packard on Jul 1, 2008 2:18 PM

    Hi Dave,
    because I don't know such a table named gmspprogram I'm not sure what to say.
    According to boolean expression syntax you do not need any of the brackets because the only operator used is OR.
    I'd suggest.
    data: lt_pattern_range type range of gmspprogram-zzreporting_ut2.
    perform insert_range using 'ICP':
      '4011*' '' changing lt_pattern_range,
      '4012*' '' changing lt_pattern_range,
      '4013*' '' changing lt_pattern_range.
    SELECT
      zzreporting_ut1
      zzreporting_ut2
      zzreporting_ut3
      zzreporting_ut4
      zzreporting_ut5
      UP TO 1000 ROWS
      INTO CORRESPONDING FIELDS OF TABLE it_gmia_gmgrresp_data
      FROM gmspprogram
      WHERE zzreporting_ut1 in lt_pattern_range
         OR zzreporting_ut2 in lt_pattern_range
         OR zzreporting_ut3 in lt_pattern_range
         OR zzreporting_ut4 in lt_pattern_range.
    * need form
    *&      Form  insert_range
    *       insert selection range - handles any range type "CLI20061218
    FORM insert_range  USING    p_signopt     TYPE c            "#EC CALLED
                                p_low         TYPE any
                                p_high        TYPE any
                       CHANGING pt_range      TYPE table.
      FIELD-SYMBOLS:
        <range>                               TYPE ANY,
        <sign>                                TYPE ANY,
        <option>                              TYPE ANY,
        <low>                                 TYPE ANY,
        <high>                                TYPE ANY.
      DATA:
        lv_ref                                TYPE REF TO data.
      CHECK NOT (
                  p_low     IS INITIAL AND
                  p_high    IS INITIAL ).
      CREATE DATA lv_ref                      LIKE LINE OF pt_range.
      ASSIGN lv_ref->* TO <range>.
      CHECK sy-subrc                          = 0.
      ASSIGN COMPONENT 'SIGN' OF STRUCTURE <range> TO <sign>.
      CHECK sy-subrc                          = 0.
      ASSIGN COMPONENT 'OPTION' OF STRUCTURE <range> TO <option>.
      CHECK sy-subrc                          = 0.
      ASSIGN COMPONENT 'LOW' OF STRUCTURE <range> TO <low>.
      CHECK sy-subrc                          = 0.
      ASSIGN COMPONENT 'HIGH' OF STRUCTURE <range> TO <high>.
      CHECK sy-subrc                          = 0.
      <sign>                                  = p_signopt(1).
      <option>                                = p_signopt+1(2).
      <low>                                   = p_low.
      <high>                                  = p_high.
      READ TABLE pt_range WITH KEY table_line = <range> BINARY SEARCH
        TRANSPORTING NO FIELDS.
      CHECK sy-subrc                          <> 0.
      INSERT <range> INTO pt_range INDEX sy-tabix.
    ENDFORM.                    " insert_range
    At least - I think - this looks better. And you may reuse the FORM insert_range whereever you want.
    Regards,
    Clemens

  • How to Get Top 10 records using SQL select statement.

    :-) Hiee E'body,
    I want to generate a sql report in which I only want the top 10 records based on the numeric value of a column.
    For Example,
    To generate a Location Wise, Employee Wise Years of Service Report.
    Here I need the Top 10 Employees according to their No. of Years of Service for all the existing locations using a single query.
    eg.
    Location Emp No. YOS
    India - 22 30
    212 28
    819 24 ...
    US 123 40
    312 33
    90 33
    144 30 ...
    UK 77 20
    79 20
    331 18
    109 16 ...
    Every Location should display their respective Top 10 Employees
    regarding their No. of Years of Service.
    Please let me the know the solution to this.
    Have a nice day.
    Thanking You,
    Vivek Kapoor.

    For example if the table contained (India rows only shown) :
    India 202 30
    India 212 28
    India 819 24
    India 820 24
    India 900 20
    India 920 18
    India 922 17
    India 925 16
    India 926 15
    India 927 14
    India 928 13
    India 929 13
    India 930 12
    do you want to see
    India 202 30
    India 212 28
    India 819 24
    India 820 24
    India 900 20
    India 920 18
    India 922 17
    India 925 16
    India 926 15
    India 927 14
    or
    India 202 30
    India 212 28
    India 819 24
    India 820 24
    India 900 20
    India 920 18
    India 922 17
    India 925 16
    India 926 15
    India 927 14
    India 928 13
    India 929 13
    Also if the India rows were
    India 202 30
    India 212 30
    India 819 30
    India 820 30
    India 900 30
    India 920 30
    India 922 30
    India 925 30
    India 926 30
    India 927 30
    India 928 30
    India 929 30
    do you want to see
    India 202 30
    India 212 30
    India 819 30
    India 820 30
    India 900 30
    India 920 30
    India 922 30
    India 925 30
    India 926 30
    India 927 30
    or
    India 202 30
    India 212 30
    India 819 30
    India 820 30
    India 900 30
    India 920 30
    India 922 30
    India 925 30
    India 926 30
    India 927 30
    India 928 30
    India 929 30
    Please clarify.
    Thanks,
    Partha

  • How to use SQL LIKE in JDBC?

    Tried to use the following syntax of "LIKE" in JDBC, but doesn't work with mysql 4.1:
    String jsql =
    "select IMG_ID,IMG_File_S FROM image WHERE IMG_Region=? and IMG_Tissue LIKE '%' ? '%' ";
    pstmt = con.prepareStatement(jsql);
    pstmt.setString(1, IMG_Region);
    pstmt.setString(2, IMG_Tissue);
    what's the right syntax to use "LIKE"? thanks a lot!

    When you call preparedStatement.setString(), place the wildcards (%) in the actual string. Remove them from the SQL. Simply leave the bind variable placeholder (?).
    - Saish

  • SQL LIKE statement help

    Hi all,
    I want to select all values from prps-usr00 where the field contains XXX-XXXX...where X is any letter or number. How in the world do I do that?
    Thanks,
    Mat

    Hi,
    SELECT SOMETHING INTO VARIABLE FROM TABLE
                                         WHERE PARAM1 LIKE '%-%'.
    Or
    If you know that there will be exactly 2 char in front of '-' and 2 char after. then use.
    SELECT SOMETHING INTO VARIABLE FROM TABLE
                                     WHERE PARAM1 LIKE '__-__'.
    Regards
    madhu
    Edited by: madhu tatikonda on Jun 27, 2008 9:08 PM

  • SQL query editor and "like" with a parameter (can't get it to work).

    I've been following all sorts of directions on how to use mysql a table and modifying the query to accept a parameter, funny thing is no matter how I try to construct the simplest query, the query editor does not parse the query properly when using the "LIKE" statement.
    Using 3.11 and/or 3.12 of the J/connector with no success.
    I am using a query that resembles the following:
    select all table.fieldname, table.fieldname2 from tablename where table.fieldname like '%?%'
    It parses correctly but the code when run can not find the parameter as it reports the number of paramenters as being incorrect.
    I have tried these varriations of the "like" statement.
    '%?%' - expected this to work, it parses correctly but errors out claiming invalid number of parameters.
    %?% - without quotes causes parsing errors.
    '?' - parses correctly but isn't the correct query.
    ? - again without quotes causes parsing errors,even if it did it isn't the correct query.
    If I set the query to use a value instead of a parameter - it works fine.
    Hints? Suggestions? Bug?
    Thanks in advance.

    Hmm, try use
    select ... like ?
    And path this kind of string as the parameter to your query
    String findCriteria = "what you are looking for";
    String parameter = "'%" + findCriteria + "%'";Roman.

Maybe you are looking for

  • Kernel panic after cloning Mac Pro to iBook G4

    Oops! For years I've "synchronized" my iBook to my G4-DP via CCC or SuperDuper. That just bit me, when I tried that from new Mac Pro. The kernel panic message is: panic (...): Unable to find driver for this platform: "PowerBook6,5" What is the smart

  • I want to download an earlier version of Firefox.

    I have Mac OS 10.4.11, and when I tried to open firefox today it wouldn't do anything- no error message, nothing. So I went to this site to download it again, and all I could find was Firefox 4.0, which apparently is not compatible with my OS. So all

  • Why do my apps crash a lot in ios5 on my iPad?

    A lot off apps seem to have trouble running stable On my 1st gen iPad. Especially Safari seems to endure a lot of them. But also itunes U, comic book lover etc have their share of troubles. It does not seem related to iCloud as i saw mentioned becaus

  • Grab in split-join

    I have a grab activity which is set to from all to all. The process has a split-join. The user cannot grab an activity which is in a branch of split-join to outside the split-join or grab an acitivity which is outside the split-join into one branch o

  • How can I tell which apps are using data

    Perhaps this is a suggestion, just in case someone who is in a position to note this at Apple (not likely?) might read it. How about an app included in the OS that allows users to track which apps are transmitting and receiving data through cellular