Planet MySQL Planet MySQL: Meta Deutsch Español Français Italiano 日本語 Русский Português 中文
Showing entries 1 to 8

Displaying posts with tag: functions (reset)

Mysql: creating a link to your glossary while fetching text for a webpage
+1 Vote Up -0Vote Down
This MySql function will generate a link to your glossary when you are fetching text for a web page. All code is provided in a zip file.
MySql Lorum Ipsum generator
+0 Vote Up -0Vote Down
A short MySql function to generate a Lorum Ipsum text. You can download the code in the zip file below.
Howto generate meaningful test data using a MySQL function
+2 Vote Up -0Vote Down
You can use this MySQL function to generate names, (e-mail)addresses, phone numbers, urls, bit values, colors, IP address, etc.. As usual, the code is provided in a zip and the code is fully documented.
MySql: cleaning user input before storing the data
+1 Vote Up -0Vote Down
This article describes a single MySql function to sanitize strings. The provided options are:
  • replace multiple spaces to a single space
  • remove Unix and Windows linebreaks and replace them with a space
  • remove tabs and replace them for a single space
  • remove multiple backslashes
  • completely remove htmlentities (&)
  • replace htmlentities with the corresponding character
  • remove all HTML tags
Custom auto increment values
+0 Vote Up -0Vote Down

The auto_increment for MySQL fields are very useful but what about if I need a custom auto-increment like a custom format like 001-000033,

001-000034
001-000035
001-000036
...

To make it possible we have an option based on past article MySQL Sequences:

  • Create the table to store the current sequence values:
    CREATE TABLE _sequence
    (
        seq_name VARCHAR(50) NOT NULL PRIMARY KEY,
        seq_group VARCHAR(10) NOT NULL,
        seq_val INT UNSIGNED NOT NULL
    );
  • Create a function to get and increment the current value:
    delimiter //
    DROP FUNCTION IF EXISTS getNextCustomSeq//
    CREATE FUNCTION getNextCustomSeq
    (
        sSeqName
  •   [Read more...]
    implementing table quotas in MySQL
    +6 Vote Up -0Vote Down
    I have just seen Limiting table disk quota in MySQL by Shlomi Noach, and I could not resist.
    You can actually implement a disk quota using an updatable view with the CHECK OPTION.
    Instead of giving the user access to the table, you give access to the view (at least for inserting, see the caveat at the end), and you will get a genuine MySQL error when the limit is reached.

    drop table if exists logs;
    create table logs (t mediumtext) engine=innodb;

    drop function if exists exceeded_logs_quota ;
    create function exceeded_logs_quota()
    returns boolean
    deterministic
    return (
    select CASE
    WHEN (DATA_LENGTH + INDEX_LENGTH) > (25*1024)














      [Read more...]
    Pitfalls of monitoring MySQL table activity with stored routines
    +3 Vote Up -0Vote Down
    A friend of mine needed a quick method to monitor a table that was frequently updated. There were several procedures writing to the table several times per second. He needed a quick way of determining how many updates per second the table was getting.
    The table has only one row, which includes a counter that is increased at each operation. Therefore, the simple plan was:
  • Let's get the counter from the table;
  • Allow N seconds to pass;
  • Get the counter again;
  • The difference between the second counter and the first counter, divided by the number of seconds gives the updates per second.
  • The plan makes sense, and if you run the above

      [Read more...]
    memcached Functions for Drizzle now in main tree!
    +0 Vote Up -0Vote Down
    What a great day! I see that the drizzle team has merged in my (and Padraig O'Sullivan's) memcached Functions for Drizzle (UDFs). I'm really glad to have this in drizzle now as it adds a means of interacting with memcached from within Drizzle. I have most functions from the MySQL branch implemented now as well. I'm extremely grateful to Padraig O'Sullivan for getting this project off the ground. I was a bit stuck with the new API and C++ when I first attempted these and he designed the class setup and had the major functions working which I then picked up and added more functions as well as tests. I was also glad to have the drizzle team add in my sleep() UDF which allowed me to test expirations in these memcached functions.

    These functions have some similar, but very little code from the memcached Functions for MySQL. The new UDF API is completely different than MySQL's UDF API. You have to

      [Read more...]
    Showing entries 1 to 8

    Planet MySQL © 1995, 2014, Oracle Corporation and/or its affiliates   Legal Policies | Your Privacy Rights | Terms of Use

    Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.