MS Access: UPDATE syntax error - sql-update

UPDATE sentences SET text = 0 WHERE text = 17
What will there occures when updating column participated in both SET and WHERE parts of query?

There is no issue here. All the row whose text value is 17 will have a text value of 0 when the UPDATE is executed. But, as text is a keyword in Access, you should enclose it with square brackets:
UPDATE sentences SET [text] = 0 WHERE [text] = 17

Related

Python-docx - How to change table font size?

table = document.add_table(rows=1, cols=1)
hdr_cells = table.rows[0].cells
hdr_cells[0].text = 'Qty'
I have to change font size of text 'Qty' in table with one row and one column, how can I make it?
You need to get the paragraph in the cell. From the documentation of python-docx:
3.5.2 _Cell objects:
class docx.table._Cell (tc, parent)
paragraphs
List of paragraphs in the cell. A table cell is required to
contain at least one block-level element and end with a paragraph. By
default, a new cell contains a single paragraph. Read-only
Reference: python-docx Documentation - Read the Docs
The code:
To change font size of text 'Qty'
paragraph =hdr_cells[0].paragraphs[0]
run = paragraph.runs
font = run[0].font
font.size= Pt(30) # font size = 30
To change font size of the whole table:
for row in table.rows:
for cell in row.cells:
paragraphs = cell.paragraphs
for paragraph in paragraphs:
for run in paragraph.runs:
font = run.font
font.size= Pt(30)
Reference of how to access paragraphs in a table: Extracting data from tables
Up there the solution really helped. I use it for a while. But I found a tiny problem:time. As your table grows bigger the time you cost to build the table getting longer. So I improve it. Cut two rounds. Here you are:
The code changes the whole table
for row in table.rows:
for cell in row.cells:
paragraphs = cell.paragraphs
paragraph = paragraphs[0]
run_obj = paragraph.runs
run = run_obj[0]
font = run.font
font.size = Pt(30)
When you cut two rounds you save the time
Building on user7609283 answer, here is a short version to set a cell to bold (the cell must contain text before applying format as it looks for the first paragraph):
row_cells = table.add_row().cells
row_cells[0].text = "Customer"
row_cells[0].paragraphs[0].runs[0].font.bold = True
This font change applies to all cells of a table and is streamlined. All cells must contain text before being formatted or an index out of range error is thrown:
for row in table.rows:
for cell in row.cells:
cp = cell.paragraphs[0].runs
cp[0].font.size = Pt(14)
This next font change applies to a single cell as wanted, in this case the top left cell:
tc = table.cell(0, 0).paragraphs[0].runs
tc[0].font.size = Pt(14)

SQLite extract string from text in column

I have a Spatialite Database and I've imported OSM Data into this database.
With the following query I get all motorways:
SELECT * FROM lines
WHERE other_tags GLOB '*A [0-9]*'
AND highway='motorway'
I use GLOB '*A [0-9]*' here, because in Germany every Autobahn begins with A, followed by a number (like A 73).
There is a column called other_tags with information about the motorway part:
"bdouble"=>"yes","hazmat"=>"designated","lanes"=>"2","maxspeed"=>"none","oneway"=>"yes","ref"=>"A 73","width"=>"7"
If you look closer there is the part "ref"=>"A 73".
I want to extract the A 73 as the name for the motorway.
How can I do this in sqlite?
If the format doesn't change, that means that you can expect that the other_tags field is something like %"ref"=>"A 73","width"=>"7"%, then you can use instr and substr (note that 8 is the length of "ref"=>"):
SELECT substr(other_tags,
instr(other_tags, '"ref"=>"') + 8,
instr(other_tags, '","width"') - 8 - instr(other_tags, '"ref"=>"')) name
FROM lines
WHERE other_tags GLOB '*A [0-9]*'
AND highway='motorway'
The result will be
name
A 73
Check with following condition..
other_tags like A% -- Begin With 'A'.
abs(substr(other_tags, 3,2)) <> 0.0 -- Substring from 3rd character, two character is number.
length(other_tags) = 4 -- length of other_tags is 4
So here is how your query should be:
SELECT *
FROM lines
WHERE other_tags LIKE 'A%'
AND abs(substr(other_tags, 3,2)) <> 0.0
AND length(other_tags) = 4
AND highway = 'motorway'

read two columns in Excel using python

I want to write a python script which should read xlsx file and based on value of column X, it should write/append file with the value of column Z.
Sample data:
Column A Column X Column Y Column Z
123 abc test value 1
124 xyz test value 2
125 xyz test value 3
126 abc test value 4
If value in Column X = abc then it should create a file (if not existing already) in some path with name abc.txt and insert the value of column Z in abc.txt file, likewise if Column X = xyz then it should create a file in same path with xyz.txt and insert the value of column Z in xyz.txt file.
from openpyxl import load_workbook
wb = load_workbook('filename.xlsm')
ws = wb.active
for cell in ws.columns[9]: #here column 9 is value is what i am testing which is Column X of my example.
if cell.value == "abc":
print ws.cell(column=12).value #this is not working and i dont know how to read corresponding value of another column
Please suggest what could be done.
Thank you.
Change
print ws.cell(column=12).value
By:
print ws.columns[col][row].value
in your case:
print ws.columns[12-1][cell.row-1].value
Note that if you use this indexation method cols and rows start with index 0. This is why I'm doing cell.row-1, so take it into account when you address your column, if your 12 starts counting from 1 you'll have to address to 11.
Alternatively you can access to your information cell like this: ws.cell(row = cell.row, column = 12).value. Note in this case cols and rows start at 1.

fetching multiple values from a string using regular expression

I have a table temp that have a column name "REMARKS"
Create script
Create table temp (id number,remarks varchar2(2000));
Insert script
Insert into temp values (1,'NAME =GAURAV Amount=981 Phone_number =98932324 Active Flag =Y');
Insert into temp values (2,'NAME =ROHAN Amount=984 Phone_number =98932333 Active Flag =N');
Now , i want to fetch the corresponding value of NAME ,Amount ,phone_number, active_flag from the remarks column of the table.
I thought of using regular expression ,but i am not comfortable in using it .
I tried with substr and instr to fetch the name from the remakrs column ,but if i want to fetch all four, i need to write a pl sql .Can we achieve this using Regular expression.
Can i get output(CURSOR) like
id Name Amount phone_number Active flag
------------------------------------------
1 Gaurav 981 98932324 Y
2 Rohan 984 98932333 N
-------------------------------------------
Thanks for your help
you can use something like :
SQL> select regexp_replace(remarks, '.*NAME *=([^ ]*).*', '\1') name,
2 regexp_replace(remarks, '.*Amount *=([^ ]*).*', '\1') amount,
3 regexp_replace(remarks, '.*Phone_number *=([^ ]*).*', '\1') ph_number,
4 regexp_replace(remarks, '.*Active Flag *=([^ ]*).*', '\1') flag
5 from temp;
NAME AMOUNT PH_NUMBER FLAG
-------------------- -------------------- -------------------- --------------------
GAURAV 981 98932324 Y
ROHAN 981 98932324 N

manipulation on a file - vb.net plus some regex

The below is the content of my file(which is already sorted). Whichever is there between square brackets, relate to one transaction. The transactions can be groupa, groupb,groupc etc.
Jan 2012 02:10:12 [5678](groupa):Part 1:data1
Jan 2012 02:10:12 [5678](groupa):Part 2:data2
Jan 2012 02:10:12 [5678](groupa):Part 3:data3
Jan 2012 02:10:12 [5678](groupa):Part 4:data4
Jan 2012 02:13:14 [12308](groupa):Part 1:data1
Jan 2012 02:13:14 [12308](groupa):Part 2:data2
Jan 2012 02:13:24 [34517](groupb):Part 1:data1
Jan 2012 02:13:24 [34517](groupb):Part 2:data2
I want to output the below data to another file using vb.net. It should contain the transaction group, followed by the time(the time should be taken from the first row of the contents grouped by transaction, then grouped by the number inside the square bracket, in the contents). Next line should concatenate the data(after Part [1-9]:), corresponding to the particular transaction grouped by the number inside the square bracket. For the above contents,
groupa at Jan 2012 02:10:12
data1data2data3data4
groupa at Jan 2012 02:13:14
data1data2
groupb at Jan 2012 02:13:24
data1data2
So first let's create a class to represent that data. It will make it easier to work it. Here is what mine looks like:
Public Class LogEntry
Public Property DateTime As DateTime
Public Property Id As Integer
Public Property Group As String
Public Property Part As String
Public Property Data As String
End Class
Now that we have that, let's parse each line with a regular expression. They aren't my strength, but in this case it works:
Dim text = File.ReadAllLines("log.log")
Dim rx As New Regex("^(?<date>.+)\s\[(?<id>\d+)\]\((?<group>.+)\):(?<part>.+):(?<data>.+)$")
Dim logEntries As New List(Of LogEntry)
For Each line In text
Dim match = rx.Match(line)
Dim entry As New LogEntry With _
{
.DateTime = DateTime.ParseExact(match.Groups("date").Value, "MMM yyyy hh:mm:ss", System.Globalization.CultureInfo.CurrentCulture),
.Id = Int32.Parse(match.Groups("id").Value),
.Group = match.Groups("group").Value.Trim(),
.Part = match.Groups("part").Value.Trim(),
.Data = match.Groups("data").Value.Trim()
}
logEntries.Add(entry)
Next
Here we are loading the text from a file. It doens't matter how it gets the text. After that we iterate over each line and gather the information with a regular expression. Once we parse it, we create a LogEntry and add it to a list. As a list this will make it easier to work. We can use LINQ to group, then print it out:
Dim grouped = logEntries _
.GroupBy(Function(x) New With {Key .Id = x.Id, Key .Group = x.Group, Key .DateTime = x.DateTime}) _
.OrderBy(Function(x) x.Key.DateTime)
For Each group In grouped
Console.WriteLine("{0} at {1:MMM yyyy hh:mm:ss}", group.Key.Group, group.Key.DateTime)
Console.WriteLine(String.Join("", group.Select(Function(x) x.Data)))
Next