Using CSV as a mutable database?

Yes, it's as stupid as it seems. Due to some extremely annoying hosting restrictions and unrequited technical support, I have to use the CSV file as a database.

Although I can use MySQL with PHP, I cannot use it with the backend of my Python program due to problems installing with the host. I can’t use SQLite with PHP due to more installation issues, but I can use it as a built-in Python.

Anyway, now the question is: is it possible to update the SQL-style values ​​in the CSV database? Or should I continue to call support?

+4
source share
12 answers

Do not go, run to immediately get a new host . If your host doesn’t even get you the simplest free databases, this is the time to change. There are a lot of fish in the sea.

At the very least, I would recommend the xml data store rather than csv. My blog uses the xml data provider, and I had no performance issues at all.

+15
source

Continue to call support.

Although you can use CSV as a database, this is usually a bad idea. You will have to implement your own locks, searches, updates, and be very careful with how you write it to make sure that it does not erase in the event of a power outage or other abnormal shutdown. There will be no transactions, no query language, unless you write your own, etc.

+1
source

I could not imagine that it was a good idea. The current mess I inherited is writing vital billing information to CSV and updating it after the projects are completed. It works terribly, and thousands of dollars are missed a month. For the current limitations that you have, I would think about finding the best hosting.

+1
source

You can use sqlite3 for a more real database. It's hard to imagine a hosting that won't let you install it as a python module.

Don't even think about using CSV, your data will be damaged and lost faster than you say "s # & t"

+1
source

"Anyway, now the question is: is it possible to update the SQL-style values ​​in the CSV database?"

Technically, this is possible. However, this can be difficult.

If PHP and Python are writing a file, you will need to use OS-level locking to ensure that they do not overwrite each other. Each part of your system will have to lock the file, rewrite it from scratch with all updates and unlock the file.

This means that PHP and Python must load the entire file into memory before overwriting it.

There are several ways to handle OS locks.

  • Use the same file and actually use some OS locking module. Both processes always open the file.

  • Write a temporary file and rename. This means that every program must open and read a file for each transaction. Very safe and reliable. A bit slow.

Or.

You can rebuild it so that only Python writes the file. The interface reads the file when it changes and discards small transaction files to create a work queue for Python. In this case, you do not have several authors - you have one reader and one writer, and life is much simpler.

+1
source

I will call support. You do not want to use CSV for data, if at all relational. It will be a nightmare.

0
source

I agree. Tell them that 5 random strangers agree that you have to go into a corner to use CSV is absurd and unacceptable.

0
source

If you understood correctly: you need to access the same database from python and php and you are screwed up because you can only use mysql from php and only sqlite from python?

Could you explain this? Perhaps you could use xml-rpc or simple HTTP requests with xml / json / ... to force the php program to interact with the python program (or vice versa?), So that only one of them addresses db directly.

If this is not the case, I am not sure what the problem is.

0
source

This is technically possible. For example, Perl has DBD :: CSV , which provides a driver that runs SQL queries in a CSV file.

As the saying goes, why not run the SQLite database on your server?

0
source

What about postgresql? I found that working well and python supports it well.

But I would really look for another provider if this is really not an option.

0
source

Disagreeing with noble colleagues, I often use Perl's DBD :: CSV. There are good reasons for this. First of all, this is a data update, simplified using a spreadsheet. As a bonus, since I use SQL queries, the application can be easily upgraded to a real database engine. Keep in mind that this is a very small database in one user application.

So, to paraphrase the question: is there a python module equivalent to Perl DBD: CSV

0
source

All Articles