Changing border colors in GAS (and *not* changing some) - google-apps-script

Follow up to this question using Google Apps Script: Set border color & style in spreadsheet programmatically
The format is in this order: .setBorder( top, left, bottom, right, vertical, horizontal, color, style )
According to the documentation,
"true" turns on format
"false" turns off format
"null" leaves it unchanged
My problem: "null" is turning the format off!
I have a very simple script for testing purposes:
var right = "red";
var left = "blue";
range.setBorder( null, null, null, true, null, null, right, null );
range.setBorder( null, true, null, null, null, null, left, null );
Shouldn't this set the right border red and the left border blue?
The result is only the blue. If I omit the blue line, it'll result in the red.
It seems the only way to get 2+ colors in a single cell is to do .setBorder separately using "null". But "null" is working as "false" and turning off the previous border.

SpreadsheetApp.flush() should solve the problem:
range.setBorder( null, null, null, true, null, null, right, null );
SpreadsheetApp.flush();
range.setBorder( null, true, null, null, null, null, left, null );

I am just rephrasing the asked question with the above answer as the following script makes more sense to the first-timers:
var rightBorderOn = true;
var leftBorderOn =true;
var rightBorderColor = "red";
var leftBorderColor = "blue";
range.setBorder( null, null, null, rightBorderOn, null, null, rightBorderColor, null );
SpreadsheetApp.flush();
range.setBorder( null, leftBorderOn, null, null, null, null, leftBorderColor, null );
Hope this helps some!

Related

Combining the data from several rows to one row of data in MySQL

I want to know how to change the display of MySQL table from this:
TagName, DateTime, Temperature, Humidity, Voltage, Current
'SG_QRA_SGHAST_0044.Zone1_Voltage', '2022-06-03 15:50:29.7580000', NULL, NULL, '3.6', NULL
'SG_QRA_SGHAST_0044.Zone1_current', '2022-06-03 14:53:19.2130000', NULL, NULL, NULL, '0.0'
'SG_QRA_SGHAST_0044.Zone1B_Voltage', '2022-06-03 15:52:59.3910000', NULL, NULL, '1.95', NULL
'SG_QRA_SGHAST_0044.Zone1B_Current', '2022-06-03 15:52:59.7070000', NULL, NULL, NULL, '0.59'
'SG_QRA_SGHAST_0044.PV_HUMIDITY', '2022-06-03 15:52:54.3930000', NULL,'85.02', NULL, NULL
'SG_QRA_SGHAST_0044.PV_TEMP', '2022-06-03 15:52:54.3930000', '109.98', NULL, NULL, NULL
To a table like this:
TagName, Temperature, Humidity, Voltage, Current
'SGHAST.0044', '109.98', '85.02', 'Zone1 = 3.6, Zone1B = 0.0', 'Zone1 = 1.95, Zone1B = 0.59'
What I am trying to do is to code the raw data form to show the table I want to get (the second table here). I managed to code to obtain the first table (separating from one column to columns of temperature, humidity, voltage, current) but I'm stuck with this step in achieving the second table.
Any help is appreciated thank you! (I was suggested to do self join but I am still not sure the steps to be taken)
(P.s. the 'SGHAST' can be 'SGTC' or 'SGTHB' or 'SGREFLOW' and the digits '0044' can be any number in sequence but within the 4 digits)

How to get list of issues of a repo using Github GraphQL.NET

According to the documentation, I used this code to build a query:
var query = new Query()
.Repository("some_repo", "MuziburRahman")
.Select(r => new
{
r.Name,
r.Description,
Issues = r.Issues(100, null, null, null, null, null, null).Select(i => i.Nodes).Select(i => new
{
i.Title,
i.Body,
}).ToList(),
});
But it shows error: An expression tree may not contain a call or invocation that uses optional arguments.
What is wrong here?
Seems like they added another parameter, so you have to add another null.
r.Issues(100, null, null, null, null, null, null, null)

How to create a table in MySQL?

I have tried to develop a table in Mysql, I have tried to fulfil the requirements but can't seem to fix a specified error. The requirements are:
Table name: vehicles
reg_no: VARCHAR(8) NOT NULL,
category: ENUM('car', 'truck') NOT NULL DEFAULT 'car',
brand: VARCHAR(30) NULL DEFAULT '',
description: VARCHAR(256) NULL DEFAULT '',
photo: BLOB NULL,
daily_rate: DECIMAL(6,2) NOT NULL DEFAULT 9.99
I have attached screenshots about how I tried create this table, and have also attached a screenshot of the error.SQL SQLError
Just tried it using sqlfiddle with the following code and it works.
create table vehicles (
reg_no VARCHAR(8) NOT NULL,
category ENUM('car', 'truck') NOT NULL DEFAULT 'car',
brand VARCHAR(30) NULL DEFAULT '',
description VARCHAR(256) NULL DEFAULT '',
photo BLOB NULL,
daily_rate DECIMAL(6,2) NOT NULL DEFAULT 9.99
);
I just took your description out of the question and edited it so it would fit the MySQL Syntax
In your screenshot "SQL" you've missed a comma between Car and Truck (In the "Length/Value" field)
You should remove DEFAULT 'car'.
If an ENUM column is declared to permit NULL, the NULL value is a valid value for the column, and the default value is NULL. If an ENUM column is declared NOT NULL, its default value is the first element of the list of permitted values.
Source MySQL Doc

SELECT Query fails because of restrictions or so it says [duplicate]

This question already has answers here:
Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints
(26 answers)
Closed 5 years ago.
I'm running a query against a MySQL database, and its statement is simply
SELECT * FROM tableOperationsHistory;
However, it fails and I get this exception (I translated it into English):
Fail activating restrictions. One or more rows contain values that
violate non-null, unique or foreign-key restrictions.
This is the routine where the error happens:
Public Function RetrieveTable(ByVal command_text As String, Optional ByVal parameters As ParameterSet = Nothing) As DataTable
Dim dt As New DataTable, retry = False
Do
Using comm = conn.CreateCommand
comm.CommandText = command_text
If parameters IsNot Nothing Then
Dim par As DbParameter
For Each pair In parameters
par = comm.CreateParameter
par.ParameterName = pair.Key
par.Value = pair.Value
comm.Parameters.Add(par)
Next
End If
Dim rdr As DbDataReader
RequestConnection()
Try
rdr = comm.ExecuteReader
dt.Load(rdr)
retry = False
Catch ex As Exception
retry = ShouldRetry(ex) 'EXCEPTION IS CAUGHT HERE
End Try
DismissConnection()
End Using
Loop While retry
Return dt
End Function
And this is the table definition statement:
CREATE TABLE `tableOperationsHistory` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`numero` varchar(45) DEFAULT NULL,
`pasta_id` int(11) DEFAULT NULL,
`dataHoraInicioPrazo` datetime DEFAULT NULL,
`dataHoraFinalPrazo` datetime DEFAULT NULL,
`urgente` tinyint(4) DEFAULT NULL,
`setorOrigem_id` int(11) DEFAULT NULL,
`unidade_id` int(11) DEFAULT NULL,
`setor_id` int(11) DEFAULT NULL,
`usuario_id` int(11) DEFAULT NULL,
`modalidadeComunicacaoJudicial_id` int(11) DEFAULT NULL,
`modalidadeRepercussao_id` int(11) DEFAULT NULL,
`especieTarefa_id` int(11) DEFAULT NULL,
`postIt` varchar(255) DEFAULT NULL,
`teor_observacao` varchar(255) DEFAULT NULL,
`comunicacaoJudicial_id` int(11) DEFAULT NULL,
`tarefa_id` int(11) DEFAULT NULL,
`mensagens` text,
`criadoPor_id` int(11) DEFAULT NULL,
`criadoEm` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=92 DEFAULT CHARSET=latin1;
How can this happen in a SELECT statement? What should I do?
This great community helped me to realize that such an error can be caused by "a mismatch in column definition (e.g. size of char fields) between the database and the dataset", and pointed me to another thread: https://stackoverflow.com/a/7029713/3718031
Possible relation with this, too: Column longtext exceeds the MaxLength limit
In my case, there are columns with "TEXT" datatype and it seems that might be the problem.
I thank deeply to all those who commented in my question and helped me to learn this.
EDIT: Since this question was voted-to-close and my problem remained, I tried to investigate a little further and made another question, I hope that one is properly exposed.

comparing a varchar field to the number zero returns as if its a true match

i am looking for some work around on this problem and/or i need it to reply with an empty result or the boolean false.
using the sql statement on MySQL
`SELECT * FROM users WHERE verify = 0 LIMIT 1`
the code above returns the second row in the table.
Here is the table i used:
CREATE TABLE IF NOT EXISTS `users` (
`user_id` bigint(20) unsigned NOT NULL,
`username` varchar(30) NOT NULL,
`password` varchar(60) NOT NULL,
`email` varchar(30) NOT NULL,
`firstname` varchar(30) DEFAULT NULL,
`lastname` varchar(30) DEFAULT NULL,
`status` tinyint(1) NOT NULL DEFAULT '1',
`verify` varchar(32) NOT NULL,
`verified` bit(1) NOT NULL DEFAULT b'0'
) ENGINE=InnoDB AUTO_INCREMENT=37 DEFAULT CHARSET=latin1;
INSERT INTO `users` VALUES(1, 'admin', '$2y$10$id6rHN6Zy8XHmCkWlAMvGO8pr3K4OD1zfFAZMaVgoGXbezY8SXcT2', 'admin#admin.com', 'Firstname', 'Lastname', 1, '21232f297a57a5a743894a0e4a801fc3', b'1');
INSERT INTO `users` VALUES(36, 'client', '$2y$10$gdtPImQhYoCIiTpTs/veW.BXsWUz6Zcxb.TY6XXQNO6uf5Q7kx99.', 'client#client.com', 'client', 'client', 1, 'cf3873cdefaefa2cc2c4f1efbba23202', b'0');
--edit, sorry did not specify want i wanted
i don't want it to return anything or maybe how do i make it that it would return false or empty result.
right now, i am using a nasty workaround by modifying the zero result and making it a text "zero" before passing it to the sql query. works but, if there is something better way that you can suggest it would be much appreciated.
I'm not sure what you expect to happen. When you write:
where verify = 0
MySQL has a conundrum. verify is a character string and 0 is an integer. They are not comparable, so MySQL converts one to the other. In this case, it will convert verify to an integer value, getting 0, and they match.
If you want a string comparison, then use:
where verify = '0'
However, that returns the same result.
If you want it to compare to the character value of 0, then perhaps you want:
where verify = '\0'