Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Take a string, turn it into some DB commands (C#)

I need to write something in C# that allows users to query data in a human-readable format. So in a textarea, they would type in this:

Students.Class, name, address, classid, grade

Which would result in:

Marcus, 11B Westbury Ave. 200718, A+

What the above should do is: Look in the students DB, joining on the class table, then retrieving the name, address, classid, grade.

I have tried writing my own parsing method, splitting the string into an array and then based on the data in the array, querying the database. However, the issue that I am now having is that some users are making mistakes with the syntax:

Students, name, address, classid, grade

(Missing out the .class bit). So I have to throw try/catch methods and present the User with error messages.

The simple method above works, but I am wondering if there are any libraries out there that will take my string data and do what I am after?

like image 290
Marcus Aurelio Avatar asked May 07 '17 06:05

Marcus Aurelio


People also ask

How do I convert a string to lowercase in MySQL?

MySQL LOWER() Function The LOWER() function converts a string to lower-case. Note: The LCASE() function is equal to the LOWER() function.

What is returned by Instr (' Hello World w ')?

The INSTR() function returns the position of the first occurrence of a string in another string.


1 Answers

you want create parse at this way you need to learn flex and bison but there is a links can help you to create that.

https://www.codeproject.com/Articles/220042/Easily-Create-Your-Own-Parser https://www.codeproject.com/Articles/664785/A-New-Parser-Generator-for-Csharp

like image 176
Shahrooz Ansari Avatar answered Oct 02 '22 23:10

Shahrooz Ansari