<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="verify-v1" content="ynzW/GE7rr+SwTxuVauAHAJHCND7JANXtoLBw5Ci6tY=" />
	<title>MySQL ::  The world's most popular open source database</title> 

	 

	<link rel="stylesheet" type="text/css" media="screen" href="../../common/css/mysql.css" />
	<link rel="stylesheet" type="text/css" media="projection" href="../../common/css/mysql.css" />
	<link rel="stylesheet" type="text/css" media="print" href="../../common/css/print.css" />
	
	 
		
		
		
		
	 
		<link rel="shortcut icon" href="../../common/themes/sakila/favicon.ico" />
	
		<script language="javascript" type="text/javascript" src="../../common/js/clear_search_text.js"></script>
    	
		<noscript></noscript>
	    
		    
    <script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js"></script>
    
    
</head>

<body  >

<div id="container">

<!--UdmComment-->
<a class="skipToContent" href="mysql_is_savepoints.cc#mainContent">Skip navigation links</a>

	<div id="header" >
	
	<div class="left">
							    <div id="logo-cic">
		    		    	
		    <a href="../../index.html" title="MySQL">
		    		    <img src="../../common/logos/logo-mysql-110x57.png" alt="MySQL" width="110" height="57" /></a>
		    </div>
		    <div id="tagline-cic">The world's most popular open source database</div>
				
				

	</div>
	
	<div class="right">
				
		<div id="search_box"> <!-- Start Search -->
				    <form id="searchform" name="searchform" method="get" action="http://search.mysql.com/search">
			<input type="text" id="q" name="q" value="Search" class="swap_value" onfocus="clearSearchText();" />
			<input type="hidden" name="ie" value="" />
			<input type="hidden" name="lr" value="lang_en" />
			<input type="image" src="../../common/themes/sakila/search_g.png" id="go" alt="Search" title="Search" value="Search" />
		    </form>
		
		</div> <!-- End Search -->

				
		  		  
		<div id="login" >
			
		  	
				
									 <p><a href="http://dev.mysql.com/login/?dest=http%3a%2f%2fdev.mysql.com%2Ftech-resources%2Farticles%2Fmysql_is_savepoints.cc">Login</a> | <a href="http://dev.mysql.com/register.php">Register</a></p>
									</div>
  
			</div>

	</div> 

	<!-- MySQL Navigation -->
	<div id="nav_container">
	
	<div id="flags">
            <ul>
		<br />
            </ul>
        </div>
		
						<div id="tab_first">
		<ul>
			<li class="current"><a href="../../index.html">Developer Zone</a></li>
			<li class="first"><a href="../../downloads/index.html" onclick="javascript: pageTracker._trackPageview('/FP/Tabs/Downloads');">Downloads</a></li>
			<li><a href="../../doc/index.html">Documentation</a></li>
		</ul>
		</div>
		
						

	
	<div id="mysql_menu">
	    <ul>
	<li class="link"><a  href="../../index.html">DevZone</a>
	
		
		
	</li>
	
	<li class="link"><a  href="../../librarian/index.html">Librarian</a>
	
		
		
	</li>
	
	<li class="current"><a class="current " href="index.html">Articles</a>
	
		
		
	</li>
	
	<li class="link"><a  href="http://dev.mysql.com/news-and-events/news/index.html">News and Events</a>
	
		
		
	</li>
	
	<li class="link"><a  href="http://forums.mysql.com/">Forums</a>
	
		
		
	</li>
	
	<li class="link"><a  href="http://bugs.mysql.com/">Bugs</a>
	
		
		
	</li>
	
	<li class="link"><a  href="http://forge.mysql.com/">Forge</a>
	
		
		
	</li>
	
	<li class="link"><a  href="http://planet.mysql.com/">Planet MySQL</a>
	
		
		
	</li>
	
	<li class="link last"><a  href="http://labs.mysql.com/">Labs</a>
	
		
		
	</li>
	
</ul>
	</div>

		<div id="og_sakila">&nbsp;</div>
	        <div id="og_title">&nbsp;</div>
	
	</div>
	<!-- End Navigation Container -->

<!--/UdmComment-->

<div class="page_container">

		
	 <div class="page_sidebar">
		
		<!--UdmComment-->
	
		<div id="menu_title">
				&nbsp;
		</div>
		
		<div id="menu">
				<ul>
	<li class="current"><a class="current " href="index.html">Articles</a>
	
		
		
	</li>
	
	<li class="link"><a  href="../../why-mysql/white-papers/index.html">White Papers</a>
	
		
		
	</li>
	
	<li class="link"><a  href="../../why-mysql/case-studies/index.html">Case Studies</a>
	
		
		
	</li>
	
	<li class="link last"><a  href="../interviews/index.html">Interviews</a>
	
		
		
	</li>
	
</ul> 
		</div>
	
		<br class="clear" />
		
				
			
				
						
				
				
					
			
			
										
				<div><a href="http://www.mysql.com/click.php?e=35251"><img src="../../common/themes/sakila/banners/h12-newsletter-subscribe.en.png" alt="MySQL Newsletter - Subscribe Today!" width="230" height="100" border="0" /></a></div>
							
        				
								
			
	<!--/UdmComment-->
	</div>		
	
	  
<!-- Main content -->
<a name="mainContent"></a>

<div id="page" class="sidebar" >

	 
		<h1 class="page_header">The world's most popular open source database</h1>
	 
	
	




	/* Copyright (C) 2008 Roland Bouman
 * http://rpbouman.blogspot.com/
 * roland.bouman@gmail.com
 
    This file is part of the MYSQL_SAVEPOINTS information_schema plugin.    
    
	This library is free software; you can redistribute it and/or
	modify it under the terms of the GNU Lesser General Public
	License as published by the Free Software Foundation; either
	version 2.1 of the License, or (at your option) any later version.
	
	This library is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
	Lesser General Public License for more details.
	
	You should have received a copy of the GNU Lesser General Public
	License along with this library; if not, write to the Free Software
	Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/

/**
    BUILD and (UN)INSTALLATION
    ==========================
    This MySQL information_schema plugin can be built on GNU/Linux as follows:
    
    g++ -Wall -shared -DMYSQL_DYNAMIC_PLUGIN -I/home/user/mysql-5.1.22-rc/include -I/home/user/mysql-5.1.22-rc/regex -I/home/user/mysql-5.1.22-rc/sql -o mysql_is_savepoints.so mysql_is_savepoints.cc
    
    where: 
    - the current working directory is the directory of this source file
    - /home/user/mysql-5.1.22-rc is the directory with an unpacked mysql-5.1.22-rc source distribution
    
    The output will be a shared library: mysql_is_savepoints.so
    Note that currently, plugins are not suppored on Microsoft Windows.

    In order to install the plugin, copy mysql_is_savepoints.so to the plugin directory.
    Use the following method to discover the location of the plugin directory:
    
    mysql> SHOW VARIABLES LIKE 'plugin_dir';
    +---------------+-----------------------------------------+
    | Variable_name | Value                                   |
    +---------------+-----------------------------------------+
    | plugin_dir    | /home/roland/mysql-5.1.22-dev/lib/mysql |
    +---------------+-----------------------------------------+
    1 row in set (0.00 sec)

    After copying mysql_is_savepoints.so to the plugin directory, 
    you can install the plugin using the INSTALL PLUGIN syntax:
    
    mysql> INSTALL PLUGIN MYSQL_SAVEPOINTS SONAME 'mysql_is_savepoints.so';
    Query OK, 0 rows affected (0.00 sec)
    
    Note: you need to have the privilege to insert into the mysql.plugin
    table in order to be able to install a plugin like this.    

    Note: there is currently a bug (http://bugs.mysql.com/bug.php?id=33731) 
    that requires you to use a *case sensitive name* 
    when installing and de-installing plugins.    
    For queries, information_schema plugin identifiers 
    are case-insensitive as usual.  

    You can verify the installation like this:
    
    mysql> SELECT * FROM information_schema.PLUGINS
        -> WHERE PLUGIN_NAME = 'MYSQL_SAVEPOINTS'\G
        *************************** 1. row ***************************
                   PLUGIN_NAME: MYSQL_SAVEPOINTS
                PLUGIN_VERSION: 0.16
                 PLUGIN_STATUS: ACTIVE
                   PLUGIN_TYPE: INFORMATION SCHEMA
           PLUGIN_TYPE_VERSION: 50122.0
                PLUGIN_LIBRARY: mysql_is_savepoints.so
        PLUGIN_LIBRARY_VERSION: 1.0
                 PLUGIN_AUTHOR: Roland Bouman (http://rpbouman.blogspot.com/)
            PLUGIN_DESCRIPTION: Show the savepoints for the current transaction
                PLUGIN_LICENSE: GPL
        1 row in set (0.01 sec)
    
    To use the plugin, do this:
    
	mysql> SET autocommit = OFF;
	Query OK, 0 rows affected (0.00 sec)
	
	mysql> SAVEPOINT A;
	Query OK, 0 rows affected (0.00 sec)
	
	mysql> SELECT * FROM information_schema.MYSQL_SAVEPOINTS;
	+--------------+----------------+
	| SAVEPOINT_ID | SAVEPOINT_NAME |
	+--------------+----------------+
	|            1 | A              |
	+--------------+----------------+
	1 row in set (0.00 sec)
	
	mysql> SAVEPOINT B;
	Query OK, 0 rows affected (0.00 sec)
	
	mysql> SELECT * FROM information_schema.MYSQL_SAVEPOINTS;
	+--------------+----------------+
	| SAVEPOINT_ID | SAVEPOINT_NAME |
	+--------------+----------------+
	|            1 | B              |
	|            2 | A              |
	+--------------+----------------+
	2 rows in set (0.00 sec)
	
	mysql> ROLLBACK TO SAVEPOINT A;
	Query OK, 0 rows affected (0.00 sec)
	
	mysql> SELECT * FROM information_schema.MYSQL_SAVEPOINTS;
	+--------------+----------------+
	| SAVEPOINT_ID | SAVEPOINT_NAME |
	+--------------+----------------+
	|            1 | A              |
	+--------------+----------------+
	1 row in set (0.00 sec)
    
    To uninstall the plugin, use the UNINSTALL PLUGIN syntax.
    Again, please use the exact same case as when you installed the plugin.
    
    mysql> UNINSTALL PLUGIN MYSQL_SAVEPOINTS;
    Query OK, 0 rows affected (0.00 sec)
 */

#ifndef MYSQL_SERVER
#define MYSQL_SERVER
#endif

#include <mysql_priv.h>
#include <stdlib.h>
#include <ctype.h>
#include <mysql_version.h>
#include <mysql/plugin.h>
#include <my_global.h>
#include <my_dir.h>

#define COLUMN_SAVEPOINT_ID 0
#define COLUMN_SAVEPOINT_NAME 1

static ST_FIELD_INFO mysql_is_savepoints_field_info[]=
{
  {"SAVEPOINT_ID", 0, MYSQL_TYPE_LONGLONG, 0, 0, "Savepoint Id"},				
  {"SAVEPOINT_NAME", 64, MYSQL_TYPE_STRING, 0, 0, "Savepoint Name"},				
  {NULL, 0, MYSQL_TYPE_NULL, 0, 0, NULL, 0}
};

//int schema_table_store_record(THD *thd, TABLE *table);

int mysql_is_savepoints_fill_table(THD *thd, TABLE_LIST *tables, COND *cond)
{
  int status = 0;                           /* return value for this func, 0=success, 1=error*/
  CHARSET_INFO *scs= system_charset_info;   /* need this to store field into table */
  TABLE *table= (TABLE *)tables->table;     /* handle to the I_S table. class declared in table.h */
  uint savepoint_id = 0; 

  SAVEPOINT *sv= thd->transaction.savepoints;

  while(sv && !status)
  {
	/* store the savepoint sequence into the table column */
    table->field[COLUMN_SAVEPOINT_ID]->store(++savepoint_id, 0);
    /* store the savepoint name into the table column */
    table->field[COLUMN_SAVEPOINT_NAME]->store(sv->name, strlen(sv->name), scs);

    status= schema_table_store_record(thd, table);
	sv= sv->prev;
  }
  return status;
}

static int mysql_is_savepoints_plugin_init(void *p)
{
  ST_SCHEMA_TABLE *schema= (ST_SCHEMA_TABLE *)p;

  schema->fields_info= mysql_is_savepoints_field_info;
  schema->fill_table= mysql_is_savepoints_fill_table;

  return 0;
}


static int mysql_is_savepoints_plugin_deinit(void *p)
{
	return 0;
}

struct st_mysql_information_schema mysql_is_savepoints_plugin=
{ MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION };

mysql_declare_plugin(mysql_is_savepoints)
{
  MYSQL_INFORMATION_SCHEMA_PLUGIN,                 /* type constant    */
  &mysql_is_savepoints_plugin,                     /* type descriptor  */
  "MYSQL_SAVEPOINTS",                              /* Name             */
  "Roland Bouman (http://rpbouman.blogspot.com/)", /* Author           */
  "Lists all savepoints in the current session.",  /* Description      */
  PLUGIN_LICENSE_GPL,                              /* License          */
  mysql_is_savepoints_plugin_init,                 /* Init function    */
  mysql_is_savepoints_plugin_deinit,               /* Deinit function  */
  0x0010,                                          /* Version (1.0)    */
  NULL,                                            /* status variables */
  NULL,                                            /* system variables */
  NULL                                             /* config options   */
}
mysql_declare_plugin_end;









 </div> 
</div> 
<div id="footer">


    <div class="links">
        <ul>
            <li class="top"><a href="../../index.html">Developer Zone</a></li>
	    <li><a href="../../doc/index.html">Documentation</a></li>
            <li><a href="../../librarian/index.html">Librarian</a></li>
            <li><a href="index.html">Developer Articles</a></li>
			<li><a href="http://dev.mysql.com/news-and-events/">News &amp; Events</a></li>
            <li><a href="http://forums.mysql.com/">Forums</a></li>
            <li><a href="http://bugs.mysql.com/">Bugs</a></li>
            <li><a href="http://forge.mysql.com/">Forge</a></li>
			            <li><a href="http://planet.mysql.com/">Planet MySQL</a></li>
			            <li><a href="http://labs.mysql.com/">Labs</a></li>
        </ul>
    </div>
    
    <div class="links">
        <ul>
            <li class="top"><a href="../../downloads/index.html">Downloads</a></li>
            <li><a href="../../downloads/mysql/index.html">MySQL Community Server</a></li>
            <li><a href="../../downloads/mysql-proxy/index.html">MySQL Proxy</a></li>
            <li><a href="../../downloads/cluster/index.html">MySQL Cluster</a></li>
            <li><a href="../../downloads/workbench/index.html">MySQL Workbench</a></li>
            <li><a href="../../downloads/connector/index.html">Connectors</a></li>
            <li><a href="http://downloads.mysql.com/archives.php">Archives</a></li>
            <li><a href="http://downloads.mysql.com/snapshots.php">Snapshots</a></li>
            <li><a href="../../downloads/mirrors.html">Mirrors</a></li>
        </ul>
    </div>
    
    <div class="links">
        <ul>
            <li class="top"><a href="../../doc/index.html">Documentation</a></li>
            <li><a href="../../doc/index.html">MySQL Reference Manuals</a></li>
            <li><a href="../../doc/index-gui.html">MySQL Workbench</a></li>
            <li><a href="../../doc/index-expert.html">Expert Guides</a></li>
            <li><a href="../../doc/index-topic.html">Topic Guides</a></li>
            <li><a href="../../doc/index-cluster.html">MySQL Cluster</a></li>
            <li><a href="../../doc/index-other.html">Other Documents</a></li>
            <li><a href="../../doc/index-mysqlu.html">MySQL University</a></li> 
            <li><a href="../../doc/index-about.html">About</a></li>     
            <li><a href="../../doc/index-archive.html">Archives</a></li>   
        </ul>
    </div>

    <div class="links">
        <ul>
            <li class="top"><a href="../../support/index.html">Support</a></li>
            <li><a href="http://forge.mysql.com/wiki/Category:MySQLUserGroups">MySQL Meetups</a></li>
            <li><a href="../../guilds/index.html">Guilds</a></li>
            <li><a href="http://lists.mysql.com/">Lists</a></li>
            <li><a href="http://forums.mysql.com/">Forums</a></li>            
		</ul>
			
		<ul>
            <li class="top">Other</li>      
            <li><a href="../../legal/mysql_web_privacy_policy.html">Privacy Policy</a></li>
			<li><a href="../../contact/index.html">Contact Us</a></li>
            <li><a href="../../sitemap.html">Site Map</a></li>
        </ul>
    </div>
    

        
    <div id="search" class="en">
        <form id="footer_search" action="http://search.mysql.com/search" method="get">
            <input type="text" id="f_q" name="q" value="" class="swap_value" onfocus="clearSearchText();" />
	    <input type="image" src="../../common/themes/sakila/footer_search_g.png" id="f_go" alt="Search" title="Search" value="Search" />
        </form>
    </div>

</div><!-- End Footer -->
    
        <div id="copyright-oracle"><a href="http://www.oracle.com/"><img src="../../common/logos/logo-oracle-red-91x22.gif" alt="Oracle" width="91" height="22" border="0" /></a>&nbsp;&nbsp;<span>&copy; 2010, Oracle Corporation and/or its affiliates</span></div>
    
    <script type="text/javascript">
    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
    document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
    </script>
    <script type="text/javascript">
    var pageTracker = _gat._getTracker("UA-225536-3");
    pageTracker._trackPageview();
    </script>

<script type="text/javascript" src="../../common/js/s_code_remote.js?ver=20091011"></script>

</body>
</html>
