Categories
Mastering Development

How do I solve this error caused from a Pivot?

When trying to pivot my table – a dynamic one which I can’t define as entries my change can be added or deleted – I receive a fatal error. I used a checked answer from this question and changed it where it was necessary. You will see that I use AVG instead of SUM. SET […]

Categories
Mastering Development

Optimizing Insertions into an SQLite Database with JDBC

I’m writing the backend for a java http server for a class project and I have to insert a few records into a database using jdbc. The maximum number of insertions I have at one time is currently 122, which takes a whopping 18.7s to execute, about 6.5 insertions per second. This is outrageously slow, […]

Categories
Database Development

Postgres query performance – hash aggregate costly operation

I’m running Postgres 9.6.6 and I have a relatively simple query, however, I’m finding that it is slow with the hash aggregation function which is the most costly operation: select program_schedule_source_count.full_name, program_schedule_source_count.country, sum(program_schedule_source_count.displays) as displays, program_schedule_source_count.source_id, program_schedule_source_count.source_region from program_schedule_source_count where program_schedule_source_count.original_title = ‘How I Met Your Mother’ and program_schedule_source_count.show_type in (‘SM’, ‘SE’) and program_schedule_source_count.start_date between […]

Categories
Mastering Development

Conditional based query execution in Hive

Do we have conditional based query execution in Hive? I have to join two tables, TAB_A and TAB_B. When TAB_A.date1 <= TAB_B.date2 then select data from TAB_A else if TAB_B.flag = ‘V’ then select data from TAB_A else select data from TAB_B. I have tried the case statement as mentioned below. but it did not […]

Categories
Mastering Development

Reading API JSON in SQL

I am trying to read an API into a SQL database directly. –Set Header Declare @header nvarchar(max) = ‘[{ “Name”: “Authorization”, “Value” :”b/XdI6IQzCviZOGJ0E+002DasdoKUFOPmVDkwpQDbQjm3w/qkdxDUzmqvSYEZDCmJGWpA23OTlhFpxRHFz3WOsvay8V58XdIp/UIsr5TpCdMwtW3QsadasdXF2ahwQYp2O6GzKlJciZKZNZjg+W7wqdlB75asdasdasu/p8isu1SLy9b32gS33LR1Ievk/eYZdjPLP4Mx6qZH10yo1UvDfMhHjRw4UrYLOR/44BEW4hON0C+qfessG5+oFgg2J+RrUyfbcIvUz7DG1LUohmyDWJclSC7qqqYRFWVZG2GjwXbeHbTbAfoDa/0Q9iZNanAOJ4ElG/3/hukeFBWQBOI+cGURskFvrHKLGgLReHRM4kZFtlOg+5kzilw6pkH8hqutxT77otJKwH+iYRzH5lgbC” }]’; –Set URL Declare @wurl varchar(max) = ‘https://in901.eu1.qb.com/IDORequestService/MGRestService.svc/json/ue_BBL_MSRPPricings/ItemCode,Country,MSRP/adv/?filter=ItemCode=”KA-2-1-SPD” AND Country=”AU”’ Declare @ts as table(Json_Table nvarchar(max)) insert into @ts –Get Account Data exec [dbo].APICaller_GET_headers @wurl ,@header SELECT * FROM OPENJSON((select * from @ts),’$.”Items”‘) […]

Categories
Mastering Development

Merge array with previous value (under defined conditions)

Here’s the initial table’s structure : yearquarter,user_id,gender,generation,country,group_id 2019-03,zfuzhfuzh,M,Y,FR,Group_1 2019-04,zfuzhfuzh,M,Y,FR,Group_1 2020-04,zfuzhfuzh,M,Y,FR,Group_1 2019-03,ggezegz,F,Y,FR,Group_2 2019-04,ggezegz,F,Y,FR,Group_2 2020-04,ggezegz,F,X,FR,Group_2 …. I want to be able to know the cumulative amount of user_id quarter after quarter grouped by gender, generation and country. Expected result: for a given combination of gender,generation,country I need the cumulated number of users quarter after quarter. I started […]

Categories
Mastering Development

Django crispy forms tabholder can’t change css

In my form i would like to change the style of the tabs, if i add a css_class to TabHolder it won’t render it, it just keeps the default class. Here is the init of the modelform. def __init__(self, *args, **kwargs): self.user = kwargs.pop(‘user’, None) super().__init__(*args, **kwargs) self.helper = FormHelper() self.helper.form_tag = True self.helper.form_method = […]

Categories
Mastering Development

How to count a number of session instances by a user

My model Suppose I created a user named ‘Ashu’ and that user ‘Ashu’ created multiple sessions, now I want to print the number of session instances by the user ‘Ashu’. class MyUser(AbstractBaseUser): email = models.EmailField( verbose_name=’email address’, max_length=255, unique=True) user_name=models.CharField(max_length=10,blank=True,null=True,unique=True) date_of_birth=models.DateField(null=True,blank=True) mobile_number=models.CharField(max_length=20,blank=True,null=True) address=models.CharField(max_length=100,blank=True,null=True) country=models.CharField(max_length=20,blank=True,null=True) joining_date=models.DateField(null=True,blank=True) Rating_CHOICES = ( (1, ‘Poor’), (2, ‘Average’), (3, ‘Good’), (4, […]

Categories
Mastering Development

Missing and inaccurate payload in Rails with ActiveModel and Forms

I have a model for Organisation like class Organisation include ActiveModel::Model attr_accessor :orguid, :title, :firstname, :lastname, :role, :telephone, :extension, :email, :name, :branch, :address1, :address2, :address3, :city, :state, :country, :zip end In my controller I have the following actions: # frozen_string_literal: true require ‘cgi’ require ‘json’ class OrganisationsController < ApplicationController include Secured before_action :set_api, only: %i[dashboard […]

Categories
Development

Export Pervasive SQL tabels to CSV

I would like to create small tool for exporting database into CSV file. I am able to establish connection to database and for example export it to DataGrid on WPF. However I would like to create Console application and just create CSV file. What would be the right approach to export database to CSV file? […]