?
Solved

C function that behaves exactly like the SQL LIKE function

Posted on 2004-09-10
7
Medium Priority
?
212 Views
Last Modified: 2010-04-15
Hi,

Does anyone know of a function or can provide an code sample of a C function that behaves exactly like the SQL LIKE function?  The function should accept and properly evaluate all wildcards and special operators used by the SQL LIKE ( %, ^, [], etc ).

Thanks In Advance.
0
Comment
Question by:CUGroup
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 12033134
Hi CUGroup,

If you can describe the exact behaviour or SQL LIKE and tell us the platform that you are working on, hopefully we can come up with something
0
 
LVL 11

Expert Comment

by:cjjclifford
ID: 12043087
Hi,

It should be relatively straight forward to convert from SQL syntax to standard Regular Expression syntax (man regex on Unix)

e.g.

_ -> .
% -> .*

etc.
the write wrapper function(s) on the regex library calls, to convert the LIKE string to the regular exp. and to process from that...

Hope this helps,
C.
0
 

Author Comment

by:CUGroup
ID: 12069571
Hi,

Thanks for the responses.  Unfortunately, I need function to be portable, UNIX and Windows so I'm in search of a c function to mimic this sql function.

This is the best resource I could find regarding the use of the SQL LIKE function.

http://www.sql-tutorial.net/SQL-LIKE.asp

Thank you for your help.

0
 
LVL 2

Accepted Solution

by:
sneeuw_chan earned 500 total points
ID: 12070444
I think it corresponds more to 'glob' than to 'regex'.
(Glob is the way that a dos-prompt or unix shell matches filenames on the commandline.)

You could try looking for a 'glob'  library.
A quick google shows this, for example:  http://www.cs.yorku.ca/~oz/glob.bun
(You could even change that code to parse this 'LIKE' format directly, just change the case '*'  to case '%' and the case '?' to case '_'.)

If that's not to your liking, search for other glob libraries.
0
 
LVL 11

Assisted Solution

by:cjjclifford
cjjclifford earned 500 total points
ID: 12072899
CUGroup, if you are just looking for a portable (Unix and Windows) way of matching patterns in text, then surely the standard Posix regex functionality I listed would be the way to go? I'd be confident that there is a Windows inplementation (defintely if you use a GCC derived compiler)
Either that, or as sneeuw_chan suggested use Glob functionality.
I wouldn't go with the SQL LIKE format, unless you are actually implementing a SQL engine... LIKE is a lot more cumbersome than regex or glob...
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question