LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 12-15-2004, 05:55 PM   #1
Ephracis
Senior Member
 
Registered: Sep 2004
Location: Sweden
Distribution: Ubuntu, Debian
Posts: 1,109

Rep: Reputation: 49
Matching with SQL


I have a table called bannedNicks that contains only one column so far called "banned" with the type varchar(50).

Now in my C++ program I use this table to check if a nick is legal by sending a query like:
Code:
SELECT count(banned) FROM bannedNicks WHERE banned="<nick>";
But I would like to be able to have nicks in the database that looks like cr*, moist?rize and ^dud[e3]$. Yeah, I want to use regexp but if I have something like that how can I make a question that would find the post with ^dud[e3]$ when I have the nick dude or dud3? Banning both nicks with just one post using regexp.
 
Old 12-15-2004, 06:34 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,971
Blog Entries: 11

Rep: Reputation: 876Reputation: 876Reputation: 876Reputation: 876Reputation: 876Reputation: 876Reputation: 876
Code:
SELECT count(banned) FROM bannedNicks WHERE banned LIKE '%<chunk>%';
should do the trick ... that's not quite regex matching but will
cover quite a few not too unusual nicks ;)

If that doesn't QUITE do what you want you'll need to load
the result table into some C++ data-structure and run patter-
matching against that e.g. vector of strings ...



Cheers,
Tink
 
Old 12-15-2004, 06:38 PM   #3
Ephracis
Senior Member
 
Registered: Sep 2004
Location: Sweden
Distribution: Ubuntu, Debian
Posts: 1,109

Original Poster
Rep: Reputation: 49
Yes I was aware of the "LIKE" and "%" but the thing is that that does "the other way around". It's the post in the database that is the pattern and the nick is what should be matched. :/
 
Old 12-15-2004, 10:41 PM   #4
csfalcon
Member
 
Registered: Jun 2004
Location: MD
Distribution: Fedora Core
Posts: 269

Rep: Reputation: 31
so the database contains the regular expressions and you want to do the matching in C++?
 
Old 12-16-2004, 05:09 AM   #5
Ephracis
Senior Member
 
Registered: Sep 2004
Location: Sweden
Distribution: Ubuntu, Debian
Posts: 1,109

Original Poster
Rep: Reputation: 49
Quote:
Originally posted by csfalcon
so the database contains the regular expressions and you want to do the matching in C++?
Yes but I use MySQL so I could use it in SQL and/or C++. My first thought was to check every row in the table and use the regexp in the table to try to match the nick. The main problem was that it could be inefficient if the database would grow big.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find/grep command to find matching files, print filename, then print matching content stefanlasiewski Programming 8 12-18-2013 05:36 PM
Migrating from MS-SQL server to My-SQL emailssent Linux - Networking 2 02-07-2005 02:20 PM
Which SQL is suitable for EMbedded SQL on C? hk_michael Programming 4 01-10-2005 05:07 PM
Matching with jokers alitrix Programming 5 12-02-2003 02:46 PM
Problems with matching alitrix Programming 3 11-18-2003 07:24 PM


All times are GMT -5. The time now is 08:29 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration