473,382 Members | 1,615 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

String.Split or Regex

Hi all,

I want to import a SQL script (SQLite) executing each queries separately.
- I read the SQL file
- I split the read string with the separator ";"
- I execute each query

Expand|Select|Wrap|Line Numbers
  1. string query = File.ReadAllText("C:\\script.sql");
  2. string[] str = query.Split(';');
  3. for (int i = 0; i < str.Length; i++) {
  4. try {
  5. SQLiteCommand cmd = mDbConnect.CreateCommand();
  6. cmd.CommandText = str[i];
  7. if (cmd.CommandText != string.Empty)
  8. cmd.ExecuteNonQuery();
  9. }
  10. catch (Exception ex) {
  11. Console.WriteLine(str[i] + ex.ToString());
  12. }
  13. }
  14.  
BUT

In the SQL script, the ";" ends not systematically a query. A sample
(two ";" for one query):

Expand|Select|Wrap|Line Numbers
  1. CREATE TRIGGER agent_commune
  2. BEFORE INSERT ON agent
  3. FOR EACH ROW BEGIN
  4. SELECT RAISE(ABORT, 'Impossible de trouver l''enregistrement lié')
  5. WHERE (SELECT Num FROM Commune WHERE Num = NEW.Localite) IS NULL;
  6. END;
  7.  
I've tried using Regex with the following code but it seems wrong.

Expand|Select|Wrap|Line Numbers
  1. string[] str = Regex.Split(query, "[^(END;)?];");
  2.  
Someone can help me?

Regards.

Cédric.
May 14 '07 #1
0 1326

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Blue Ocean | last post by:
In short, it's not working right for me. In long: The program is designed to read numbers from an accumulator and speak them out loud. Unfortunately, the class that contains the method to...
11
by: Martin Robins | last post by:
I am trying to parse a string that is similar in form to an OLEDB connection string using regular expressions; in principle it is working, but certain character combinations in the string being...
19
by: David Logan | last post by:
We need an additional function in the String class. We need the ability to suppress empty fields, so that we can more effectively parse. Right now, multiple whitespace characters create multiple...
1
by: Guadala Harry | last post by:
I have a string that must be split out into a string array. The segment delimiter is like this: {flag:xxx} and the "xxx" part is unknown ahead of time (can be just about any character AND any...
6
by: Bruce Wiebe | last post by:
Hi all I have a string that contains a list of email addresses in the format {"X@y.com","x@y.com"} and i need to convert it to a string array in the same format so my array would loook like ...
16
by: Charles Law | last post by:
I have a string similar to the following: " MyString 40 "Hello world" all " It contains white space that may be spaces or tabs, or a combination, and I want to produce an array...
3
by: Michael D Murphy | last post by:
Hi, I would like to know how to use Regular Expressions to iteratively return and print the items between the colons in the following string to say the console.. Any help would be appreciated....
28
by: Materialised | last post by:
Hi all, Just wondering if someone could help me with this little problem I'm having. I have a string value (it actually represents a barcode) which looks like this: 5021378002392 What I...
24
by: garyusenet | last post by:
I'm working on a data file and can't find any common delimmiters in the file to indicate the end of one row of data and the start of the next. Rows are not on individual lines but run accross...
1
Atli
by: Atli | last post by:
The following small HowTo is a compilation of an original problem in getting some cookie-values through different methods of string-handling. The original Problem was posted as follows: As...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.