## mysql cursor not fetching data from select query inside stored procedure

I have written the following procedure but the the cursor is not displaying or inserting any data. I have ran the select query separately and it returns data properly.

I tried checking other solutions on stack overflow and dba stack exchange but the solutions are not fixing the issue.

As advise in the answers in the above mentioned links I renamed all the variables with _ in varibalename but still it cursor doesn’t display or insert data

Any help would be appriciated.

``````DELIMITER \$\$

CREATE PROCEDURE getUniquePartnerIds()
BEGIN

DECLARE temp_partnerId INTEGER DEFAULT 0;
DECLARE is_finished INTEGER DEFAULT 0;

DECLARE cursor_Partnerid CURSOR FOR
SELECT DISTINCT(partnerId) FROM multiplepartners WHERE partnerId NOT IN (SELECT partnerId FROM partner_language);

OPEN cursor_Partnerid;

get_PartnerId: LOOP
FETCH cursor_Partnerid INTO temp_partnerId;
SELECT temp_partnerId;
IF is_finished = 1 THEN LEAVE get_PartnerId;
END IF;

-- INSERT INTO `partner_language`(`partnerid`)
-- VALUES (temp_partnerId);
END LOOP get_PartnerId;
CLOSE cursor_Partnerid;

END\$\$

DELIMITER ;
``````

## computer architecture – Arithmetic on signed 12-bit octal number stored in sign magnitude form

What is 4365 − 3412 when these values represent signed 12-bit
octal numbers stored in sign-magnitude format? The result should be written in

Octal to binary:

• 4365: 100 011 110 101
• 3412: 011 100 001 010

By recognising the role of the sign bit, we can
represent positive and negative 64-bit numbers in terms of the bit value times a
power of 2. The binary number x, where xi means the ith bit, represents the number:

(x11 * -2^11) + (x10 * 2^10) + (x9 * 2^9) + … + (x1 * 2^1) + (x0 * 2^0)

I have used the formula given above to convert the value of octal 4365 in decimal:

(1 * -2^11) + (1 * 2^7) + 2^6 + 2^5 + 2^4 + 2^2 + 2^0 = -2048 + 245 = -1803

Similarly, the value of octal 3412 in decimal is 1802.

Having obtained the two values in decimal, I subtract (-1803 – 1802), obtaining the result -3605.

Binary representation of 3605 is 111 000 010 101.

Converting it back to octal gives 7025.

This answer is wrong. It should be octal 7777 or decimal -3777.

The concept is not clear to me. Where am I going wrong?

## mysql 5.7 – Can you use a SELECT … FOR UPDATE cursor in a stored procedure to enforce row-level locking?

From https://www.oreilly.com/library/view/mysql-stored-procedure/0596100892/re37.html:

``````    CREATE PROCEDURE needy_bonus(  )
BEGIN
DECLARE  v_employee_id INT;
DECLARE  v_salary      NUMERIC(8,2);
DECLARE  v_last_emp    INT DEFAULT 0;

DECLARE emp_csr CURSOR FOR
SELECT employee_id,salary
FROM employees
WHERE salary <45000
FOR UPDATE;

START TRANSACTION;
OPEN emp_csr;
emp_loop:LOOP
FETCH emp_csr INTO  v_employee_id, v_salary;
IF  v_last_emp THEN
LEAVE emp_loop;
END IF;
CALL grant_raise( v_employee_id, v_salary);
END LOOP emp_loop;
CLOSE emp_csr;
SET  v_last_emp=0;

COMMIT;

END;
``````

Does this method really work for row-level update locking in a stored procedure? I ask because I’m doing this myself and I’m getting some consistency issues. Is it possible I need to set the transaction isolation mode to `REPEATABLE READ`? I’m currently using `READ COMMITTED`.

## Where the %MEM value is stored in /proc?

Using the top command you can find out the %MEM used by the process, but where is this value stored in /proc? In /proc/uid/status I found only the value of virtual memory.

## dictionary – Where are dictionaries stored in MacOS?

I’m studying the Dutch language, and the built-in dictionary has plenty of example sentences that are superior to the ones in the materials I’ve been working with from Loecsen.  I’d like to put many of them (a few at a time) into Anki for memory drill.

But Apple has disabled copy on the pop-up. Perhaps that’s a copyright issue, in which case my question is irrelevant. But if not, I’d like some way to get to them other than screen shot, OCR, and cleanup.

The same dictionary is also on my iPad, so a way to access that would be useful as well.

I found many possible packages in `/System/Library/AssetsV2/com_apple_MobileAsset_DictionaryServices_dictionaryOSX` but don’t see any way to parse them.

## sql server 2016 – Stored Procedure Signed by Certificate Unable to Add Members to Database Roles

I created a Stored Procedure that performs the Following tasks:

• Creates database
• Change owner to sa
• Set recovery model
• Creates users in database
• Adds users to database roles.
• Grants execute and view definition to users

I then created a certificate, Login from cert, user from cert, granted exec on SP to user, granted control server to login, added signature to sp by certificate.

When non sysadmins execute the SP everything works except for adding users to the database roles with error: Cannot alter the role ‘db_datareader’, because it does not exist or you do not have permission.

If I add the login to the sysadmin server role, when non sysadmins execute the SP it will work. Ideally the login would have minimal permissions to perform these functions. Is it possible to do this w/o granting sysadmin to the user?

Here is the code I used to create the certificate, login, user, signature, etc:

``````use master;
go

CREATE CERTIFICATE sp_CreateNewReportingDatabase_cert
WITH SUBJECT = 'Certificate for sp_CreateNewReportingDatabase',
START_DATE = '20201015', EXPIRY_DATE = '21000101'
GO

CREATE LOGIN sp_CreateNewReportingDatabase_cert_user FROM CERTIFICATE sp_CreateNewReportingDatabase_cert;
GO
CREATE USER sp_CreateNewReportingDatabase_cert_user FROM CERTIFICATE sp_CreateNewReportingDatabase_cert;
GO
GRANT EXECUTE ON dbo.CreateNewReportingDatabase TO sp_CreateNewReportingDatabase_cert_user;
GO
GRANT CONTROL SERVER TO sp_CreateNewReportingDatabase_cert_user;
GO
ADD SIGNATURE TO (dbo).(CreateNewReportingDatabase) BY CERTIFICATE sp_CreateNewReportingDatabase_cert
GO
``````

Here is the code to create the stored proc:

``````CREATE OR ALTER PROC dbo.CreateNewReportingDatabase @DatabaseName NVARCHAR(50), @ReportingPod NVARCHAR(50) = NULL
AS
SET XACT_ABORT, NOCOUNT ON

DECLARE @SqlCommand NVARCHAR(2000);

--Error Checking
IF @ReportingPod NOT LIKE 'TAC(_)NTAnalysis-%' AND (@DatabaseName LIKE 'Reporting(_)%' OR @DatabaseName LIKE '(_)Salesforce')
BEGIN
RAISERROR('For Reporting_<client> and <client>_Salesforce databases you must populate @ReportingPod with a value that follow formate TAC_NTAnalysis-<reportingpod> Contact DBA',16,1)
SET NOEXEC ON --Stops running the script --I believe that this requires sysadmin rights.
END
ELSE IF (@DatabaseName LIKE 'Reporting(_)%' OR @DatabaseName LIKE '(_)Salesforce') AND @ReportingPod IS NULL
BEGIN
RAISERROR('For Reporting_<client> and <client>_Salesforce databases you must populate @ReportingPod with a value that follow formate TAC_NTAnalysis-<reportingpod> Contact DBA',16,1)
SET NOEXEC ON --Stops running the script --I believe that this requires sysadmin rights.
END
ELSE IF EXISTS (
SELECT (name)
FROM sys.databases
WHERE (name) = @DatabaseName
)
BEGIN
RAISERROR('There is already a detabase with that name!',16,1)
SET NOEXEC ON --Stops running the script --I believe that this requires sysadmin rights.
END

--Execute Scrips
ELSE
BEGIN
--Create the database
PRINT 'Creating database ' + @databasename;
SET @SqlCommand = N'CREATE DATABASE (' + @DatabaseName + ')'
EXEC dbo.sp_executesql @SqlCommand

-- change owner to sa
PRINT 'Switching owner to sa';
SET @SqlCommand = N'ALTER AUTHORIZATION ON DATABASE::(' + @DatabaseName + ') TO (sa);'
EXEC dbo.sp_executesql @SqlCommand;

-- set recovery model to simple
IF @DatabaseName LIKE 'Reporting(_)%' OR @DatabaseName LIKE '%(_)Salesforce'
BEGIN
PRINT 'Setting recovery model to simple';
SET @SqlCommand = N'ALTER DATABASE (' + @DatabaseName + ') SET RECOVERY SIMPLE;'
EXEC dbo.sp_executesql @SqlCommand
END
ELSE PRINT 'Revoery model not modified from default';

-- Create users for ServiceAccount and reportingPod in Reporting_ databases.
IF @DatabaseName LIKE 'reporting(_)%' OR @DatabaseName LIKE '%(_)Salesforce'
BEGIN
SET @SqlCommand = N'
USE (' + @DatabaseName + ')
IF NOT EXISTS(
SELECT (name)
FROM sys.database_principals
WHERE
(type) NOT IN (''s'',''r'')
AND (NAME) = ''TAC_NTServiceAccount''
)
BEGIN
PRINT ''Creating (TAC_NTServiceAccount) user''
CREATE USER (TAC_NTServiceAccount) FOR LOGIN (TAC_NTServiceAccount)
END

IF NOT EXISTS(
SELECT (name)
FROM sys.database_principals
WHERE
(type) NOT IN (''s'',''r'')
AND (NAME) = ''' + @ReportingPod + '''
)
BEGIN
PRINT ''Creating ' + @ReportingPod + ' user''
CREATE USER (' + @ReportingPod +  ') FOR LOGIN (' + @ReportingPod + ');
END'
EXEC sp_executesql @SqlCommand;
END
ELSE PRINT 'Skipping the creation of the ServiceAccount and Reporting POD database principals'

---Grant role membership for ServiceAccount
IF @DatabaseName LIKE 'Reporting(_)%'
BEGIN
SET @SqlCommand = N'
USE (' + @DatabaseName + ')
ALTER ROLE db_datawriter ADD MEMBER (TAC_NTServiceAccount)
'
EXEC sp_executesql @SqlCommand
END
ELSE IF @DatabaseName  LIKE '%(_)salesforce'
BEGIN
SET @SqlCommand = N'
USE (' + @DatabaseName + ')
'
EXEC sp_executesql @SqlCommand
END

--Grant role membership for ReportingPod
IF @DatabaseName  LIKE 'Reporting(_)%' AND @ReportingPod LIKE 'TAC_NTAnalysis%'
BEGIN
SET @SqlCommand = N'
USE (' + @DatabaseName + ')
EXEC sp_executesql @SqlCommand
END
ELSE IF @DatabaseName  LIKE '%salesforce' AND @ReportingPod LIKE 'TAC_NTAnalysis%'
BEGIN
SET @SqlCommand = N'
USE (' + @DatabaseName + ')
EXEC sp_executesql @SqlCommand
END

--Grant execute and view definition for ReportingPod
IF @DatabaseName  LIKE '%(_)Salesforce' OR @DatabaseName  LIKE 'Reporting(_)%'
BEGIN
PRINT 'Granting execute and view definition to ' + @ReportingPod;
SET @SqlCommand = N'
USE (' + @DatabaseName + ')
GRANT EXECUTE TO (' + @ReportingPod + ');
GRANT VIEW DEFINITION TO (' + @ReportingPod + ');'
EXEC dbo.sp_executesql @SqlCommand;
END
END
GO
``````

## sql server – How to execute specific stored procedure using LIKE wildcard or any other methods just to execute the specific SP

I have multiple stored procedure but I need to execute only specific stored procedure. I already tried

``````Exec Stored1 from dbo.Db1 where Person LIKE 'James'
Exec Stored2 from dbo.Db1 where Person LIKE 'Mike'
``````

and this

``````IF @Person= 'James'
EXEC Stored1 '
IF @Person= 'Mike'
EXEC Stored2
``````

I did this because it takes too long to execute my stored procedure due to the long query. That’s why I separate the other stored procedure and execute only the specific results for faster query results.

Is it possible to do this if not is there any other way to execute specific Stored Procedure? Thank you for the great help

## Gmail: Search for email based on name stored in contacts

I have at least one friend with a Gmail address associated with a fake name. In my contacts list, I have the correct name associated with the email address. I can then type this person’s name in the recipient field and Gmail populates it appropriately. However, if I search this person’s name in my email, their messages are not returned.

A workaround is to type “from:[start typing in the person’s name and their email autocompletes]” and search for emails from that email address. However, this is unsatisfying if the person uses multiple email addresses, as I would have to look up each email address. Additionally, I might just type the person’s name in and forget that Gmail isn’t returning all messages from all of their email addresses, since some messages are returned.

## Does `adb backup` also backs up what is backed up by Android automatic backup (that is stored on Google Drive)?

I have two backups: one from Android automatic backup, stored in Google Drive; another is what I manually backed up with `adb backup`.

What are the differences between the two? Do I need to restore the one from Drive as well if I reinstall my OS?

There is a similar question but it doesn’t answer my question.

## complexity theory – Expressivity of neural networks, how much information can be stored

You’re probably not going to get a theoretical answer, because analyzing exactly what set of functions can be computed by a particular neural network is messy. Or, at least, you probably won’t get a tight analysis. There are theorems showing that neural networks are universal approximators, meaning that given sufficient capacity it is possible to express every function, but this doesn’t tell you the minimize size needed to express every function; it just tells you that there exists a size that is large enough.

However, if you’re willing to accept empirical evidence rather than theorems and proofs, research has demonstrated empirically that if you choose a deep neural network architecture with sufficient capacity and you train for long enough, neural nets can memorize the training set and achieve 100% accuracy on the training set, at least for a randomly chosen function $$f$$ [1]. This may not tell you exactly what size neural network you need to ensure that it can express all such functions, and it’s not a proof or a guarantee.

The VC dimension is beautiful theory but it’s not clear it has a great deal of relevance to modern use of neural networks in practice.

[1] Understanding deep learning requires rethinking generalization. Chiyuan Zhang, Samy Bengio, Moritz Hardt, Benjamin Recht, Oriol Vinyals. arXiv:1611.03530