In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "mysql string escape function examples". In daily operation, I believe many people have doubts about mysql string escape function examples. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts of "mysql string escape function examples". Next, please follow the editor to study!
Inserting a data table in mysql will cause syntax errors if there is a'\ "in the data. There is no need to explain this, you know, so you need to write an escape function. At first, you want to use string's replace directly, but this method needs to be called three times.
It feels inefficient to put it on the server, so I write one in C, which feels OK. The time complexity has nothing to do with the number of escape characters that need to be escaped. If the source string does not match, there is no need for copy operation.
/ / escape function, 'convert to\'
Bool ConverToDBStr (const char* src,char*dst)
{
Int I =-1 ram / record the location of the last match
Int dOffset = 0 position hand / target string cursor
Int nCopy = 0 copy / the number of bytes that need to be copy this time
Const char*p = src
While (* p)
{
If (* paired bands'\\'| | * paired frames'\'| | * paired fragments'"'")
{
NCopy = p-src-i-1
Memcpy (dst+dOffset,src+i+1,nCopy)
DOffset+=nCopy
* (dst+Offset) ='\\'
* (dst+dOffset+1) = * p
DOffset+=2
I = p-src
}
Pendant +
}
If (dOffset > 0) / / matches the last string of copy
{
Memcpy (dst+dOffset,src+i+1,p-src-i)
Return true
}
Return false
}
As you can see, replace can be implemented with a slight change to this function.
At this point, the study of "mysql string escape function instance" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.