Database Component hxj. Data () (MySQL)

Source: Internet
Author: User

MySQL support is added to component v1.7 (MySQL 5.1 is tested ).

The following shows how to use it.

First add connectionstring

<add name="MySQLConnectionString" connectionString="server=192.168.1.175;user id=root; password=huxj; Port=3306;database=test;" providerName="Hxj.Data.MySql" />
 
public static DbSession MySqlTest = new DbSession("MySQLConnectionString");
 

A new table mtable is created in the test database. There are only two fields: Mid int auto-increment, mname varchar (50)
 
Then, use the object generation tool to generate an object.
 
The code for adding data to the test is as follows:
Mtable m = new Mtable();m.Mname = Hxj.Common.StringHelper.GetRandomString();int returnValue = Db.MySqlTest.Insert<Mtable>(m);

The generated SQL statement is as follows:

Text:    
INSERT INTO `mtable` (`mname`) VALUES (?swbeetoamhazjwa);select last_insert_id();

Parameters:
?swbeetoamhazjwa[String] = wzfJPJIDvKPP15HKRyxO4w==

 

 

Then test batch addition:

using (DbBatch batch = Db.MySqlTest.BeginBatchConnection(5)){    for (int i = 0; i < 10; i++)    {        Mtable m = new Mtable();        m.Mname = Hxj.Common.StringHelper.GetRandomString();        batch.Insert<Mtable>(m);    }}

The generated SQL statement is as follows:

Text:    
INSERT INTO `mtable` (`mname`) VALUES (?tksvpwwdiguovrlq);INSERT INTO `mtable` (`mname`) VALUES (?ttnbgzirzhvlssuv);INSERT INTO `mtable` (`mname`) VALUES (?eotxpjjzywvzzcro);INSERT INTO `mtable` (`mname`) VALUES (?xemplfkdzouwbwzx);INSERT INTO `mtable` (`mname`) VALUES (?ulyiapnhhwkufzxn);
Parameters:
?tksvpwwdiguovrlq[String] = oYCY91wzpUnDA5TOiPtL9g==
?ttnbgzirzhvlssuv[String] = TEtLPO3QvuUEGeHTuoufhw==
?eotxpjjzywvzzcro[String] = k0Gs4Ndf4Kjp/1m973CMwA==
?xemplfkdzouwbwzx[String] = MIH1LPkpa2HwPnIJmNUmnA==
?ulyiapnhhwkufzxn[String] = NIni89feCPwRLspG1BFevg==

Text:
INSERT INTO `mtable` (`mname`) VALUES (?rkqfafnpxtfyqaka);INSERT INTO `mtable` (`mname`) VALUES (?ymfmodryykkiozcc);INSERT INTO `mtable` (`mname`) VALUES (?ztwdwxcwnkrdfzvd);INSERT INTO `mtable` (`mname`) VALUES (?pugtkuoehuqavxch);INSERT INTO `mtable` (`mname`) VALUES (?igthuzfzqopddexr);
Parameters:
?rkqfafnpxtfyqaka[String] = u/rxTfVKLkvymn5+U3gARA==
?ymfmodryykkiozcc[String] = ypsRx4kDZPjH/MRrwoHegA==
?ztwdwxcwnkrdfzvd[String] = DnzF82DWq5313Vg7LWPKxA==
?pugtkuoehuqavxch[String] = qNQ058RJ4fZSDQocALGVaQ==
?igthuzfzqopddexr[String] = 9fv5ZpttbcicvT5M573jGA==

Five SQL statements are executed in combination once.

 

Then perform the query:

Db.MySqlTest.From<Mtable>().Page(10, 2).ToList();

The generated SQL statement is as follows:

Text:     
SELECT * FROM `mtable` ORDER BY `mtable`.`mid` ASC limit 10,10

 

In other examples, the code is no longer displayed, and the operations are the same as before.

 

Download

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.