A NpgsqlConnection object is created. This object is used to open a connection to a database. The using statement releases the database connection resource when the variable goes out of scope. It returns the version of the database.
The version is a built-in PostgreSQL function. The NpgsqlCommand is an object which is used to execute a query on the database. The parameters are the SQL statement and the connection object. There are queries which return only a scalar value.
In our case, we want a simple string specifying the version of the database. The ExecuteScalar is used in such situations. First we drop the table if it already exists. The cars table is created.
Prepared statements increase security and performance. When we write prepared statements, we use placeholders instead of directly writing the values into the statements. Prepared statements are faster and guard against SQL injection attacks.
Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Connect Postgresql in C Ask Question. Asked 4 years, 9 months ago. Active 4 years, 9 months ago. Viewed 3k times. I'm trying to connect a C script running on Windows to my Postgresql database.
How can I make this working? Improve this question. Ozn M. Ozn 14 14 silver badges 34 34 bronze badges. You don't need the C file, You just need to include Postgres library in linker like this: -lpq. Because I'm on Windows, I have to compile it with mingw. See this question: stackoverflow. Are you also compiling those. If you are using gcc, for instance, gcc main.
Sorry I made a mistake, those files are header. Show 3 more comments. Active Oldest Votes. You can set the mode with the gcc options -m32 and -m You can use the user ID and password based on your database setting. Remember to keep the -lpqxx and -lpq in the given order! Otherwise, the linker will complain bitterly about the missing functions with names starting with "PQ. John Elder. Niyazi Erdogan. Abhishek And Pukhraj. Karthikeya T.
Vinay Kumar. Previous Page.
0コメント