Visualizzazione dei risultati da 1 a 6 su 6
  1. #1
    Utente di HTML.it L'avatar di nicki
    Registrato dal
    Dec 2000
    Messaggi
    139

    [SQLite] Where-like e attributi

    Ciao a tutti!

    dovrei fare una query usando lo statement LIKE nel WHERE e utilizzando gli attributi.

    Una roba tipo:

    SELECT * FROM veicoli WHERE targa LIKE '%'+:targa+'%'

    Il problema è che facendo la stessa cosa, con lo stesso parametro targa, con l'uguale funziona, con il like neanche un risultato.

    Query con l'uguale:

    SELECT * FROM veicoli WHERE targa =:targa

    Qualche idea o link con informazioni utili?

    Se serve aggiungo anche codice C# che utilizzo.

    Grazie, nicola.
    Ciao, nic.

  2. #2
    Utente di HTML.it L'avatar di Joe Taras
    Registrato dal
    Nov 2003
    residenza
    Taranto
    Messaggi
    955

    Re: [SQLite] Where-like e attributi

    Originariamente inviato da nicki
    Ciao a tutti!

    dovrei fare una query usando lo statement LIKE nel WHERE e utilizzando gli attributi.

    Una roba tipo:

    SELECT * FROM veicoli WHERE targa LIKE '%'+:targa+'%'

    Il problema è che facendo la stessa cosa, con lo stesso parametro targa, con l'uguale funziona, con il like neanche un risultato.

    Query con l'uguale:

    SELECT * FROM veicoli WHERE targa =:targa

    Qualche idea o link con informazioni utili?

    Se serve aggiungo anche codice C# che utilizzo.

    Grazie, nicola.
    SqLite forse usa come funzione di concatenazione di stringhe il concat invece del +,
    quindi fai concat('%',targa,'%')

  3. #3
    Utente di HTML.it L'avatar di nicki
    Registrato dal
    Dec 2000
    Messaggi
    139
    Il concat non funziona:

    codice:
    SQLite error no such function: concat
    Per concatenare stringhe bisogna || e non + che restituisce la somma intera. Infatti così ho risolto:

    SELECT * FROM tbl_veicoli WHERE targa LIKE '%'||:targa||'%'


    riferimenti:
    http://www.sqlite.org/datatypes.html punto 4.0

    [...]
    4.0 How SQLite Determines Datatypes

    For SQLite version 2.6.3 and earlier, all values used the numeric datatype. The text datatype appears in version 2.7.0 and later. In the sequel it is assumed that you are using version 2.7.0 or later of SQLite.

    For an expression, the datatype of the result is often determined by the outermost operator. For example, arithmetic operators ("+", "*", "%") always return a numeric results. The string concatenation operator ("||") returns a text result. And so forth. If you are ever in doubt about the datatype of an expression you can use the special typeof() SQL function to determine what the datatype is. For example:

    sqlite> SELECT typeof('abc'+123);
    numeric
    sqlite> SELECT typeof('abc'||123);
    text
    [...]


    Ciao e grazie dell'aiuto!
    Ciao, nic.

  4. #4
    Utente di HTML.it L'avatar di Joe Taras
    Registrato dal
    Nov 2003
    residenza
    Taranto
    Messaggi
    955
    Originariamente inviato da nicki
    Il concat non funziona:

    codice:
    SQLite error no such function: concat
    Per concatenare stringhe bisogna || e non + che restituisce la somma intera. Infatti così ho risolto:

    SELECT * FROM tbl_veicoli WHERE targa LIKE '%'||:targa||'%'


    riferimenti:
    http://www.sqlite.org/datatypes.html punto 4.0

    [...]
    4.0 How SQLite Determines Datatypes

    For SQLite version 2.6.3 and earlier, all values used the numeric datatype. The text datatype appears in version 2.7.0 and later. In the sequel it is assumed that you are using version 2.7.0 or later of SQLite.

    For an expression, the datatype of the result is often determined by the outermost operator. For example, arithmetic operators ("+", "*", "%") always return a numeric results. The string concatenation operator ("||") returns a text result. And so forth. If you are ever in doubt about the datatype of an expression you can use the special typeof() SQL function to determine what the datatype is. For example:

    sqlite> SELECT typeof('abc'+123);
    numeric
    sqlite> SELECT typeof('abc'||123);
    text
    [...]


    Ciao e grazie dell'aiuto!
    Quale DBMS stai usando? Ah ecco se hai usato il pipe credo sia sotto Oracle.

  5. #5
    Utente di HTML.it L'avatar di nicki
    Registrato dal
    Dec 2000
    Messaggi
    139
    e sqlite non è un dbms?

    Scusa che c'azzecca oracle con 'sto thread?
    Ciao, nic.

  6. #6
    Utente di HTML.it L'avatar di Joe Taras
    Registrato dal
    Nov 2003
    residenza
    Taranto
    Messaggi
    955
    Originariamente inviato da nicki
    e sqlite non è un dbms?

    Scusa che c'azzecca oracle con 'sto thread?
    Niente, hai ragione, ho detto una ca**ata

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.