Normandnorbertoshari's Profile

55
Points

Questions
9

Answers
12

  • You can do something like this:

    public async Task ClearRedisWithDelay() {     await Task.Delay(500);     await ClearRedis(); } 

    and call

    ClearRedisWithDelay 

    without await.

    There are a few downsides with this approach: https://stackoverflow.com/a/54485904/14072498

    Your own suggestion from your comment

     Task.Run(async () => { await Task.Delay(500); await ClearRedis(); }) 

    will do the job in a new thread which should be acceptable.

    The only guarantee regarding time, is a delay of min. 500 ms before calling ClearRedis.

    • 6 views
    • 1 answers
    • 0 votes
  • Asked on September 1, 2020 in Mysql.

    Another way of doing this is to get the histogram of the table. It’s more work, though. For example:

    create table customer (   name varchar(20),   salary int ); 

    Then insert 1000 random rows in the table:

    insert into customer (name, salary) with recursive c (it, name, salary) as (   select 1,  substring(md5(rand()) from 1 for 10), 50000  union all   select     it + 1,     substring(md5(rand()) from 1 for 10),     floor(rand() * (120000 - 22000 + 1)) + 22000   from c   where it < 1000 ) select name, salary from c; 

    Now that you have a table with data you can compute a histogram (with a single bucket) and get the value ranges for each column:

    analyze table customer  update histogram on name, salary with 1 buckets;  select column_name,   histogram->>'$."buckets"[0][0]' as min_value,   histogram->>'$."buckets"[0][1]' as max_value from information_schema.column_statistics where table_name = 'customer' 

    Result:

    COLUMN_NAME  min_value                        max_value                       -----------  -------------------------------  ------------------------------- name         base64:type254:MDA2NzM2YmUwYQ==  base64:type254:ZmZjNjJlYWNmMg== salary       22089                            119840                          
    • 5 views
    • 2 answers
    • 0 votes
  • Asked on September 1, 2020 in Mysql.

    As the list of values goes bigger and bigger, a better solution is to load it into a table, that you can then use it your query. In MySQL, the load data statement syntax comes handy for this.

    Consider something like:

    create temporary table all_ids (id int); load data infile 'myfile.txt' into table all_ids; create index idx_all_ids on all_ids(id);  -- for performance  select t.* from mytable t where exists (select 1 from all_ids a where a.id = t.id) 

    The load data syntax accepts many options to accommodate the format of the input file – you can read the documentation for more information.

    • 9 views
    • 1 answers
    • 0 votes
  • Asked on September 1, 2020 in Mysql.

    #The Problem

    In MySQL, certain words like SELECT, INSERT, DELETE etc. are reserved words. Since they have a special meaning, MySQL treats it as a syntax error whenever you use them as a table name, column name, or other kind of identifier – unless you surround the identifier with backticks.

    As noted in the official docs, in section 10.2 Schema Object Names (emphasis added):

    Certain objects within MySQL, including database, table, index, column, alias, view, stored procedure, partition, tablespace, and other object names are known as identifiers.

    If an identifier contains special characters or is a reserved word, you must quote it whenever you refer to it.

    The identifier quote character is the backtick ("`"):

    A complete list of keywords and reserved words can be found in section 10.3 Keywords and Reserved Words. In that page, words followed by "(R)" are reserved words. Some reserved words are listed below, including many that tend to cause this issue.

    • ADD
    • AND
    • BEFORE
    • BY
    • CALL
    • CASE
    • CONDITION
    • DELETE
    • DESC
    • DESCRIBE
    • FROM
    • GROUP
    • IN
    • INDEX
    • INSERT
    • INTERVAL
    • IS
    • KEY
    • LIKE
    • LIMIT
    • LONG
    • MATCH
    • NOT
    • OPTION
    • OR
    • ORDER
    • PARTITION
    • REFERENCES
    • SELECT
    • TABLE
    • TO
    • UPDATE
    • WHERE

    #The Solution

    You have two options.

    1. Don’t use reserved words as identifiers

    The simplest solution is simply to avoid using reserved words as identifiers. You can probably find another reasonable name for your column that is not a reserved word.

    Doing this has a couple of advantages:

    • It eliminates the possibility that you or another developer using your database will accidentally write a syntax error due to forgetting – or not knowing – that a particular identifier is a reserved word. There are many reserved words in MySQL and most developers are unlikely to know all of them. By not using these words in the first place, you avoid leaving traps for yourself or future developers.

    • The means of quoting identifiers differs between SQL dialects. While MySQL uses backticks for quoting identifiers by default, ANSI-compliant SQL (and indeed MySQL in ANSI SQL mode, as noted here) uses double quotes for quoting identifiers. As such, queries that quote identifiers with backticks are less easily portable to other SQL dialects.

    Purely for the sake of reducing the risk of future mistakes, this is usually a wiser course of action than backtick-quoting the identifier.

    2. Use backticks

    If renaming the table or column isn’t possible, wrap the offending identifier in backticks (`) as described in the earlier quote from 10.2 Schema Object Names.

    An example to demonstrate the usage (taken from 10.3 Keywords and Reserved Words):

    mysql> CREATE TABLE interval (begin INT, end INT); ERROR 1064 (42000): You have an error in your SQL syntax. near 'interval (begin INT, end INT)' 

    mysql> CREATE TABLE interval (begin INT, end INT); Query OK, 0 rows affected (0.01 sec)

    Similarly, the query from the question can be fixed by wrapping the keyword key in backticks, as shown below:

    INSERT INTO user_details (username, location, `key`) VALUES ('Tim', 'Florida', 42)";               ^   ^ 
    • 0 views
    • 1 answers
    • 0 votes
  • Asked on September 1, 2020 in Mysql.

    Unpivot the transactions and then join and aggregate:

    select user_id, sum(credit) as credit, sum(debit) as debit from ((select paid_to as user_id, sum(amount) as credit, 0 as debit        from transactions t        group by paid_to       ) union all       (select paid_from as user_id, 0, sum(amount)        from transactions t        group by paid_from       )      ) t group by user_id; 

    Then join in for the final result:

    select u.*, u.credit + t.credit - u.debit,        (case when u.credit + t.credit - u.debit < 0 then 'yes' else no' end) from users u left join      (select user_id, sum(credit) as credit, sum(debit) as debit       from ((select paid_to as user_id, sum(amount) as credit, 0 as debit              from transactions t              group by paid_to             ) union all             (select paid_from as user_id, 0, sum(amount)              from transactions t              group by paid_from             )            ) t       group by user_id      ) t      on t.user_id = u.user_id 
    • 9 views
    • 2 answers
    • 0 votes
  • Asked on September 1, 2020 in Mysql.

    There are 1M sales records and 30K user records in the database. I have created view in database with user and sales table. I have included amount,month,year,bank,userid and usertype table fields. Now loading issue is not happening.

    • 0 views
    • 2 answers
    • 0 votes
  • Your json is an array of category object, you have to loop through your json to create the list of options element, your success function should look like this:

    success: function (response) {    var html = '<option value="">Select Sub Category</option>';    response.forEach(category => {        html += "<option value='" + category.categories_id + "'>"+ category.categories_name +"</option>"        $("#productCategories"+row).html(html);    }) }  
    • 0 views
    • 1 answers
    • 0 votes
  • Asked on September 1, 2020 in CSS.

    I found that wrapping the hyphen in a div with display:inline-block properties seems to be doing the trick.

    face<div style="display: inline-block;">-</div>to<div style="display: inline-block;">-</div>face<br> 

    Still I wonder if there are better ways to do this.

    • 6 views
    • 3 answers
    • 0 votes
  • Asked on September 1, 2020 in CSS.

    You can use getBoundingClientRect() method which returns the size of an element and its position relative to the viewport.

    This method returns a DOMRect object with eight properties: left, top, right, bottom, x, y, width, height.

    Click here for more info.

    var canvas = document.querySelector("canvas"); var rect = canvas.getBoundingClientRect();   x = rect.left;   y = rect.top;   w = rect.width;   h = rect.height;   console.log("Left: " , x , ", Top: " , y , ", Width: " , w , ", Height: " , h);
    canvas {   border:1px solid #d3d3d3;   background-color: #ff0000; }
    <canvas width="240" height="297"> Your browser does not support the HTML5 canvas tag. </canvas>

    • 11 views
    • 1 answers
    • 0 votes
  • Asked on September 1, 2020 in CSS.

    Try setting the width to 100% in the svg code and then control the size of svg with CSS (however you are implmenting css) by adjusting the width of the container that holds the svg.

    Something like:

    .sl-container {     width: 4rem; }  

    EDIT: If you need help implementing the css you can find a good explanation of numerous implmentations here. Inline styling is probably the simplest way to do it.

    <Logo style="width: 4rem;" /> 
    • 9 views
    • 2 answers
    • 0 votes