I want to parse the SQL code of a file .sql using C#.
I want determinate Syntax Check of a file sql, specifically Insert, Update and Delete statements.
Specifically is there any parser freely available which can parse the SQL code in C# .NET ? better is freeware, source code included, and easy use.
I use Oracle
You can try with ANTLR.
On grammar page you will find several grammars related to Oracle.
Unrelated, is there a way to just "Prepare" statement without execution? That way you could have Oracle check syntax and then catch eventual errors in your code. This will help you skip duplicating functionality already present in Oracle. Not to mention problem of handling changes between different versions of Oracle.
Edit:
Re comment about code examples: I used ANTLR briefly and I had hard time finding code examples on internet. Main source I found was examples from ANTLR download page. Now I see that Terence Parr, author of ANTLR, published new book and that accompanying source code contains more ANTLR examples.
Since you don't have much experience with ANTLR, may I, again, suggest that you try another approach, since this is fairly complex area and needs considerable learning effort to get you started. At least, that was my experience.
General SQL Parser can do offline SQL syntax check without connecting to a database. It's support Oracle, SQL Server, DB2, MySQL, MS-ACCESS, Teradata and PostGreSQL.
But it's a commercial SQL library and not open source.
The miniSqlParser can parse and check SQL statements. This is a assembly of C# and open source. SQL Formatter is a web application of indenting SQLs, that use this assembly. Please try it.
Related
In the past I was able to use SQL select statements on a flat file from VBA from within Excel.
How can I do something similar in C# using VS 2013?
As an overview, I'm creating a desktop app that needs to search a static table of ~100k rows and 6 columns and I'm thinking it doesn't warrant incorporating a real db.
Any pointers or other ideas out there?
Fred
LINQ is made for this. It's a layer between 'something' (text file, database, XML etc.) and the LINQ language. Take a look here.
Linq To Text Files
Microsoft has a great tool for querying different filetypes: It's called log parser .
I personally use it for parsing IIS logs ( *.csv)
Have fun ;-)
I work for a company that uses a program that uses Foxpro as its database.
I'm actually a little bit confused if Visual FoxPro is just a DB or its a programming lagnauge + database combined.
I want to create some software to integrate with it, but I just need to manipulate the date in the database (As i do not have access to the source).
Is there a SQL Management Studio equalivelent to Visual FoxPro, and can I see the tables and data by looking at the Database files? or is it all integrated some how into the programming and I would need the source to manipulate it?
The best SQL Management Studio equivalent would be the VFP IDE. However, as a C# developer you might prefer to use LINQPad so that you can work with the data using LINQ and not have to know anything about the VFP syntax. As far as writing some C# code to manipulate VFP data… I would suggest checking out LINQ to VFP and the VFP EF Provider.
Full disclosure: I wrote the LINQPad Provider, LINQ to VFP, and the VFP EF Provider so I might be a bit bias :)
Visual Foxpro is both a programming language AND a database all wrapped into one. If you can get Visual Foxpro, you can do you own programming and directly work with opening the tables, updating them, etc as you need.
Additionally, Microsoft has an OleDbProvider that can hook up to VFP tables and do all your common select/insert/update/delete functionality too. So, that said, you can use whatever .net you might be comfortable with. I personally use C# and the Microsoft OleDbProvider and have built some websites with it and also desktop apps too, all going directly to the tables. The only issue is IF any of the tables are encrypted using a third-party encryption tool.
I and others have had many posts on how to connect with VFP to select, insert and update data, so you can obviously feel free to look that up. I would start by using tag search such as
C# VFP OleDb
And you'll always be able to ask again here to get answers when you get stuck :)
Without FoxPro itself (think access) you are messing about with ODBC and writing it all yourself. or better yet (apparently) there's an OLEDB provider for it.
Sm OLE DB Provider for Visual FoxPro
and like #Tim Medora, I'm sorry.
No need for anyone to say 'I'm sorry' and as Alan B said, there are more FoxPro apps out there than most folks will ever realize. I for one have made a good living out of converting MS Access apps to FoxPro due to Access cratering with large data files.
FoxPro is both a Database (Think RDBMS systems) and a great rapid application development tool. You can easily read the tables through the OleDbProvider, and if you're using it as a front end you can easily connect to ANY of the main Databases. I personally have apps that connect to MySql, Sql-Server.
Writing an application in C# to read and return the data in FoxPro tables is actually quite simple if you're using Visual Studio 2010 and Tom gives some excellent links for info on how to accomplish what you're trying to do
I am developing a small application with ASP and C# in .NET and I want to have a small local database next to it where I can save and retrieve records by either SQL queries or Linq queries. I don't need anything powerful, just something to use instead of keeping records in .txt files.
So what's your suggestion?
Use SQLite
It does not have to be installed and is just a DB File and there are connectors to .Net available.
And you can use LINQ
I would go with either SQLLite or with XML since you are saying very small database.
And with xml you can use Linq to xml
You can use SQL CE or SQLite.
Best to use SQL Express edition since it comes for free. Try using .NET entity framework code first for rapid application development.
In any case application is very small consider using SQL express since you can write neat and clean stored procedures and can play with other database objects.
Please refer http://www.microsoft.com/sqlserver/en/us/editions/express.aspx for more details.
I'll consider SQLite for this purposes.
If you are more comfortable with MS tools, or for some reason (i.e. your company already has a well formed mdb database file) you can use MS Access too, for local and small applications.
I recommend you to use SQL Server Express, becuase
It is free to use and easy to install
You can easily use either Entity Framework or LINQ TO SQL to manipulate your data
It can easily communicate with your company's DB ( if it is also SQL Server), for example, one day in the future, you may need to test the replication.
No one's mentioned it yet so here it is. mySQL and the .Net mySQL client.
In your case I would consider the following:
XML if you don't with more than a couple hundred records in all tables. And #Ali mentioned already LINQ to XML what will be handy.
VistaDB, because it's 100% managed code and require deployment of just one small assembly for both 32- and 64-bit.
SQL CE, just because it's the most popular one. Of course, it supports LINQ and concurrency.
SQLite as an alternative for SQL CE :)
Don't go with SQL Express unless it's been already provided by your hoster. It increases complexity of distributing/installing of your solution.
Hey, what's the easiest way to use a file-based database with LINQ in C#? It would be best if I could use it without installing extra components.
EDIT: I want to use it for a file index. Not the whole file system, but the database should be not too slow and not too big.
I'd recommend MS SQL Server Compact Edition. Its embedable, small footprint, good performance and you can use Linq2Sql to query it easily. Also it integrates well with Visual Studio IDE and SQL Management Studio.
Are you opposed to using XML?
That's basically what XML is (or, rather, is a major use of XML), and Linq to XML is very powerful.
The way i've implemented this kind of thing previously is to load a csv file into a C# List structure (couldn't say which is best without information on the data), and use Linq to access data from there.
This may not be the best solution for you, but you have given limited information on what you're looking for.
You will always need to install database drivers to talk to a specific database. The only way to avoid that is to create your own driver to talk to a database, or even create your own database engine.
However, both SQLite and VistaDB have LINQ to SQL now. Other alternatives are to use a text file or XML file for your "database."
Complete newbie question here: I'm just playing with C# for the first time and want to make a Windows Forms application which stores some info in a database structure, but obviously don't want to require something like MySQL to be installed on each client's computer. How do I go about this?
You can use SQLite. It doesn't require any installation or server on the client's computers. Here is an blog describing how to use it with .NET. It is easy to use, just add a reference to the System.Data.SQLite.dll.
Here is an open source data provider for .NET: System.Data.SQLite
From homepage: "SQLite is a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine. SQLite is the most widely deployed SQL database engine in the world. The source code for SQLite is in the public domain."
You use a database that doesn't require an install. There are a few out there - there's Microsoft SQL Server Compact, which frankly is badly named, as it won't support the more useful SQL functions like stored procedures, views and so on. There's also VistaDB which does support stored procs, but requires purchase if you want Visual Studio plugins.
The answer is Embedded Databases. You've got quite a large list of Embedded databases that you can use:
Commercial:
VistaDB - This database is written completely in managed C#.
Open Source:
Firebird - .NET Driver
SQLite - .NET Driver
You could write your data to XML files, or you could take a look at the Sql Server Compact Edition.
You could also work with objects and serialize/deserialize these to disk as binaries.
Of course the type of storage you choose depends a lot on the kind of data you're storing (and the volume of it).
Use SQL Server CE
An easy way to do it from .NET 3.5 onwards is to store your data in XML files and use Linq to XML. This allows you to use SQL-like commands on your data which are actually compiled into your application, so you get full IDE IntelliSense support and error checking.
Perhaps you could serialise a dataset and save it as XML. I'm a little confused why if you're playing around you would need to install MySQL on all client's computers. You could look at using SQL Express which is free perhaps?
Serialise Dataset:
http://blogs.msdn.com/yosit/archive/2003/07/10/9921.aspx
http://msdn.microsoft.com/en-us/magazine/cc163911.aspx
The Easiest way will be SQL Server Compact, Because it integrates directly into the Visual Studio IDE (I'm just hazarding the guess here that you use VS). Add the "Local Database", Create your tables and be sure to make your Table Adapter with Select, Update, Insert and Delete methods. If during Database Creation you called your Dataset "DS" you will be able to instantiate a Table Adapter Object from
DSTableAdapters
Namespace, and Use GetData() or Fill() methods to retrieve your Data, and Insert(), Update() and Delete() to Manage it.
VelocityDB works in a server less mode but can also be combined with a server when there is a need for it. It outperforms all the other choices mentioned here by roughly a magnitude, see comparison here. It allows you to use almost any .NET data structures persistently. The entire database engine and the optional server is implemented using C# code.