MVC Complete Add/Edit/Delete/Details Controller with Entity FrameWork
public class genreController : Controller
{
//
// GET: /genre/
MVCBookStoreEntities db = new MVCBookStoreEntities();
public ActionResult Index()
{
//var model = db.genres.ToList();
//return View(model);
List gen =new List();
gen=db.genres.ToList();
var model=from g in gen
orderby g.GenreId descending
where g.Status==true
select g;
return View(model);
}
//
// GET: /genre/Details/5
public ActionResult Details(int id)
{
var model = db.genres.Find(id);
return View(model);
}
//
// GET: /genre/Create
public ActionResult Create()
{
return View();
}
//
// POST: /genre/Create
[HttpPost]
public ActionResult Create(Genre addgen)
// public ActionResult Create(FormCollection collection)
{
try
{
// TODO: Add insert logic here
//return RedirectToAction("Index");
db.Entry(addgen).State = EntityState.Added;
//db.genres.Add(addgen);
db.SaveChanges();
return RedirectToAction("Index");
}
catch
{
return View();
}
}
//
// GET: /genre/Edit/5
public ActionResult Edit(int id)
{
var model=db.genres.Find(id);
return View(model);
}
//
// POST: /genre/Edit/5
[HttpPost]
public ActionResult Edit(int id, Genre editgen)
//public ActionResult Edit(int id, FormCollection collection)
{
try
{
if (ModelState.IsValid)
{
// TODO: Add update logic here
editgen.GenreId = id;
db.Entry(editgen).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
else {
return RedirectToAction("Index");
}
}
catch
{
return View();
}
}
//
// GET: /genre/Delete/5
public ActionResult Delete(int id)
{
var model = db.genres.Find(id);
return View(model);
}
//
// POST: /genre/Delete/5
[HttpPost]
public ActionResult Delete(int id, Genre deletegen)
{
try
{
if (ModelState.IsValid)
{
// TODO: Add update logic here
deletegen.GenreId = id;
db.Entry(deletegen).State = EntityState.Deleted;
db.SaveChanges();
return RedirectToAction("Index");
}
else
{
return RedirectToAction("Index");
}
}
catch
{
return View();
}
}
}
{
//
// GET: /genre/
MVCBookStoreEntities db = new MVCBookStoreEntities();
public ActionResult Index()
{
//var model = db.genres.ToList();
//return View(model);
List
gen=db.genres.ToList();
var model=from g in gen
orderby g.GenreId descending
where g.Status==true
select g;
return View(model);
}
//
// GET: /genre/Details/5
public ActionResult Details(int id)
{
var model = db.genres.Find(id);
return View(model);
}
//
// GET: /genre/Create
public ActionResult Create()
{
return View();
}
//
// POST: /genre/Create
[HttpPost]
public ActionResult Create(Genre addgen)
// public ActionResult Create(FormCollection collection)
{
try
{
// TODO: Add insert logic here
//return RedirectToAction("Index");
db.Entry(addgen).State = EntityState.Added;
//db.genres.Add(addgen);
db.SaveChanges();
return RedirectToAction("Index");
}
catch
{
return View();
}
}
//
// GET: /genre/Edit/5
public ActionResult Edit(int id)
{
var model=db.genres.Find(id);
return View(model);
}
//
// POST: /genre/Edit/5
[HttpPost]
public ActionResult Edit(int id, Genre editgen)
//public ActionResult Edit(int id, FormCollection collection)
{
try
{
if (ModelState.IsValid)
{
// TODO: Add update logic here
editgen.GenreId = id;
db.Entry(editgen).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
else {
return RedirectToAction("Index");
}
}
catch
{
return View();
}
}
//
// GET: /genre/Delete/5
public ActionResult Delete(int id)
{
var model = db.genres.Find(id);
return View(model);
}
//
// POST: /genre/Delete/5
[HttpPost]
public ActionResult Delete(int id, Genre deletegen)
{
try
{
if (ModelState.IsValid)
{
// TODO: Add update logic here
deletegen.GenreId = id;
db.Entry(deletegen).State = EntityState.Deleted;
db.SaveChanges();
return RedirectToAction("Index");
}
else
{
return RedirectToAction("Index");
}
}
catch
{
return View();
}
}
}
Installation of EntityFramework 6.0.0-beta1
Microsoft Visual Studio 2012
Tools
Library Package Manager
Package Manager Console
Then
Tools
Library Package Manager
Package Manager Console
Then
PM> Install-Package EntityFramework
-Pre required Internet Connection............ Scaffold (programming)
Scaffolding is a technique supported by some model-view-controller frameworks, in which the programmer may write a specification that describes how the application database may be used. The compiler uses this specification to generate code that the application can use to create, read, update and delete database entries, effectively treating the template as a "scaffold" on which to build a more powerful application.
Introduction to LINQ
Language-Integrated Query (LINQ) is an innovation
introduced in Visual Studio 2008 and .NET Framework version 3.5 that
bridges the gap between the world of objects and the world of data.
Traditionally, queries against data are expressed as simple strings without type checking at compile time or IntelliSense support. Furthermore, you have to learn a different query language for each type of data source: SQL databases, XML documents, various Web services, and so on. LINQ makes a query a first-class language construct in C# and Visual Basic. You write queries against strongly typed collections of objects by using language keywords and familiar operators. The following illustration shows a partially-completed LINQ query against a SQL Server database in C# with full type checking and IntelliSense support.
In Visual Studio you can write LINQ queries in Visual Basic
or C# with SQL Server databases, XML documents, ADO.NET Datasets, and
any collection of objects that supports IEnumerable or the generic IEnumerable<T>
interface. LINQ support for the ADO.NET Entity Framework is also
planned, and LINQ providers are being written by third parties for many
Web services and other database implementations.
You can use LINQ queries in new projects, or alongside non-LINQ queries in existing projects. The only requirement is that the project target .NET Framework 3.5 or later.
Traditionally, queries against data are expressed as simple strings without type checking at compile time or IntelliSense support. Furthermore, you have to learn a different query language for each type of data source: SQL databases, XML documents, various Web services, and so on. LINQ makes a query a first-class language construct in C# and Visual Basic. You write queries against strongly typed collections of objects by using language keywords and familiar operators. The following illustration shows a partially-completed LINQ query against a SQL Server database in C# with full type checking and IntelliSense support.
You can use LINQ queries in new projects, or alongside non-LINQ queries in existing projects. The only requirement is that the project target .NET Framework 3.5 or later.
Introduction to Generic Classes and Inheritance
Consider the following geometric figures:
|
|
|
|
|
| Square | Rectangle | Trapezoid | Parallelogram |
Notice that these are geometric figures with each having
four sides. From what we know so far, we can create a base class to prepare
it for inheritance. If the class is very general, we can make it a generic
one. We can set a data type as an unknown type, anticipating that the
dimensions of the figure can be considered as integer or double-precision
types. Here is an example:
using System; public class Quadrilateral{ protected T _base; protected T _height; protected string _name; public virtual T Base { get { return _base; } set { _base = value; } } public virtual T Height { get { return _height; } set { _height = value; } } public virtual string Name { get { return _name; } set { _name = value; } } public Quadrilateral(string name = "Quadrilateral") { _name = name; } public Quadrilateral(T bs, T height) { _name = "Quadrilateral"; _base = bs; _height = height; } public Quadrilateral(string name, T bs, T height) { _name = name; _base = bs; _height = height; } public virtual string Describe() { return "A quadrilateral is a geometric figure with four sides"; } public virtual void ShowCharacteristics() { Console.WriteLine("Geometric Figure: {0}", Name); Console.WriteLine("Description: {0}", Describe()); Console.WriteLine("Base: {0}", Base); Console.WriteLine("Height: {0}", Height); } } public class Exercise { static int Main() { // Trapezoid with equal sides var Kite = new Quadrilateral ("Beach Kite", 18.64, 18.64); Kite.ShowCharacteristics(); Console.WriteLine(); // Rectangle, in meters var BasketballStadium = new Quadrilateral (); BasketballStadium.Name = "Basketball Stadium"; BasketballStadium.Base = 15; BasketballStadium.Height = 28; BasketballStadium.ShowCharacteristics(); Console.WriteLine(); return 0; } }
This would produce:
Geometric Figure: Beach Kite Description: A quadrilateral is a geometric figure with four sides Base: 18.64 Height: 18.64 Geometric Figure: Basketball Stadium Description: A quadrilateral is a geometric figure with four sides Base: 15 Height: 28 Press any key to continue . . .
If you have a generic class that can serve as a
foundation for another class, you can derive a class from the generic one.
To do this, use the formula we apply when deriving a class but follow the
name of each class with <>. Inside of the <> operator, enter the same
identifier to indicate that the class is a generic type that is based on
another generic class. Here is an example:
public class Square: Quadrilateral { }
In the body of the new class, you can use the parameter
type as you see fit. For example, you can declare some member variables of
that type. You can create methods that return the parameter type or you can
pass arguments of the parameter type. When implementing the methods of the
new class, use the member variables of the parameter and the argument(s)
based on the parameter type as you see fit. You can then declare a variable
of the class and use it as we done so far for other generic classes. Here is
an example:
using System; public class Quadrilateral{ protected T _base; protected T _height; protected string _name; public virtual T Base { get { return _base; } set { _base = value; } } public virtual T Height { get { return _height; } set { _height = value; } } public virtual string Name { get { return _name; } set { _name = value; } } public Quadrilateral(string name = "Quadrilateral") { _name = name; } public Quadrilateral(T bs, T height) { _name = "Quadrilateral"; _base = bs; _height = height; } public Quadrilateral(string name, T bs, T height) { _name = name; _base = bs; _height = height; } public virtual string Describe() { return "A quadrilateral is a geometric figure with four sides"; } public virtual void ShowCharacteristics() { Console.WriteLine("Geometric Figure: {0}", Name); Console.WriteLine("Description: {0}", Describe()); Console.WriteLine("Base: {0}", Base); Console.WriteLine("Height: {0}", Height); } } public class Square : Quadrilateral { public Square() { _name = "Square"; } public Square(string name) { _name = "Square"; } public Square(T side) { _name = "Square"; _base = side; _height = side; } public Square(string name, T side) { _name = name; _base = side; _height = side; } public override string Describe() { return "A square is a quadrilateral with four equal sides"; } public override void ShowCharacteristics() { Console.WriteLine("Geometric Figure: {0}", Name); Console.WriteLine("Description: {0}", Describe()); Console.WriteLine(" {0}", Describe()); Console.WriteLine("Side: {0}", Base); } } public class Exercise { static int Main() { // Rectangle, in meters var plate = new Square (); plate.Name = "Plate"; plate.Base = 15; plate.Height = 28; plate.ShowCharacteristics(); Console.WriteLine(); return 0; } }
This would produce:
Geometric Figure: Plate
Description: A quadrilateral is a geometric figure with four sides
A square is a quadrilateral with four equal sides
Side: 15
Press any key to continue . . .
5 Different Ways to Declare Functions in jQuery
From jQuery4u
Introduction
Choosing which way to declare a JavaScript function can be confusing for beginners as there are several different ways to declare functions using JavaScript/jQuery. I’ll try to explain the benefits of each one and how and why you might use them when writing your awesome jQuery code.1. The basic JavaScript function
This is the simplest way to declare a function in JavaScript. Say for example, we want to write a simple function called multiply(x,y) which simply takes in two parameters x and y, does a simple x times y and returns the value. Here are a few ways you might go about doing exactly this.If you wanted a quick function to test something then maybe that’s the only occasion you would use this. It’s not good coding and doesn’t promote code reuse.
2. JavaScript functions for get/set
If you need a private utility for getting/setting/deleting model values then you can declare a function as a variable like this. This could be useful for assigning a variable upon declaration calculated by a function.
var multiply = function(x,y) {
return (x * y);
}
console.log(multiply(2,2));
//output: 4
//The same function but with a self execution to set the value of the variable:
var multiply = function(x,y) {
return (x * y);
}(2,2);
console.log(multiply);
//output: 4
return (x * y);
}
console.log(multiply(2,2));
//output: 4
//The same function but with a self execution to set the value of the variable:
var multiply = function(x,y) {
return (x * y);
}(2,2);
console.log(multiply);
//output: 4
3. Create your own jQuery function
This is an awesome way to declare functions that can be used just like your regular jQuery functions, on your DOM elements! Rememeber jQuery.fn is just an alias for jQuery.prototype (which just saves us time when coding such jQuery.fn.init.prototype = jQuery.fn = $.fn as such).
jQuery.fn.extend({
zigzag: function () {
var text = $(this).text();
var zigzagText = '';
var toggle = true; //lower/uppper toggle
$.each(text, function(i, nome) {
zigzagText += (toggle) ? nome.toUpperCase() : nome.toLowerCase();
toggle = (toggle) ? false : true;
});
return zigzagText;
}
});
console.log($('#tagline').zigzag());
//output: #1 jQuErY BlOg fOr yOuR DaIlY NeWs, PlUgInS, tUtS/TiPs & cOdE SnIpPeTs.
//chained example
console.log($('#tagline').zigzag().toLowerCase());
//output: #1 jquery blog for your daily news, plugins, tuts/tips & code snippets.
zigzag: function () {
var text = $(this).text();
var zigzagText = '';
var toggle = true; //lower/uppper toggle
$.each(text, function(i, nome) {
zigzagText += (toggle) ? nome.toUpperCase() : nome.toLowerCase();
toggle = (toggle) ? false : true;
});
return zigzagText;
}
});
console.log($('#tagline').zigzag());
//output: #1 jQuErY BlOg fOr yOuR DaIlY NeWs, PlUgInS, tUtS/TiPs & cOdE SnIpPeTs.
//chained example
console.log($('#tagline').zigzag().toLowerCase());
//output: #1 jquery blog for your daily news, plugins, tuts/tips & code snippets.
4. Extend Existing jQuery Functions
(or which either extend existing jQuery functions with extra functionality or creating your own functions that can be called using the jQuery namespace (usually, we use the $ sign to represent the jQuery namespace). In this example the $.fn.each function has been modified with custom behaviour.
(function($){
// maintain a to the existing function
var oldEachFn = $.fn.each;
$.fn.each = function() {
// original behavior - use function.apply to preserve context
var ret = oldEachFn.apply(this, arguments);
// add custom behaviour
try {
// change background colour
$(this).css({'background-color':'orange'});
// add a message
var msg = 'Danger high voltage!';
$(this).prepend(msg);
}
catch(e)
{
console.log(e);
}
// preserve return value (probably the jQuery object...)
return ret;
}
// run the $.fn.each function as normal
$('p').each(function(i,v)
{
console.log(i,v);
});
//output: all paragrahs on page now appear with orange background and high voltage!
})(jQuery);
// maintain a to the existing function
var oldEachFn = $.fn.each;
$.fn.each = function() {
// original behavior - use function.apply to preserve context
var ret = oldEachFn.apply(this, arguments);
// add custom behaviour
try {
// change background colour
$(this).css({'background-color':'orange'});
// add a message
var msg = 'Danger high voltage!';
$(this).prepend(msg);
}
catch(e)
{
console.log(e);
}
// preserve return value (probably the jQuery object...)
return ret;
}
// run the $.fn.each function as normal
$('p').each(function(i,v)
{
console.log(i,v);
});
//output: all paragrahs on page now appear with orange background and high voltage!
})(jQuery);
5. Functions in custom namespaces
If your writing functions in a custom namespace you must declare them in this way. Extra functions can be added to the namespace you just need to add a comma after each one (except the last one!). If your unsure about namespacing see jQuery Function Namespacing in Plain EnglishConclusion
Knowing when and how to declare different types of JavaScript/jQuery functions is definitely something any good js developer should know inside out.An Introduction to Stored Procedures in MySQL 5
Introduction
“ A stored routine is a set of SQL statements that can be stored in the server.”A stored procedure is a method to encapsulate repetitive tasks. They allow for variable declarations, flow control and other useful programming techniques.
The “academic” position on this is quite clear and supports the extensive use of stored procedures. On the other hand, when you consider the opinions of those who work with them day in, day out, you’ll notice that reactions vary from complete, unwavering support to utter hate. Keep these in mind.
Pros
- Share logic with other applications. Stored procedures encapsulate functionality; this ensures that data access and manipulation are coherent between different applications.
- Isolate users from data tables. This gives you the ability to grant access to the stored procedures that manipulate the data but not directly to the tables.
- Provide a security
mechanism. Considering the prior item, if you can only access the data
using the stored procedures defined, no one else can execute a
DELETESQL statement and erase your data. - To improve performance because it reduces network traffic. With a stored procedure, multiple calls can be melded into one.
Cons
- Increased load on the database server — most of the work is done on the server side, and less on the client side.
- There’s a decent learning curve. You’ll need to learn the syntax of MySQL statements in order to write stored procedures.
- You are repeating the logic of your application in two different places: your server code and the stored procedures code, making things a bit more difficult to maintain.
- Migrating to a different database management system (DB2, SQL Server, etc) may potentially be more difficult.
Additionally, I’ll be using very rudimentary table structures, strictly to ease the explanation. I’m showing off stored procedures, and they’re complex enough without worrying about big tables.
Step 1 – Picking a Delimiter
The delimiter is the character or string of characters that you’ll use to tell the mySQL client that you’ve finished typing in an SQL statement. For ages, the delimiter has always been a semicolon. That, however, causes problems, because, in a stored procedure, one can have many statements, and each must end with a semicolon. In this tutorial I will use “//”Step 2 – How to Work with a Stored Procedure
Creating a Stored Procedure
- DELIMITER //
- CREATE PROCEDURE `p2` ()
- LANGUAGE SQL
- DETERMINISTIC
- SQL SECURITY DEFINER
- COMMENT 'A procedure'
- BEGIN
- SELECT 'Hello World !';
- END//
Stored procedure names are case insensitive, and you cannot create procedures with the same name. Inside a procedure body, you can’t put database-manipulation statements.
The four characteristics of a procedure are:
- Language : For portability purposes; the default value is SQL.
- Deterministic
: If the procedure always returns the same results, given the same
input. This is for replication and logging purposes. The default value
is
NOT DETERMINISTIC. - SQL Security : At call time, check privileges of the user.
INVOKERis the user who calls the procedure.DEFINERis the creator of the procedure. The default value isDEFINER. - Comment : For documentation purposes; the default value is
""
Calling a Stored Procedure
To call a procedure, you only need to enter the wordCALL,
followed by the name of the procedure, and then the parentheses,
including all the parameters between them (variables or values).
Parentheses are compulsory.- CALL stored_procedure_name (param1, param2, ....)
- CALL procedure1(10 , 'string parameter' , @parameter_var);
Modify a Stored Procedure
MySQL provides anALTER PROCEDURE
statement to modify a routine, but only allows for the ability to
change certain characteristics. If you need to alter the body or the
parameters, you must drop and recreate the procedure.Delete a Stored Procedure
- DROP PROCEDURE IF EXISTS p2;
IF EXISTS clause prevents an error in case the procedure does not exist.Step 3 – Parameters
Let’s examine how you can define parameters within a stored procedure.CREATE PROCEDURE proc1 (): Parameter list is emptyCREATE PROCEDURE proc1 (IN varname DATA-TYPE): One input parameter. The wordINis optional because parameters areIN(input) by default.CREATE PROCEDURE proc1 (OUT varname DATA-TYPE): One output parameter.CREATE PROCEDURE proc1 (INOUT varname DATA-TYPE): One parameter which is both input and output.
IN example
- DELIMITER //
- CREATE PROCEDURE `proc_IN` (IN var1 INT)
- BEGIN
- SELECT var1 + 2 AS result;
- END//
OUT example
- DELIMITER //
- CREATE PROCEDURE `proc_OUT` (OUT var1 VARCHAR(100))
- BEGIN
- SET var1 = 'This is a test';
- END //
INOUT example
- DELIMITER //
- CREATE PROCEDURE `proc_INOUT` (OUT var1 INT)
- BEGIN
- SET var1 = var1 * 2;
- END //
Step 4 – Variables
The following step will teach you how to define variables, and store values inside a procedure. You must declare them explicitly at the start of theBEGIN/END block, along with their data types. Once
you’ve declared a variable, you can use it anywhere that you could use
a session variable, or literal, or column name.- DECLARE varname DATA-TYPE DEFAULT defaultvalue;
- DECLARE a, b INT DEFAULT 5;
- DECLARE str VARCHAR(50);
- DECLARE today TIMESTAMP DEFAULT CURRENT_DATE;
- DECLARE v1, v2, v3 TINYINT;
Working with variables
Once the variables have been declared, you can assign them values using theSET or SELECT command:- DELIMITER //
- CREATE PROCEDURE `var_proc` (IN paramstr VARCHAR(20))
- BEGIN
- DECLARE a, b INT DEFAULT 5;
- DECLARE str VARCHAR(50);
- DECLARE today TIMESTAMP DEFAULT CURRENT_DATE;
- DECLARE v1, v2, v3 TINYINT;
- INSERT INTO table1 VALUES (a);
- SET str = 'I am a string';
- SELECT CONCAT(str,paramstr), today FROM table2 WHERE b >=5;
- END //
Step 5 – Flow Control Structures
MySQL supports the IF, CASE, ITERATE, LEAVE LOOP, WHILE and REPEAT constructs for flow control within stored programs. We’re going to review how to use IF, CASE and WHILE specifically, since they happen to be the most commonly used statements in routines.
IF statement
With the IF statement, we can handle tasks which involves conditions:- DELIMITER //
- CREATE PROCEDURE `proc_IF` (IN param1 INT)
- BEGIN
- DECLARE variable1 INT;
- SET variable1 = param1 + 1;
- IF variable1 = 0 THEN
- SELECT variable1;
- END IF;
- IF param1 = 0 THEN
- SELECT 'Parameter value = 0';
- ELSE
- SELECT 'Parameter value <> 0';
- END IF;
- END //
CASE statement
The CASE statement is another way to check conditions and take the appropriate path. It’s an excellent way to replace multiple IF statements. The statement can be written in two different ways, providing great flexibility to handle multiple conditions.- DELIMITER //
- CREATE PROCEDURE `proc_CASE` (IN param1 INT)
- BEGIN
- DECLARE variable1 INT;
- SET variable1 = param1 + 1;
- CASE variable1
- WHEN 0 THEN
- INSERT INTO table1 VALUES (param1);
- WHEN 1 THEN
- INSERT INTO table1 VALUES (variable1);
- ELSE
- INSERT INTO table1 VALUES (99);
- END CASE;
- END //
- DELIMITER //
- CREATE PROCEDURE `proc_CASE` (IN param1 INT)
- BEGIN
- DECLARE variable1 INT;
- SET variable1 = param1 + 1;
- CASE
- WHEN variable1 = 0 THEN
- INSERT INTO table1 VALUES (param1);
- WHEN variable1 = 1 THEN
- INSERT INTO table1 VALUES (variable1);
- ELSE
- INSERT INTO table1 VALUES (99);
- END CASE;
- END //
WHILE statement
There are technically three standard loops: WHILE loops, LOOP loops, and REPEAT loops. You also have the option of creating a loop using the “Darth Vader” of programming techniques: the GOTO statement. Check out this example of a loop in action:- DELIMITER //
- CREATE PROCEDURE `proc_WHILE` (IN param1 INT)
- BEGIN
- DECLARE variable1, variable2 INT;
- SET variable1 = 0;
- WHILE variable1 < param1 DO
- INSERT INTO table1 VALUES (param1);
- SELECT COUNT(*) INTO variable2 FROM table1;
- SET variable1 = variable1 + 1;
- END WHILE;
- END //
Step 6 - Cursors
Cursor is used to iterate through a set of rows returned by a query and process each row.
MySQL supports cursor in stored procedures. Here's a summary of the essential syntax to create and use a cursor.- DECLARE cursor-name CURSOR FOR SELECT ...; /*Declare and populate the cursor with a SELECT statement */
- DECLARE CONTINUE HANDLER FOR NOT FOUND /*Specify what to do when no more records found*/
- OPEN cursor-name; /*Open cursor for use*/
- FETCH cursor-name INTO variable [, variable]; /*Assign variables with the current column values*/
- CLOSE cursor-name; /*Close cursor after use*/
- DELIMITER //
- CREATE PROCEDURE `proc_CURSOR` (OUT param1 INT)
- BEGIN
- DECLARE a, b, c INT;
- DECLARE cur1 CURSOR FOR SELECT col1 FROM table1;
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET b = 1;
- OPEN cur1;
- SET b = 0;
- SET c = 0;
- WHILE b = 0 DO
- FETCH cur1 INTO a;
- IF b = 0 THEN
- SET c = c + a;
- END IF;
- END WHILE;
- CLOSE cur1;
- SET param1 = c;
- END //
- Asensitive : Once open, the cursor will not reflect changes in its source tables. In fact, MySQL does not guarantee the cursor will be updated, so you can't rely on it.
- Read Only : Cursors are not updatable.
- Not Scrollable : Cursors can be traversed only in one direction, forward, and you can't skip records from fetching.
Conclusion
In this lesson, we covered the fundamentals of stored procedures and some specific properties pertaining to them. Of course, you should continue your studies in areas like security, SQL statements, and performance before you can master MySQL routines.You have to evaluate the advantages that stored procedures can potentially bring to your applications, and then make a reasonable implementation that fits your requirements. I generally use procedures; their benefits in terms of security, code maintenance and software design make them worthy of use, in my opinion. Additionally, remember that procedures in MySQL are still a work in progress. You should fully expect improvements, in terms of functionality and performance in the future. Please don't hesitate to comment and share your ideas and opinions.
Subscribe to:
Posts
(
Atom
)