473,400 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,400 software developers and data experts.

newbee question on sql select

I use the following line to create a recordset. The s4, in the LIKE
statement, is text of a filepath and some of the files have an ( ' )
apostrophe in the file name. The code will not add those files to the
recordset. Is there a way to get around this without changing all the
filenames?

rs2 = App.eBookDB.SQLSelect("SELECT * FROM eBooks WHERE FilePath LIKE
'%" + s4 + "%'")

thanks, pepe

Mar 6 '06 #1
6 1251
Pepe wrote:
I use the following line to create a recordset. The s4, in the LIKE
statement, is text of a filepath and some of the files have an ( ' )
apostrophe in the file name. The code will not add those files to the
recordset. Is there a way to get around this without changing all the
filenames?


Escape ' characters with \.. So change

"that's it" to "that\'s it"

You will also need to escape \ characters with \. And also ? and %
characters unless you wish to use them like the way you are using % in
your example.
Mar 6 '06 #2
"Pepe" <no***@nowhere.com> wrote in message
news:2006030616555716807-noone@nowherecom...
I use the following line to create a recordset. The s4, in the LIKE
statement, is text of a filepath and some of the files have an ( ' )
apostrophe in the file name. The code will not add those files to the
recordset. Is there a way to get around this without changing all the
filenames?

rs2 = App.eBookDB.SQLSelect("SELECT * FROM eBooks WHERE FilePath LIKE '%"
+ s4 + "%'")


The safest way is to use parameterized queries. I can't tell from your
example which language or object library you're using, but any programming
interface should support parameters for queries.

So your query would be something like:

rs2 = App.eBookDB.SQLSelect("SELECT * FROM eBooks WHERE FilePath LIKE
CONCAT('%', ?, '%')")

And then you need to supply your s4 as the parameter, which assigns the
value of s4 to the ? parameter in the SQL statement. This avoids problems
with special characters in the value of s4, and it also helps to protect
against SQL injection security flaws.

The method for supplying the parameter depends on the language and object
library you're using. Refer to your documentation.

Regards,
Bill K.
Mar 6 '06 #3
"Aggro" <sp**********@yahoo.com> wrote in message
news:zi**************@read3.inet.fi...
And also ? and % characters unless you wish to use them like the way you
are using % in your example.


Do you mean the _ and % characters? The question mark is not a wildcard in
LIKE predicates; the underscore character is.

Regards,
Bill K.
Mar 7 '06 #4
On 2006-03-06 17:52:03 -0500, "Bill Karwin" <bi**@karwin.com> said:

The safest way is to use parameterized queries. I can't tell from your
example which language or object library you're using, but any
programming interface should support parameters for queries.

So your query would be something like:

rs2 = App.eBookDB.SQLSelect("SELECT * FROM eBooks WHERE FilePath LIKE
CONCAT('%', ?, '%')")

And then you need to supply your s4 as the parameter, which assigns the
value of s4 to the ? parameter in the SQL statement. This avoids
problems with special characters in the value of s4, and it also helps
to protect against SQL injection security flaws.

The method for supplying the parameter depends on the language and
object library you're using. Refer to your documentation.


Bill K
I'm using RealBasic SQLDatabase, and I don't have any documentation for
it, only what I find on the net. I looked up CONCAT and understand what
it does but I don't know enough about the ? and how to use it.
pepe

Mar 7 '06 #5
On 2006-03-06 18:09:19 -0500, Aggro <sp**********@yahoo.com> said:
Pepe wrote:
I use the following line to create a recordset. The s4, in the LIKE
statement, is text of a filepath and some of the files have an ( ' )
apostrophe in the file name. The code will not add those files to the
recordset. Is there a way to get around this without changing all the
filenames?


Escape ' characters with \.. So change

"that's it" to "that\'s it"

You will also need to escape \ characters with \. And also ? and %
characters unless you wish to use them like the way you are using % in
your example.


Thanks, I'll give it a try.
pepe

Mar 7 '06 #6
Bill Karwin wrote:
Do you mean the _ and % characters? The question mark is not a wildcard in
LIKE predicates; the underscore character is.


That is right. Thank you for correcting this.
Mar 7 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Newbee | last post by:
Hi ! Let's say that this is the folder on the server: /web/firstDir/secondDir/images/image.gif where i have stored my pictures. I have tryed with apsolute and relative paths but i can't display...
5
by: Adam | last post by:
Hi, Me very confused. I have some XML that I want to convert to a more basic XML. I have put an example of what I have and what I want, I have used XSL to convert XML to HTML, but never this way. ...
2
by: Newbee Adam | last post by:
some said that .NET app can run on any program where rutime exists. What is "runtime" in this sense? will I have to install runtime or .net framework or .NET support on an xp machine for a...
1
by: Magnus | last post by:
Hi, I have previously worked mostly with Sql Server and wonder how to write a subselect query in mysql 4.0. What i would like to do is something like: select a.name, b.isbn from author a...
4
by: PerryC | last post by:
All, 1. Do the following codes seem ok? 2. If so, then how do I pull the value of YOE1 and YOE2 into my report? (to do some further calculations) ...
1
by: Mike | last post by:
Hello all, I'm new to vb.net and I was hoping to get a little help. I am trying to write an application where you can select individual files from one directory and copy them to a target directory...
2
by: IchBin | last post by:
I am trying to clean up my code. I have run it through tidy and now have the code below. The problem is that anytime I select a radio button I get the following error: Forbidden You don't have...
2
by: Mel | last post by:
I have a selection box with 3 values. what i need is to pass 3 urls to a function that has a switch statement and based on the selection index goes on one of the tree urls. Question is how do i...
2
by: horsecock | last post by:
Hi, Being new to DB2 I'm having a small problem that I'm sure is quite easy to someone smarter than me. I have a table with duplicate entries and I need to know how to code a query to exctract...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.