How to reference a document in MySQL? - mysql

My database has a table within it, let's call it 'doclist'. I want the table to display a document name, the date associated with it, and a link to download this file. After researching it seems that the file (looking to include a PDF or Word doc) needs to be stored somewhere within htdocs, and I will need to reference the file location within one of the table fields. What type of field would that need to be: varchar, blob, or text? The only other tutorials I have seen including files are just dumping data, where I want to reference a file and allow its download. Any direction would be very helpful at this point.

Related

Finding part of a sequence of numerical values in files with unknown name

I have the following problem I would like to solve.
I have a main table file that contains two columns: a unique identifier and a sequence of numerical values. The file looks something like this. The numerical values were copied into this file from a number of different Excel or .csv files (not more than 10). Each of these source files contain a part of the numerical values in the main file. These files look something like this.
I know the approximate, although not the exact length of each of the sub-sequences making up the numerical values in the column in the main file. I do not know the name of the .csv or Excel file where they originally came from.
I would like to do three things:
For each part of the values in the main file, determine which source file they originally came from.
Identify all numerical values that are in the same column but above and below this sub-sequence in the source file.
Copy these numerical values from the column of the sub-sequence in the source file into a new column in the main file.
Save. The results should look like this.
To restate this, the problems are:
I do not know the exact length of each sub-sequence, although I know the approximate length.
I do not know the source file for each sub-sequence of the numerical values in the main file.
In principle, this could be done by hand, but I would rather not. Does someone have an idea how to approach this?

How do i refresh csv data set in quicksight and not replace the data set as this loses my calcs

I am looking to refresh a data set in quicksight, this is in Spice. The data set comes from a csv file that has been updated and now has more data than the original file I uploaded.
I can't seem to find a way to simply repoint to the same file with same format. I know how to replace the file but whenever i do this it states that it can't create some of my calculated fields and so drops multiple rows of data!
I assume I'm missing something obvious but I can't seem to find the right method or any help on the issue.
Thanks
Unfortunately, QuickSight doesn't support refreshing file data-sets to my knowledge. One solution, however, is to put your CSV in S3 and refresh from there.
The one gotcha with this approach is that you'll need to create a manifest file pointing to your CSV. This isn't too difficult and the QuickSight documentation is pretty helpful.
You can replace the datasource by going into the Analysis and clicking on the pencil icon as highlighted in Step 1. By replacing dataset, you will not lose any new calculated fields that might have been calculated already on the old dataset.
If you try to replace the data source by going into the Datasets as highlighted below, you'll lose all calculated fields and modifications etc
I don't know when this was introduced but you can now do this exact thing through the "Edit Dataset", starting either from the Dataset page or from the 'pencil' -> Edit dataset inside an Analysis. It is called "update file" and will result in an updated dataset (additional or different data) without losing anything from your analysis including calculated fields, filters etc.
The normal caveat applies in that the newer uploaded file MUST contain the same column names and datatypes as the original - although it can also contain additional columns if needed.
Screenshots:

What is the best way to keep track of multiple files (strings) with dynamic properties?

I have a settings file that contains a single string. Only one setting can be set at one time but you can have multiple saved settings. I need to be able to reference the setting by name, category, and subcategory. For example, the category is character and the subcategory is what 2 spells are selected for that character. I want to track them by unique name but also be able to look up a character and spell setting as well.
My current solution is to have a directory with each category and then spell combinations sub folders with the file being stored in the last folder with the title of the setting as the file name. However, my problem is that it's very slow and bulky.
I thought I could store all the information in one file but then I have to search each file when a character is selected. There may not be an additional setting for a particular combination either, which means it just stays whatever it was originally.
In summary, I want to list a string by name or character and each character has a subcategory that has a two string combination. Does anyone have any ideas on the best method to approach this problem?
I also thought about using one file in a Json strong and just deserializing and querying it, but the file could be extremely large. I am working on the program in vb.net.
I can take this down if it's useless. I used one file as a map to the rest of the larger files. The map has the basic metadata as well to prevent me from having to search all the files. I am not sure if it is the best answer but it did work for me. I can take this question down if no one finds this useful.

Add PDF to database

I hope you can help me. In my database (supermarket) I have a table for orders and other for order_details and I would like to add the PDF of each invoice (associated to the order_number) to the database. Is this possible in mySQL? How can I do it?
You could store the PDF in an orders directory and insert the link into the db so when it is sent to the customer it would provide the link to the invoice
There are three possible ways I can think of to go about this.
Method 1.
Have a directory in which all the pdfs are stored. Give each PDF a name that is the order number found in the database.
Method 2.
Store the PDFs in a directory like method 1, but in your database store a file path to the PDF as a varchar. eg: /orderPdfs/124.pdf
Method 3.
Create a BLOB column in your order table and store the PDFs in this field.
Information on how to do this with PHP can be found in the answer to this post: How to store .pdf files into MySQL as BLOBs using PHP?

Insert missing rows in CSV of incrementally numbered files generated by directory listing?

I have created a CSV from a set of files in a directory that are numbered incrementally:
img1_1.jpg, img1_2.jpg ... img1_1999.jpg, img1_2000.jpg
The CSV output is like so:
filename, datetime
eg:
img1_1.JPG,2011-05-11 09:16:33.000000000
img1_3.jpg,2011-05-11 10:10:55.000000000
img1_4.jpg,2011-05-11 10:17:31.000000000
img1_6.jpg,2011-05-11 10:58:37.000000000
The problem is, there are a number of files missing in the listing, as some of the files don't exist. As a result, when imported, the actual row number does not match the file number.
Can anyone think of a reasonably efficient way to insert the missing rows so that the row number and filename matches up other than manually inserting rows for the missing ones? (There are over 800 missing rows).
Background
A previous programmer developed an uploader script and did not save the creation time of the mysql record in the database. I figured the easiest way to find the creation time for the majority of the records would be to output a directory listing of all the files and combine them in a spreadsheet.
You exactly need to do what you write in your comment to answer #tadman.
A text parser script to inject the missing lines with e.g. a date/time value that reflects the record is an empty one, i.e. there is no real data is behind it (e.g. date it to 1950-01-01 00:00:00). When it is done, bulk import the CSV.I think this must be the best and most efficient solution.
Also, think about any future insert/delete/update events might occur to your data.
That would possibly break the chain you initially have had, so you might prefer instead, to introduce a numeric field for the jpegs IDs (and index that field), and leave the PK "as is" (auto increment).
In this case you can avoid CSV manipulation, as well as being chained to your AUTO PK (means: you will not get in trouble if a new jpeg arrives with an ID which was previously deleted, or existing ID, etc).
So the solution really depends on how you want to use this table in the future. If you give more details, I am sure the community can come up with even more ideas.
If it's a one-time thing, it might be easiest to open up your csv in a spreadsheet.
If your table above is in sheet1, you could put something like the following in sheet2 (this is openoffice, but there are similar functions for Excel)
pre_filename | filename | datetime
img1_1 | = A2&".JPG" | =OFFSET(Sheet1.$B$1;MATCH(B2;Sheet1.$A$2:$A$4;0);0)
You should be able to select the three cells above and drag them down to however many you need.