Solved

database problem for a blocklist!

Posted on 2006-11-02
10
165 Views
Last Modified: 2010-04-05
I got a small problem with a database statment I want to check a blocklist on my privmsg section for blocked users but when I try following code it dont check blocklist it till allows people to msg one and other even if name is in blocklist can anyone help fix the problem please?

thanks

[code]
if UsersTable.Locate('Name',dat[0],[locaseinsensitive])then // check my own account table
     begin
     if UsersTable.Locate('BlockedUsers',dat[1],[locaseinsensitive]) then // check my blocklist table
     begin

      if rSocket<>nil then
      if rSocket.Connected then
         rSocket.SendText(CodeStr('šTechMsgœERROR '+dat[0]+'œ')); // send error msg if name found in blocklist

   end
   else
   begin // if name not found then send msg!

rSocket.SendText(CodeStr('šRPrivMsgœOKœ'+dat[0]+'œ'+dat[3]+'œ'));
    s:='šPrivMsgœ'
          +dat[1]+'œ'  // MyName
          +dat[2]+'œ'  // There Name
          +dat[3]+'œ'; // Message
0
Comment
Question by:fiveuk
  • 4
  • 4
10 Comments
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 17861952
If you are using "real" database do it with query inside the DB. For example:

SELECT * FROM privmsg
WHERE sender_id NOT IN
  ( SELECT user_id FROM blocked_user ...)

Something like this...
0
 

Author Comment

by:fiveuk
ID: 17862009
am using db its how the program been setup :( can you still help? allso my sql programing sucks
0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 17862095
Give me some more info. Which tables you query, what fields they have and so on, so I can help you with the SQL query.
0
 

Author Comment

by:fiveuk
ID: 17862154
this database

CREATE TABLE `users` (
  `N` int(11) NOT NULL auto_increment,
  `Name` varchar(32) default '',
  `Pass` varchar(16) default '',
  `BlockedUsers` text,
  PRIMARY KEY  (`N`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

all I want to do is check the persons database that I am sending a message to and if am on his blocklist my message will not be sent to him!

can you help?

so when I send message it would do following :

dat[0] (Simon)  -> Send msg -> server checks Blocklist of person dat[1] (bob) I am sending msg to and if my ID is in his block list it will send me the error msg if not then it will allow me to send msgs
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 12

Accepted Solution

by:
Ivanov_G earned 125 total points
ID: 17862290
My opinion is that your DB design is wrong. What will happen if you have 2 users in the blocklist? Maybe "bob1,bob2,etc"

I think you should do it this way:

Table: users
---------------------------
N
Name
Pass


Table: users_blocked
---------------------------
rel_id - relation ID, auto_increment
user_N - your user ID
ignored_user_N - ID for ignored user


Some example data:

user
-------
1 Simon asfkjafklasjflksajf
2 Peter asdkfjaklfjalsfasfk
3 Georgi asfjalksjfasjf;lajf

users_blocked
1 1 2
2 1 3

In this example user Simon has blocked users Peter and Georgi. Using a query it can be checked like this:

SELECT COUNT(*)
FROM users u, users_blocked ub
WHERE u.ignored_user_N = 'Simon' -- your user ID that will be checked for ignore
  AND u.N = ub.user_N
  AND u.Name = 'bob' -- user that you checked if he has ignored you

If the result is 1 (or more) the user ignored you, if it is 0 - you can send the message
0
 

Author Comment

by:fiveuk
ID: 17862366
ok am lost lol
0
 

Author Comment

by:fiveuk
ID: 17862428
I did say am a newbe at MYSQL?

dont no were to start or anything
0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 17862609
MySQL is quite simple database. You can start with its online documentation:
http://dev.mysql.com/doc/refman/5.1/en/index.html
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This video discusses moving either the default database or any database to a new volume.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

762 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now