Can anyone help How do I add a limit on size
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Can anyone help How do I add a limit on size

  1. #1
    Join Date
    Feb 2013
    Posts
    1

    Can anyone help How do I add a limit on size

    Im working on a small code and am trying to limit the size of the mysql databse string its pulling.
    It can only be 119 characters, or less if its more i would like to do nothing, but if its meets the requirements it runs the script.

    Code:
    int32 message_id;
       string_t message ="Is requesting some one to respond.";<_______________TEMP SHOULD BE THE POSTERS MESSAGE
       string_t username = "Guest";<_______________TEMP SHOULD BE THE POSTERS NAME
    
    
       // char will not be logged in so get the id manually
       const int8* Query = "SELECT message_id, username, message FROM phpbb_chat WHERE count = '0';";
       int32 ret = Sql_Query(SqlHandle,Query);
    
       if (ret != SQL_ERROR && Sql_NumRows(SqlHandle) != 0 && Sql_NextRow(SqlHandle) == SQL_SUCCESS)
       {
          
          
       
       message_id = (int32)Sql_GetIntData(SqlHandle,0);
       username =  Sql_GetData(SqlHandle,0);
       message   =  Sql_GetData(SqlHandle,1);
       
       //So here is where I'm heaving the problem 
    
    if(message is less then 119 characters run script )<<_______________________________________________THIS IS THE CODE LINE IM TRYING TO LEARN
    {
    
     char buf[110];
        sprintf(buf,"[Web Chat] %s %s",username.c_str(), message.c_str());
       for (uint16 zone = 0; zone < 256; ++zone)
                {
                zoneutils::GetZone(zone)->PushPacket(
                    NULL, 
                    CHAR_INZONE, 
                 new CChatMessageStringPacket(PChar, MESSAGE_STRING_SAY , ("%s",buf)));
                }
    
    ShowNotice(CL_RED"TRACER:COMMAND: CRecastContainer::Check MessageID %u Username %s Message %s  \n" CL_RESET,message_id,username.c_str(),message.c_str());   
    
    }
    else
    {
     ShowNotice(CL_RED"TRACER:COMMAND: CRecastContainer::Check Message Is To Large and can not be posted \n" CL_RESET);   
    }
    
       
    
           Query = "UPDATE phpbb_chat SET count = '1' WHERE message_id = %u;";
    
       Sql_Query(SqlHandle, Query,message_id);
            
           
       
       }
    CAN ANY ONE HELP ME?

  2. #2
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,877

    Re: Can anyone help How do I add a limit on size

    Yet on querying MySQL you need to cut off all the entries that you are to do nothing with:
    Code:
    SELECT message_id, username, message FROM phpbb_chat WHERE count = '0' and CHAR_LENGTH(message) < 120;
    MySQL String Functions
    Best regards,
    Igor

  3. #3
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    10,965

    Re: Can anyone help How do I add a limit on size

    Igor's advice is very good - just restrict the SQL query so it only returns results with message size < 120. Simple - do it in the query code so you don't need to do it in C++.

    Along these lines, why not also only store valid entries in the database? So if the data doesn't meet the criteria, don't store it in the database to begin with. Remember, with databases, it's garbage in; garbage out.

    So if you only store 'clean' data in the database, you've got less work to 'fix-up' the data when you use it later.

    Such a simple concept, but many developers miss this and cause themselves a lot of work and more complicated code base because they allow bad data to be stored in the database.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center